User prompt
adjust the location of buttons little up and make background little bit darker to see more clearly
User prompt
noww just adjust the location of buttons little bit up
User prompt
still not working make it infinite changeable and restart button not working make it reset all numbers ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
now ı cant change ıt back,add changing freely can im now 6x6 make me able to make it 4x4 to 10x10 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
when ı change sıze ıts frozen and not changıng sıze of the grıd
User prompt
make ball color more bright and change buttons locatıon to upper rıght on grıd and add grıd changıng to bottom grıd sızes cause grıd not changıng ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
add stop and restart button to grid and change colors to more darker colors on bar
User prompt
make the bar corners smooth and add ball to adjust grid size with swiping and when ball comes to grid size make it go up like bubbles separating and when stop adjusting reset game and make grid size that number ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
add bar to bottom with smooth swaping animations that makes tile grid size from 4x4 to 10x10 with all steps like 5x5 6x6 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make pastel colors
User prompt
pastel colors only
User prompt
3d smooth tiles and i want more warm pastel colors ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make all colors pastel and 3d ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Initial prompt
make background more darker blue
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var GameGrid = Container.expand(function () {
var self = Container.call(this);
self.gridSize = 6;
self.cellSize = 120;
self.cellGap = 10;
self.grid = [];
self.tiles = [];
self.isAnimating = false;
// Initialize grid array
for (var i = 0; i < self.gridSize; i++) {
self.grid[i] = [];
for (var j = 0; j < self.gridSize; j++) {
self.grid[i][j] = null;
}
}
// Create visual grid background
var gridBg = self.attachAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5
});
self.getCellX = function (col) {
return (col - 2.5) * (self.cellSize + self.cellGap);
};
self.getCellY = function (row) {
return (row - 2.5) * (self.cellSize + self.cellGap);
};
// Create grid cells
for (var i = 0; i < self.gridSize; i++) {
for (var j = 0; j < self.gridSize; j++) {
var cell = LK.getAsset('gridCell', {
anchorX: 0.5,
anchorY: 0.5
});
cell.x = self.getCellX(j);
cell.y = self.getCellY(i);
self.addChild(cell);
}
}
self.addTile = function (value, row, col) {
var tile = new Tile(value);
tile.gridX = col;
tile.gridY = row;
tile.x = self.getCellX(col);
tile.y = self.getCellY(row);
self.grid[row][col] = tile;
self.tiles.push(tile);
self.addChild(tile);
// Spawn animation
tile.scaleX = 0;
tile.scaleY = 0;
tween(tile, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
return tile;
};
self.removeTile = function (tile) {
var row = tile.gridY;
var col = tile.gridX;
self.grid[row][col] = null;
var index = self.tiles.indexOf(tile);
if (index > -1) {
self.tiles.splice(index, 1);
}
self.removeChild(tile);
};
self.getEmptyCells = function () {
var emptyCells = [];
for (var i = 0; i < self.gridSize; i++) {
for (var j = 0; j < self.gridSize; j++) {
if (self.grid[i][j] === null) {
emptyCells.push({
row: i,
col: j
});
}
}
}
return emptyCells;
};
self.spawnRandomTile = function () {
var emptyCells = self.getEmptyCells();
if (emptyCells.length === 0) return false;
var randomCell = emptyCells[Math.floor(Math.random() * emptyCells.length)];
var value = Math.random() < 0.9 ? 2 : 4;
self.addTile(value, randomCell.row, randomCell.col);
return true;
};
self.canMove = function () {
// Check for empty cells
if (self.getEmptyCells().length > 0) return true;
// Check for possible merges
for (var i = 0; i < self.gridSize; i++) {
for (var j = 0; j < self.gridSize; j++) {
var current = self.grid[i][j];
if (current) {
// Check right
if (j < self.gridSize - 1 && self.grid[i][j + 1] && self.grid[i][j + 1].value === current.value) {
return true;
}
// Check down
if (i < self.gridSize - 1 && self.grid[i + 1][j] && self.grid[i + 1][j].value === current.value) {
return true;
}
}
}
}
return false;
};
self.move = function (direction, callback) {
if (self.isAnimating) return false;
var moved = false;
var merges = [];
self.isAnimating = true;
// Reset merge flags
for (var i = 0; i < self.tiles.length; i++) {
self.tiles[i].justMerged = false;
}
if (direction === 'left') {
for (var row = 0; row < self.gridSize; row++) {
var line = [];
for (var col = 0; col < self.gridSize; col++) {
if (self.grid[row][col]) {
line.push(self.grid[row][col]);
self.grid[row][col] = null;
}
}
var newLine = self.mergeLine(line);
for (var i = 0; i < newLine.length; i++) {
if (newLine[i]) {
var tile = newLine[i];
var oldCol = tile.gridX;
var newCol = i;
if (oldCol !== newCol || tile.justMerged) {
moved = true;
}
tile.gridX = newCol;
tile.gridY = row;
self.grid[row][newCol] = tile;
if (tile.justMerged) {
merges.push(tile);
}
}
}
}
} else if (direction === 'right') {
for (var row = 0; row < self.gridSize; row++) {
var line = [];
for (var col = self.gridSize - 1; col >= 0; col--) {
if (self.grid[row][col]) {
line.push(self.grid[row][col]);
self.grid[row][col] = null;
}
}
var newLine = self.mergeLine(line);
for (var i = 0; i < newLine.length; i++) {
if (newLine[i]) {
var tile = newLine[i];
var oldCol = tile.gridX;
var newCol = self.gridSize - 1 - i;
if (oldCol !== newCol || tile.justMerged) {
moved = true;
}
tile.gridX = newCol;
tile.gridY = row;
self.grid[row][newCol] = tile;
if (tile.justMerged) {
merges.push(tile);
}
}
}
}
} else if (direction === 'up') {
for (var col = 0; col < self.gridSize; col++) {
var line = [];
for (var row = 0; row < self.gridSize; row++) {
if (self.grid[row][col]) {
line.push(self.grid[row][col]);
self.grid[row][col] = null;
}
}
var newLine = self.mergeLine(line);
for (var i = 0; i < newLine.length; i++) {
if (newLine[i]) {
var tile = newLine[i];
var oldRow = tile.gridY;
var newRow = i;
if (oldRow !== newRow || tile.justMerged) {
moved = true;
}
tile.gridX = col;
tile.gridY = newRow;
self.grid[newRow][col] = tile;
if (tile.justMerged) {
merges.push(tile);
}
}
}
}
} else if (direction === 'down') {
for (var col = 0; col < self.gridSize; col++) {
var line = [];
for (var row = self.gridSize - 1; row >= 0; row--) {
if (self.grid[row][col]) {
line.push(self.grid[row][col]);
self.grid[row][col] = null;
}
}
var newLine = self.mergeLine(line);
for (var i = 0; i < newLine.length; i++) {
if (newLine[i]) {
var tile = newLine[i];
var oldRow = tile.gridY;
var newRow = self.gridSize - 1 - i;
if (oldRow !== newRow || tile.justMerged) {
moved = true;
}
tile.gridX = col;
tile.gridY = newRow;
self.grid[newRow][col] = tile;
if (tile.justMerged) {
merges.push(tile);
}
}
}
}
}
if (moved) {
// Animate tiles to new positions
var animatingTiles = 0;
for (var i = 0; i < self.tiles.length; i++) {
var tile = self.tiles[i];
var targetX = self.getCellX(tile.gridX);
var targetY = self.getCellY(tile.gridY);
if (tile.x !== targetX || tile.y !== targetY) {
animatingTiles++;
tile.animateMoveTo(targetX, targetY, function () {
animatingTiles--;
if (animatingTiles === 0) {
// All animations complete
for (var j = 0; j < merges.length; j++) {
merges[j].animateMerge();
LK.getSound('merge').play();
}
self.isAnimating = false;
if (callback && typeof callback === 'function') callback(true);
}
});
}
}
if (animatingTiles === 0) {
self.isAnimating = false;
if (callback && typeof callback === 'function') callback(true);
}
if (merges.length === 0) {
LK.getSound('slide').play();
}
} else {
self.isAnimating = false;
if (callback && typeof callback === 'function') callback(false);
}
return moved;
};
self.mergeLine = function (line) {
var result = [];
var i = 0;
while (i < line.length) {
if (i < line.length - 1 && line[i].value === line[i + 1].value) {
// Merge tiles
var newValue = line[i].value * 2;
line[i].setValue(newValue);
line[i].justMerged = true;
LK.setScore(LK.getScore() + newValue);
// Remove the second tile
self.removeTile(line[i + 1]);
result.push(line[i]);
i += 2;
} else {
result.push(line[i]);
i++;
}
}
return result;
};
return self;
});
var Tile = Container.expand(function (value) {
var self = Container.call(this);
self.value = value;
self.gridX = 0;
self.gridY = 0;
self.isMoving = false;
self.justMerged = false;
function getTileAssetId(value) {
return 'tile' + value;
}
function getTileColor(value) {
if (value <= 4) return 0x776E65;
return 0xF9F6F2;
}
var tileGraphics = self.attachAsset(getTileAssetId(value), {
anchorX: 0.5,
anchorY: 0.5
});
var tileText = new Text2(value.toString(), {
size: value >= 128 ? 40 : value >= 32 ? 50 : 60,
fill: getTileColor(value)
});
tileText.anchor.set(0.5, 0.5);
self.addChild(tileText);
self.setValue = function (newValue) {
self.value = newValue;
self.removeChild(tileGraphics);
tileGraphics = self.attachAsset(getTileAssetId(newValue), {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(tileGraphics, 0);
// Remove old text and create new one with updated properties
self.removeChild(tileText);
tileText = new Text2(newValue.toString(), {
size: newValue >= 128 ? 40 : newValue >= 32 ? 50 : 60,
fill: getTileColor(newValue)
});
tileText.anchor.set(0.5, 0.5);
self.addChild(tileText);
// Pop animation for new value
self.scaleX = 1.2;
self.scaleY = 1.2;
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
};
self.animateMoveTo = function (x, y, callback) {
self.isMoving = true;
tween(self, {
x: x,
y: y
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
if (callback && typeof callback === 'function') callback();
}
});
};
self.animateMerge = function () {
self.scaleX = 1.1;
self.scaleY = 1.1;
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeOut
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0a0a2e
});
/****
* Game Code
****/
var gameGrid;
var scoreTxt;
var bestTxt;
var gameWon = false;
var gameOver = false;
var touchStartX = 0;
var touchStartY = 0;
var minSwipeDistance = 30;
// Initialize score display
scoreTxt = new Text2('0', {
size: 60,
fill: 0x776E65
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 100;
// Create and position game grid
gameGrid = new GameGrid();
gameGrid.x = 2048 / 2;
gameGrid.y = 2732 / 2;
game.addChild(gameGrid);
// Spawn initial tiles
gameGrid.spawnRandomTile();
gameGrid.spawnRandomTile();
// Update score display
scoreTxt.setText('Score: ' + LK.getScore());
// Touch/swipe handling
game.down = function (x, y, obj) {
if (gameOver || gameWon) return;
touchStartX = x;
touchStartY = y;
};
game.up = function (x, y, obj) {
if (gameOver || gameWon || gameGrid.isAnimating) return;
var deltaX = x - touchStartX;
var deltaY = y - touchStartY;
var absDeltaX = Math.abs(deltaX);
var absDeltaY = Math.abs(deltaY);
if (Math.max(absDeltaX, absDeltaY) < minSwipeDistance) return;
var direction;
if (absDeltaX > absDeltaY) {
direction = deltaX > 0 ? 'right' : 'left';
} else {
direction = deltaY > 0 ? 'down' : 'up';
}
gameGrid.move(direction, function (moved) {
if (moved) {
scoreTxt.setText('Score: ' + LK.getScore());
// Check for 2048 tile (win condition)
if (!gameWon) {
for (var i = 0; i < gameGrid.tiles.length; i++) {
if (gameGrid.tiles[i].value === 2048) {
gameWon = true;
LK.setTimeout(function () {
LK.showYouWin();
}, 500);
return;
}
}
}
// Spawn new tile
if (!gameGrid.spawnRandomTile()) {
// Grid is full, check if game over
if (!gameGrid.canMove()) {
gameOver = true;
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
}
}
}
});
};
game.update = function () {
// Game loop updates handled by other systems
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var GameGrid = Container.expand(function () {
var self = Container.call(this);
self.gridSize = 6;
self.cellSize = 120;
self.cellGap = 10;
self.grid = [];
self.tiles = [];
self.isAnimating = false;
// Initialize grid array
for (var i = 0; i < self.gridSize; i++) {
self.grid[i] = [];
for (var j = 0; j < self.gridSize; j++) {
self.grid[i][j] = null;
}
}
// Create visual grid background
var gridBg = self.attachAsset('gridBackground', {
anchorX: 0.5,
anchorY: 0.5
});
self.getCellX = function (col) {
return (col - 2.5) * (self.cellSize + self.cellGap);
};
self.getCellY = function (row) {
return (row - 2.5) * (self.cellSize + self.cellGap);
};
// Create grid cells
for (var i = 0; i < self.gridSize; i++) {
for (var j = 0; j < self.gridSize; j++) {
var cell = LK.getAsset('gridCell', {
anchorX: 0.5,
anchorY: 0.5
});
cell.x = self.getCellX(j);
cell.y = self.getCellY(i);
self.addChild(cell);
}
}
self.addTile = function (value, row, col) {
var tile = new Tile(value);
tile.gridX = col;
tile.gridY = row;
tile.x = self.getCellX(col);
tile.y = self.getCellY(row);
self.grid[row][col] = tile;
self.tiles.push(tile);
self.addChild(tile);
// Spawn animation
tile.scaleX = 0;
tile.scaleY = 0;
tween(tile, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
return tile;
};
self.removeTile = function (tile) {
var row = tile.gridY;
var col = tile.gridX;
self.grid[row][col] = null;
var index = self.tiles.indexOf(tile);
if (index > -1) {
self.tiles.splice(index, 1);
}
self.removeChild(tile);
};
self.getEmptyCells = function () {
var emptyCells = [];
for (var i = 0; i < self.gridSize; i++) {
for (var j = 0; j < self.gridSize; j++) {
if (self.grid[i][j] === null) {
emptyCells.push({
row: i,
col: j
});
}
}
}
return emptyCells;
};
self.spawnRandomTile = function () {
var emptyCells = self.getEmptyCells();
if (emptyCells.length === 0) return false;
var randomCell = emptyCells[Math.floor(Math.random() * emptyCells.length)];
var value = Math.random() < 0.9 ? 2 : 4;
self.addTile(value, randomCell.row, randomCell.col);
return true;
};
self.canMove = function () {
// Check for empty cells
if (self.getEmptyCells().length > 0) return true;
// Check for possible merges
for (var i = 0; i < self.gridSize; i++) {
for (var j = 0; j < self.gridSize; j++) {
var current = self.grid[i][j];
if (current) {
// Check right
if (j < self.gridSize - 1 && self.grid[i][j + 1] && self.grid[i][j + 1].value === current.value) {
return true;
}
// Check down
if (i < self.gridSize - 1 && self.grid[i + 1][j] && self.grid[i + 1][j].value === current.value) {
return true;
}
}
}
}
return false;
};
self.move = function (direction, callback) {
if (self.isAnimating) return false;
var moved = false;
var merges = [];
self.isAnimating = true;
// Reset merge flags
for (var i = 0; i < self.tiles.length; i++) {
self.tiles[i].justMerged = false;
}
if (direction === 'left') {
for (var row = 0; row < self.gridSize; row++) {
var line = [];
for (var col = 0; col < self.gridSize; col++) {
if (self.grid[row][col]) {
line.push(self.grid[row][col]);
self.grid[row][col] = null;
}
}
var newLine = self.mergeLine(line);
for (var i = 0; i < newLine.length; i++) {
if (newLine[i]) {
var tile = newLine[i];
var oldCol = tile.gridX;
var newCol = i;
if (oldCol !== newCol || tile.justMerged) {
moved = true;
}
tile.gridX = newCol;
tile.gridY = row;
self.grid[row][newCol] = tile;
if (tile.justMerged) {
merges.push(tile);
}
}
}
}
} else if (direction === 'right') {
for (var row = 0; row < self.gridSize; row++) {
var line = [];
for (var col = self.gridSize - 1; col >= 0; col--) {
if (self.grid[row][col]) {
line.push(self.grid[row][col]);
self.grid[row][col] = null;
}
}
var newLine = self.mergeLine(line);
for (var i = 0; i < newLine.length; i++) {
if (newLine[i]) {
var tile = newLine[i];
var oldCol = tile.gridX;
var newCol = self.gridSize - 1 - i;
if (oldCol !== newCol || tile.justMerged) {
moved = true;
}
tile.gridX = newCol;
tile.gridY = row;
self.grid[row][newCol] = tile;
if (tile.justMerged) {
merges.push(tile);
}
}
}
}
} else if (direction === 'up') {
for (var col = 0; col < self.gridSize; col++) {
var line = [];
for (var row = 0; row < self.gridSize; row++) {
if (self.grid[row][col]) {
line.push(self.grid[row][col]);
self.grid[row][col] = null;
}
}
var newLine = self.mergeLine(line);
for (var i = 0; i < newLine.length; i++) {
if (newLine[i]) {
var tile = newLine[i];
var oldRow = tile.gridY;
var newRow = i;
if (oldRow !== newRow || tile.justMerged) {
moved = true;
}
tile.gridX = col;
tile.gridY = newRow;
self.grid[newRow][col] = tile;
if (tile.justMerged) {
merges.push(tile);
}
}
}
}
} else if (direction === 'down') {
for (var col = 0; col < self.gridSize; col++) {
var line = [];
for (var row = self.gridSize - 1; row >= 0; row--) {
if (self.grid[row][col]) {
line.push(self.grid[row][col]);
self.grid[row][col] = null;
}
}
var newLine = self.mergeLine(line);
for (var i = 0; i < newLine.length; i++) {
if (newLine[i]) {
var tile = newLine[i];
var oldRow = tile.gridY;
var newRow = self.gridSize - 1 - i;
if (oldRow !== newRow || tile.justMerged) {
moved = true;
}
tile.gridX = col;
tile.gridY = newRow;
self.grid[newRow][col] = tile;
if (tile.justMerged) {
merges.push(tile);
}
}
}
}
}
if (moved) {
// Animate tiles to new positions
var animatingTiles = 0;
for (var i = 0; i < self.tiles.length; i++) {
var tile = self.tiles[i];
var targetX = self.getCellX(tile.gridX);
var targetY = self.getCellY(tile.gridY);
if (tile.x !== targetX || tile.y !== targetY) {
animatingTiles++;
tile.animateMoveTo(targetX, targetY, function () {
animatingTiles--;
if (animatingTiles === 0) {
// All animations complete
for (var j = 0; j < merges.length; j++) {
merges[j].animateMerge();
LK.getSound('merge').play();
}
self.isAnimating = false;
if (callback && typeof callback === 'function') callback(true);
}
});
}
}
if (animatingTiles === 0) {
self.isAnimating = false;
if (callback && typeof callback === 'function') callback(true);
}
if (merges.length === 0) {
LK.getSound('slide').play();
}
} else {
self.isAnimating = false;
if (callback && typeof callback === 'function') callback(false);
}
return moved;
};
self.mergeLine = function (line) {
var result = [];
var i = 0;
while (i < line.length) {
if (i < line.length - 1 && line[i].value === line[i + 1].value) {
// Merge tiles
var newValue = line[i].value * 2;
line[i].setValue(newValue);
line[i].justMerged = true;
LK.setScore(LK.getScore() + newValue);
// Remove the second tile
self.removeTile(line[i + 1]);
result.push(line[i]);
i += 2;
} else {
result.push(line[i]);
i++;
}
}
return result;
};
return self;
});
var Tile = Container.expand(function (value) {
var self = Container.call(this);
self.value = value;
self.gridX = 0;
self.gridY = 0;
self.isMoving = false;
self.justMerged = false;
function getTileAssetId(value) {
return 'tile' + value;
}
function getTileColor(value) {
if (value <= 4) return 0x776E65;
return 0xF9F6F2;
}
var tileGraphics = self.attachAsset(getTileAssetId(value), {
anchorX: 0.5,
anchorY: 0.5
});
var tileText = new Text2(value.toString(), {
size: value >= 128 ? 40 : value >= 32 ? 50 : 60,
fill: getTileColor(value)
});
tileText.anchor.set(0.5, 0.5);
self.addChild(tileText);
self.setValue = function (newValue) {
self.value = newValue;
self.removeChild(tileGraphics);
tileGraphics = self.attachAsset(getTileAssetId(newValue), {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(tileGraphics, 0);
// Remove old text and create new one with updated properties
self.removeChild(tileText);
tileText = new Text2(newValue.toString(), {
size: newValue >= 128 ? 40 : newValue >= 32 ? 50 : 60,
fill: getTileColor(newValue)
});
tileText.anchor.set(0.5, 0.5);
self.addChild(tileText);
// Pop animation for new value
self.scaleX = 1.2;
self.scaleY = 1.2;
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
};
self.animateMoveTo = function (x, y, callback) {
self.isMoving = true;
tween(self, {
x: x,
y: y
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
if (callback && typeof callback === 'function') callback();
}
});
};
self.animateMerge = function () {
self.scaleX = 1.1;
self.scaleY = 1.1;
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeOut
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0a0a2e
});
/****
* Game Code
****/
var gameGrid;
var scoreTxt;
var bestTxt;
var gameWon = false;
var gameOver = false;
var touchStartX = 0;
var touchStartY = 0;
var minSwipeDistance = 30;
// Initialize score display
scoreTxt = new Text2('0', {
size: 60,
fill: 0x776E65
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 100;
// Create and position game grid
gameGrid = new GameGrid();
gameGrid.x = 2048 / 2;
gameGrid.y = 2732 / 2;
game.addChild(gameGrid);
// Spawn initial tiles
gameGrid.spawnRandomTile();
gameGrid.spawnRandomTile();
// Update score display
scoreTxt.setText('Score: ' + LK.getScore());
// Touch/swipe handling
game.down = function (x, y, obj) {
if (gameOver || gameWon) return;
touchStartX = x;
touchStartY = y;
};
game.up = function (x, y, obj) {
if (gameOver || gameWon || gameGrid.isAnimating) return;
var deltaX = x - touchStartX;
var deltaY = y - touchStartY;
var absDeltaX = Math.abs(deltaX);
var absDeltaY = Math.abs(deltaY);
if (Math.max(absDeltaX, absDeltaY) < minSwipeDistance) return;
var direction;
if (absDeltaX > absDeltaY) {
direction = deltaX > 0 ? 'right' : 'left';
} else {
direction = deltaY > 0 ? 'down' : 'up';
}
gameGrid.move(direction, function (moved) {
if (moved) {
scoreTxt.setText('Score: ' + LK.getScore());
// Check for 2048 tile (win condition)
if (!gameWon) {
for (var i = 0; i < gameGrid.tiles.length; i++) {
if (gameGrid.tiles[i].value === 2048) {
gameWon = true;
LK.setTimeout(function () {
LK.showYouWin();
}, 500);
return;
}
}
}
// Spawn new tile
if (!gameGrid.spawnRandomTile()) {
// Grid is full, check if game over
if (!gameGrid.canMove()) {
gameOver = true;
LK.setTimeout(function () {
LK.showGameOver();
}, 500);
}
}
}
});
};
game.update = function () {
// Game loop updates handled by other systems
};