/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var GameBlock = Container.expand(function () {
var self = Container.call(this);
self.blockColor = 0x4CAF50;
self.gridX = 0;
self.gridY = 0;
self.isPlaced = false;
self.isDragging = false;
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5
});
self.setColor = function (colorId) {
self.blockColor = colorId;
var assetMap = {
0: 'block',
1: 'blockRed',
2: 'blockBlue',
3: 'blockYellow',
4: 'blockPurple'
};
blockGraphics.tint = colorId;
};
self.getGridPos = function () {
return {
x: self.gridX,
y: self.gridY
};
};
self.setGridPos = function (gx, gy) {
self.gridX = gx;
self.gridY = gy;
};
self.down = function (x, y, obj) {
self.isDragging = true;
};
self.up = function (x, y, obj) {
self.isDragging = false;
};
return self;
});
var GameGrid = Container.expand(function () {
var self = Container.call(this);
self.gridWidth = 8;
self.gridHeight = 8;
self.cellSize = 80;
self.startX = 300;
self.startY = 300;
self.cells = [];
self.blocks = [];
self.init = function () {
for (var row = 0; row < self.gridHeight; row++) {
self.cells[row] = [];
for (var col = 0; col < self.gridWidth; col++) {
var gridCell = LK.getAsset('gridCell', {
anchorX: 0.5,
anchorY: 0.5
});
gridCell.x = self.startX + col * self.cellSize + self.cellSize / 2;
gridCell.y = self.startY + row * self.cellSize + self.cellSize / 2;
gridCell.alpha = 0.3;
self.cells[row][col] = null;
self.addChild(gridCell);
}
}
};
self.getWorldPos = function (gridX, gridY) {
return {
x: self.startX + gridX * self.cellSize + self.cellSize / 2,
y: self.startY + gridY * self.cellSize + self.cellSize / 2
};
};
self.getGridPosFromWorld = function (worldX, worldY) {
var relX = worldX - self.startX;
var relY = worldY - self.startY;
var gridX = Math.floor(relX / self.cellSize);
var gridY = Math.floor(relY / self.cellSize);
if (gridX < 0) gridX = 0;
if (gridY < 0) gridY = 0;
if (gridX >= self.gridWidth) gridX = self.gridWidth - 1;
if (gridY >= self.gridHeight) gridY = self.gridHeight - 1;
return {
x: gridX,
y: gridY
};
};
self.isValidPlacement = function (gridX, gridY) {
if (gridX < 0 || gridX >= self.gridWidth) return false;
if (gridY < 0 || gridY >= self.gridHeight) return false;
if (gridY === self.gridHeight - 1) return true;
if (self.cells[gridY + 1][gridX] !== null) return true;
return false;
};
self.placeBlock = function (block, gridX, gridY) {
if (!self.isValidPlacement(gridX, gridY)) return false;
self.cells[gridY][gridX] = block;
block.setGridPos(gridX, gridY);
var worldPos = self.getWorldPos(gridX, gridY);
block.x = worldPos.x;
block.y = worldPos.y;
block.isPlaced = true;
LK.getSound('placeBlock').play();
return true;
};
self.getBlockAt = function (gridX, gridY) {
if (gridY < 0 || gridY >= self.gridHeight || gridX < 0 || gridX >= self.gridWidth) {
return null;
}
return self.cells[gridY][gridX];
};
self.removeBlock = function (gridX, gridY) {
if (gridY < 0 || gridY >= self.gridHeight || gridX < 0 || gridX >= self.gridWidth) {
return null;
}
var block = self.cells[gridY][gridX];
self.cells[gridY][gridX] = null;
return block;
};
return self;
});
var Level = Container.expand(function () {
var self = Container.call(this);
self.levelNum = 1;
self.targetPattern = [];
self.completed = false;
self.init = function (levelNumber) {
self.levelNum = levelNumber;
self.generatePattern(levelNumber);
};
self.generatePattern = function (levelNum) {
self.targetPattern = [];
var complexity = Math.min(2 + Math.floor(levelNum / 3), 8);
if (levelNum === 1) {
self.targetPattern = [{
x: 3,
y: 7,
color: 0x4CAF50
}, {
x: 4,
y: 7,
color: 0x4CAF50
}, {
x: 3,
y: 6,
color: 0x4CAF50
}];
} else if (levelNum === 2) {
self.targetPattern = [{
x: 2,
y: 7,
color: 0xF44336
}, {
x: 3,
y: 7,
color: 0xF44336
}, {
x: 4,
y: 7,
color: 0xF44336
}, {
x: 3,
y: 6,
color: 0xF44336
}, {
x: 3,
y: 5,
color: 0xF44336
}];
} else if (levelNum === 3) {
self.targetPattern = [{
x: 2,
y: 7,
color: 0x2196F3
}, {
x: 3,
y: 7,
color: 0x2196F3
}, {
x: 4,
y: 7,
color: 0x2196F3
}, {
x: 5,
y: 7,
color: 0x2196F3
}, {
x: 3,
y: 6,
color: 0x2196F3
}, {
x: 4,
y: 6,
color: 0x2196F3
}];
} else {
for (var i = 0; i < complexity; i++) {
var colorOptions = [0x4CAF50, 0xF44336, 0x2196F3, 0xFFEB3B, 0x9C27B0];
var randomColor = colorOptions[Math.floor(Math.random() * colorOptions.length)];
self.targetPattern.push({
x: Math.floor(Math.random() * 6) + 1,
y: Math.floor(Math.random() * 3) + 5,
color: randomColor
});
}
}
};
self.displayTarget = function (container, grid) {
for (var i = 0; i < self.targetPattern.length; i++) {
var target = self.targetPattern[i];
var targetGraphic = LK.getAsset('targetBlock', {
anchorX: 0.5,
anchorY: 0.5
});
targetGraphic.tint = target.color;
targetGraphic.alpha = 0.4;
var worldPos = grid.getWorldPos(target.x, target.y);
targetGraphic.x = worldPos.x;
targetGraphic.y = worldPos.y;
container.addChild(targetGraphic);
}
};
self.checkCompletion = function (grid) {
for (var i = 0; i < self.targetPattern.length; i++) {
var target = self.targetPattern[i];
var block = grid.getBlockAt(target.x, target.y);
if (block === null || block.blockColor !== target.color) {
return false;
}
}
return true;
};
return self;
});
var Palette = Container.expand(function () {
var self = Container.call(this);
self.selectedColor = 0;
self.colorIds = [0x4CAF50, 0xF44336, 0x2196F3, 0xFFEB3B, 0x9C27B0];
self.buttons = [];
self.init = function () {
var buttonX = 100;
for (var i = 0; i < 5; i++) {
var paletteBtn = LK.getAsset('paletteButton', {
anchorX: 0.5,
anchorY: 0.5
});
paletteBtn.x = buttonX;
paletteBtn.y = 2650;
paletteBtn.tint = self.colorIds[i];
paletteBtn.colorIndex = i;
self.buttons.push(paletteBtn);
self.addChild(paletteBtn);
buttonX += 110;
}
};
self.down = function (x, y, obj) {
for (var i = 0; i < self.buttons.length; i++) {
if (self.buttons[i].intersects(obj)) {
self.selectedColor = i;
tween(self.buttons[i], {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut
});
} else {
tween(self.buttons[i], {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var grid = game.addChild(new GameGrid());
grid.init();
var palette = game.addChild(new Palette());
palette.init();
var currentLevel = new Level();
currentLevel.init(storage.currentLevel || 1);
currentLevel.displayTarget(game, grid);
var scoreText = new Text2('Level: ' + currentLevel.levelNum, {
size: 80,
fill: '#FFFFFF'
});
scoreText.anchor.set(0.5, 0);
scoreText.x = 1024;
scoreText.y = 50;
LK.gui.top.addChild(scoreText);
var pointsText = new Text2('Score: 0', {
size: 60,
fill: '#FFFFFF'
});
pointsText.anchor.set(0.5, 0);
pointsText.x = 1024;
pointsText.y = 150;
LK.gui.top.addChild(pointsText);
var currentScore = 0;
var placedBlocks = [];
var selectedBlock = null;
var dragOffset = {
x: 0,
y: 0
};
function createNewBlock() {
var newBlock = new GameBlock();
newBlock.setColor(palette.colorIds[palette.selectedColor]);
return newBlock;
}
game.down = function (x, y, obj) {
var gridPos = grid.getGridPosFromWorld(x, y);
if (y > 2500) {
palette.down(x, y, {
x: x,
y: y
});
return;
}
var existingBlock = grid.getBlockAt(gridPos.x, gridPos.y);
if (existingBlock && existingBlock.isPlaced) {
selectedBlock = existingBlock;
dragOffset.x = x - selectedBlock.x;
dragOffset.y = y - selectedBlock.y;
selectedBlock.isDragging = true;
tween(selectedBlock, {
alpha: 0.7
}, {
duration: 100
});
return;
}
if (!selectedBlock) {
selectedBlock = createNewBlock();
game.addChild(selectedBlock);
placedBlocks.push(selectedBlock);
}
selectedBlock.isDragging = true;
selectedBlock.x = x;
selectedBlock.y = y;
};
game.move = function (x, y, obj) {
if (!selectedBlock || !selectedBlock.isDragging) {
return;
}
if (selectedBlock.isPlaced) {
selectedBlock.x = x - dragOffset.x;
selectedBlock.y = y - dragOffset.y;
} else {
selectedBlock.x = x;
selectedBlock.y = y;
}
};
game.up = function (x, y, obj) {
if (!selectedBlock) {
return;
}
var gridPos = grid.getGridPosFromWorld(x, y);
if (selectedBlock.isPlaced) {
var oldPos = selectedBlock.getGridPos();
grid.removeBlock(oldPos.x, oldPos.y);
selectedBlock.isPlaced = false;
tween(selectedBlock, {
alpha: 1
}, {
duration: 100
});
}
if (grid.isValidPlacement(gridPos.x, gridPos.y)) {
grid.placeBlock(selectedBlock, gridPos.x, gridPos.y);
var worldPos = grid.getWorldPos(gridPos.x, gridPos.y);
tween(selectedBlock, {
x: worldPos.x,
y: worldPos.y
}, {
duration: 150,
easing: tween.easeOut
});
if (currentLevel.checkCompletion(grid)) {
LK.getSound('completePattern').play();
LK.setScore(LK.getScore() + 100);
currentScore = LK.getScore();
pointsText.setText('Score: ' + currentScore);
LK.setTimeout(function () {
storage.currentLevel = currentLevel.levelNum + 1;
LK.showYouWin();
}, 1000);
}
} else {
tween(selectedBlock, {
x: 100,
y: 100
}, {
duration: 200,
easing: tween.easeOut
});
}
selectedBlock.isDragging = false;
selectedBlock = null;
};
game.update = function () {
for (var i = 0; i < placedBlocks.length; i++) {
if (placedBlocks[i].isPlaced && !placedBlocks[i].isDragging) {
var gridPos = placedBlocks[i].getGridPos();
var worldPos = grid.getWorldPos(gridPos.x, gridPos.y);
if (Math.abs(placedBlocks[i].x - worldPos.x) > 1 || Math.abs(placedBlocks[i].y - worldPos.y) > 1) {
placedBlocks[i].x = worldPos.x;
placedBlocks[i].y = worldPos.y;
}
}
}
};
LK.playMusic('bgmusic'); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,434 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var GameBlock = Container.expand(function () {
+ var self = Container.call(this);
+ self.blockColor = 0x4CAF50;
+ self.gridX = 0;
+ self.gridY = 0;
+ self.isPlaced = false;
+ self.isDragging = false;
+ var blockGraphics = self.attachAsset('block', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.setColor = function (colorId) {
+ self.blockColor = colorId;
+ var assetMap = {
+ 0: 'block',
+ 1: 'blockRed',
+ 2: 'blockBlue',
+ 3: 'blockYellow',
+ 4: 'blockPurple'
+ };
+ blockGraphics.tint = colorId;
+ };
+ self.getGridPos = function () {
+ return {
+ x: self.gridX,
+ y: self.gridY
+ };
+ };
+ self.setGridPos = function (gx, gy) {
+ self.gridX = gx;
+ self.gridY = gy;
+ };
+ self.down = function (x, y, obj) {
+ self.isDragging = true;
+ };
+ self.up = function (x, y, obj) {
+ self.isDragging = false;
+ };
+ return self;
+});
+var GameGrid = Container.expand(function () {
+ var self = Container.call(this);
+ self.gridWidth = 8;
+ self.gridHeight = 8;
+ self.cellSize = 80;
+ self.startX = 300;
+ self.startY = 300;
+ self.cells = [];
+ self.blocks = [];
+ self.init = function () {
+ for (var row = 0; row < self.gridHeight; row++) {
+ self.cells[row] = [];
+ for (var col = 0; col < self.gridWidth; col++) {
+ var gridCell = LK.getAsset('gridCell', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ gridCell.x = self.startX + col * self.cellSize + self.cellSize / 2;
+ gridCell.y = self.startY + row * self.cellSize + self.cellSize / 2;
+ gridCell.alpha = 0.3;
+ self.cells[row][col] = null;
+ self.addChild(gridCell);
+ }
+ }
+ };
+ self.getWorldPos = function (gridX, gridY) {
+ return {
+ x: self.startX + gridX * self.cellSize + self.cellSize / 2,
+ y: self.startY + gridY * self.cellSize + self.cellSize / 2
+ };
+ };
+ self.getGridPosFromWorld = function (worldX, worldY) {
+ var relX = worldX - self.startX;
+ var relY = worldY - self.startY;
+ var gridX = Math.floor(relX / self.cellSize);
+ var gridY = Math.floor(relY / self.cellSize);
+ if (gridX < 0) gridX = 0;
+ if (gridY < 0) gridY = 0;
+ if (gridX >= self.gridWidth) gridX = self.gridWidth - 1;
+ if (gridY >= self.gridHeight) gridY = self.gridHeight - 1;
+ return {
+ x: gridX,
+ y: gridY
+ };
+ };
+ self.isValidPlacement = function (gridX, gridY) {
+ if (gridX < 0 || gridX >= self.gridWidth) return false;
+ if (gridY < 0 || gridY >= self.gridHeight) return false;
+ if (gridY === self.gridHeight - 1) return true;
+ if (self.cells[gridY + 1][gridX] !== null) return true;
+ return false;
+ };
+ self.placeBlock = function (block, gridX, gridY) {
+ if (!self.isValidPlacement(gridX, gridY)) return false;
+ self.cells[gridY][gridX] = block;
+ block.setGridPos(gridX, gridY);
+ var worldPos = self.getWorldPos(gridX, gridY);
+ block.x = worldPos.x;
+ block.y = worldPos.y;
+ block.isPlaced = true;
+ LK.getSound('placeBlock').play();
+ return true;
+ };
+ self.getBlockAt = function (gridX, gridY) {
+ if (gridY < 0 || gridY >= self.gridHeight || gridX < 0 || gridX >= self.gridWidth) {
+ return null;
+ }
+ return self.cells[gridY][gridX];
+ };
+ self.removeBlock = function (gridX, gridY) {
+ if (gridY < 0 || gridY >= self.gridHeight || gridX < 0 || gridX >= self.gridWidth) {
+ return null;
+ }
+ var block = self.cells[gridY][gridX];
+ self.cells[gridY][gridX] = null;
+ return block;
+ };
+ return self;
+});
+var Level = Container.expand(function () {
+ var self = Container.call(this);
+ self.levelNum = 1;
+ self.targetPattern = [];
+ self.completed = false;
+ self.init = function (levelNumber) {
+ self.levelNum = levelNumber;
+ self.generatePattern(levelNumber);
+ };
+ self.generatePattern = function (levelNum) {
+ self.targetPattern = [];
+ var complexity = Math.min(2 + Math.floor(levelNum / 3), 8);
+ if (levelNum === 1) {
+ self.targetPattern = [{
+ x: 3,
+ y: 7,
+ color: 0x4CAF50
+ }, {
+ x: 4,
+ y: 7,
+ color: 0x4CAF50
+ }, {
+ x: 3,
+ y: 6,
+ color: 0x4CAF50
+ }];
+ } else if (levelNum === 2) {
+ self.targetPattern = [{
+ x: 2,
+ y: 7,
+ color: 0xF44336
+ }, {
+ x: 3,
+ y: 7,
+ color: 0xF44336
+ }, {
+ x: 4,
+ y: 7,
+ color: 0xF44336
+ }, {
+ x: 3,
+ y: 6,
+ color: 0xF44336
+ }, {
+ x: 3,
+ y: 5,
+ color: 0xF44336
+ }];
+ } else if (levelNum === 3) {
+ self.targetPattern = [{
+ x: 2,
+ y: 7,
+ color: 0x2196F3
+ }, {
+ x: 3,
+ y: 7,
+ color: 0x2196F3
+ }, {
+ x: 4,
+ y: 7,
+ color: 0x2196F3
+ }, {
+ x: 5,
+ y: 7,
+ color: 0x2196F3
+ }, {
+ x: 3,
+ y: 6,
+ color: 0x2196F3
+ }, {
+ x: 4,
+ y: 6,
+ color: 0x2196F3
+ }];
+ } else {
+ for (var i = 0; i < complexity; i++) {
+ var colorOptions = [0x4CAF50, 0xF44336, 0x2196F3, 0xFFEB3B, 0x9C27B0];
+ var randomColor = colorOptions[Math.floor(Math.random() * colorOptions.length)];
+ self.targetPattern.push({
+ x: Math.floor(Math.random() * 6) + 1,
+ y: Math.floor(Math.random() * 3) + 5,
+ color: randomColor
+ });
+ }
+ }
+ };
+ self.displayTarget = function (container, grid) {
+ for (var i = 0; i < self.targetPattern.length; i++) {
+ var target = self.targetPattern[i];
+ var targetGraphic = LK.getAsset('targetBlock', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ targetGraphic.tint = target.color;
+ targetGraphic.alpha = 0.4;
+ var worldPos = grid.getWorldPos(target.x, target.y);
+ targetGraphic.x = worldPos.x;
+ targetGraphic.y = worldPos.y;
+ container.addChild(targetGraphic);
+ }
+ };
+ self.checkCompletion = function (grid) {
+ for (var i = 0; i < self.targetPattern.length; i++) {
+ var target = self.targetPattern[i];
+ var block = grid.getBlockAt(target.x, target.y);
+ if (block === null || block.blockColor !== target.color) {
+ return false;
+ }
+ }
+ return true;
+ };
+ return self;
+});
+var Palette = Container.expand(function () {
+ var self = Container.call(this);
+ self.selectedColor = 0;
+ self.colorIds = [0x4CAF50, 0xF44336, 0x2196F3, 0xFFEB3B, 0x9C27B0];
+ self.buttons = [];
+ self.init = function () {
+ var buttonX = 100;
+ for (var i = 0; i < 5; i++) {
+ var paletteBtn = LK.getAsset('paletteButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ paletteBtn.x = buttonX;
+ paletteBtn.y = 2650;
+ paletteBtn.tint = self.colorIds[i];
+ paletteBtn.colorIndex = i;
+ self.buttons.push(paletteBtn);
+ self.addChild(paletteBtn);
+ buttonX += 110;
+ }
+ };
+ self.down = function (x, y, obj) {
+ for (var i = 0; i < self.buttons.length; i++) {
+ if (self.buttons[i].intersects(obj)) {
+ self.selectedColor = i;
+ tween(self.buttons[i], {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ } else {
+ tween(self.buttons[i], {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200
+ });
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a1a
+});
+
+/****
+* Game Code
+****/
+var grid = game.addChild(new GameGrid());
+grid.init();
+var palette = game.addChild(new Palette());
+palette.init();
+var currentLevel = new Level();
+currentLevel.init(storage.currentLevel || 1);
+currentLevel.displayTarget(game, grid);
+var scoreText = new Text2('Level: ' + currentLevel.levelNum, {
+ size: 80,
+ fill: '#FFFFFF'
+});
+scoreText.anchor.set(0.5, 0);
+scoreText.x = 1024;
+scoreText.y = 50;
+LK.gui.top.addChild(scoreText);
+var pointsText = new Text2('Score: 0', {
+ size: 60,
+ fill: '#FFFFFF'
+});
+pointsText.anchor.set(0.5, 0);
+pointsText.x = 1024;
+pointsText.y = 150;
+LK.gui.top.addChild(pointsText);
+var currentScore = 0;
+var placedBlocks = [];
+var selectedBlock = null;
+var dragOffset = {
+ x: 0,
+ y: 0
+};
+function createNewBlock() {
+ var newBlock = new GameBlock();
+ newBlock.setColor(palette.colorIds[palette.selectedColor]);
+ return newBlock;
+}
+game.down = function (x, y, obj) {
+ var gridPos = grid.getGridPosFromWorld(x, y);
+ if (y > 2500) {
+ palette.down(x, y, {
+ x: x,
+ y: y
+ });
+ return;
+ }
+ var existingBlock = grid.getBlockAt(gridPos.x, gridPos.y);
+ if (existingBlock && existingBlock.isPlaced) {
+ selectedBlock = existingBlock;
+ dragOffset.x = x - selectedBlock.x;
+ dragOffset.y = y - selectedBlock.y;
+ selectedBlock.isDragging = true;
+ tween(selectedBlock, {
+ alpha: 0.7
+ }, {
+ duration: 100
+ });
+ return;
+ }
+ if (!selectedBlock) {
+ selectedBlock = createNewBlock();
+ game.addChild(selectedBlock);
+ placedBlocks.push(selectedBlock);
+ }
+ selectedBlock.isDragging = true;
+ selectedBlock.x = x;
+ selectedBlock.y = y;
+};
+game.move = function (x, y, obj) {
+ if (!selectedBlock || !selectedBlock.isDragging) {
+ return;
+ }
+ if (selectedBlock.isPlaced) {
+ selectedBlock.x = x - dragOffset.x;
+ selectedBlock.y = y - dragOffset.y;
+ } else {
+ selectedBlock.x = x;
+ selectedBlock.y = y;
+ }
+};
+game.up = function (x, y, obj) {
+ if (!selectedBlock) {
+ return;
+ }
+ var gridPos = grid.getGridPosFromWorld(x, y);
+ if (selectedBlock.isPlaced) {
+ var oldPos = selectedBlock.getGridPos();
+ grid.removeBlock(oldPos.x, oldPos.y);
+ selectedBlock.isPlaced = false;
+ tween(selectedBlock, {
+ alpha: 1
+ }, {
+ duration: 100
+ });
+ }
+ if (grid.isValidPlacement(gridPos.x, gridPos.y)) {
+ grid.placeBlock(selectedBlock, gridPos.x, gridPos.y);
+ var worldPos = grid.getWorldPos(gridPos.x, gridPos.y);
+ tween(selectedBlock, {
+ x: worldPos.x,
+ y: worldPos.y
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ if (currentLevel.checkCompletion(grid)) {
+ LK.getSound('completePattern').play();
+ LK.setScore(LK.getScore() + 100);
+ currentScore = LK.getScore();
+ pointsText.setText('Score: ' + currentScore);
+ LK.setTimeout(function () {
+ storage.currentLevel = currentLevel.levelNum + 1;
+ LK.showYouWin();
+ }, 1000);
+ }
+ } else {
+ tween(selectedBlock, {
+ x: 100,
+ y: 100
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ }
+ selectedBlock.isDragging = false;
+ selectedBlock = null;
+};
+game.update = function () {
+ for (var i = 0; i < placedBlocks.length; i++) {
+ if (placedBlocks[i].isPlaced && !placedBlocks[i].isDragging) {
+ var gridPos = placedBlocks[i].getGridPos();
+ var worldPos = grid.getWorldPos(gridPos.x, gridPos.y);
+ if (Math.abs(placedBlocks[i].x - worldPos.x) > 1 || Math.abs(placedBlocks[i].y - worldPos.y) > 1) {
+ placedBlocks[i].x = worldPos.x;
+ placedBlocks[i].y = worldPos.y;
+ }
+ }
+ }
+};
+LK.playMusic('bgmusic');
\ No newline at end of file