===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,41 @@
/****
* Classes
****/
+var LetterPiece = Container.expand(function () {
+ var self = Container.call(this);
+ self.assetId = 'letter' + String.fromCharCode(65 + Math.floor(Math.random() * 6));
+ var pieceGraphics = self.attachAsset(self.assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.correctPosition = {
+ x: 0,
+ y: 0
+ };
+ self.isCorrect = false;
+ self.setCorrectPosition = function (x, y) {
+ self.correctPosition.x = x;
+ self.correctPosition.y = y;
+ };
+ self.checkPosition = function () {
+ if (Math.abs(self.x - self.correctPosition.x) < 10 && Math.abs(self.y - self.correctPosition.y) < 10) {
+ self.isCorrect = true;
+ self.x = self.correctPosition.x;
+ self.y = self.correctPosition.y;
+ } else {
+ self.isCorrect = false;
+ }
+ };
+ self.down = function (x, y, obj) {
+ dragNode = self;
+ };
+ self.up = function (x, y, obj) {
+ dragNode = null;
+ self.checkPosition();
+ };
+ return self;
+});
//<Assets used in the game will automatically appear here>
// PuzzlePiece class to represent each piece of the puzzle
var PuzzlePiece = Container.expand(function () {
var self = Container.call(this);
@@ -89,9 +123,9 @@
});
pieces = [];
// Create new pieces for the current level
for (var i = 0; i < 10; i++) {
- var piece = new PuzzlePiece();
+ var piece = new LetterPiece();
piece.x = Math.random() * 2048;
piece.y = Math.random() * 2732;
piece.setCorrectPosition(100 + i * 150, 100 + i * 150);
pieces.push(piece);