User prompt
Daha büyük hale getir
User prompt
Oyun alanını ve icersindeki gemleri ekrana tamamen doldur
User prompt
Yer değiştirmeyi birer kare olarak yap eğer birbirinle eşleşmiyorsa geri dönsün ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Yer değiştirmesini kaydırma yap ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Gem Swap Adventure
Initial prompt
Candy crush ve jewel ancient benzeri
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Gem = Container.expand(function (gemType, gridX, gridY) { var self = Container.call(this); self.gemType = gemType; self.gridX = gridX; self.gridY = gridY; self.isAnimating = false; var gemAssets = ['gemRed', 'gemBlue', 'gemGreen', 'gemYellow', 'gemPurple', 'gemOrange']; var gemGraphics = self.attachAsset(gemAssets[gemType], { anchorX: 0.5, anchorY: 0.5 }); self.setGridPosition = function (x, y) { self.gridX = x; self.gridY = y; }; self.animateToPosition = function (targetX, targetY, duration, onComplete) { if (!duration) duration = 200; self.isAnimating = true; tween(self, { x: targetX, y: targetY }, { duration: duration, easing: tween.easeOut, onFinish: function onFinish() { self.isAnimating = false; if (onComplete) onComplete(); } }); }; self.destroy = function () { if (self.parent) { self.parent.removeChild(self); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2C1810 }); /**** * Game Code ****/ var GRID_SIZE = 8; var CELL_SIZE = 90; var BOARD_OFFSET_X = (2048 - GRID_SIZE * CELL_SIZE) / 2; var BOARD_OFFSET_Y = 400; var gameBoard = []; var selectedGem = null; var draggedGem = null; var dragStartPos = null; var isDragging = false; var isSwapping = false; var score = 0; var comboMultiplier = 1; // Create board background var boardBg = game.attachAsset('boardBg', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: BOARD_OFFSET_Y + GRID_SIZE * CELL_SIZE / 2 }); // Create score display var scoreTxt = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); scoreTxt.y = 100; // Initialize empty board function initializeBoard() { gameBoard = []; for (var x = 0; x < GRID_SIZE; x++) { gameBoard[x] = []; for (var y = 0; y < GRID_SIZE; y++) { gameBoard[x][y] = null; } } } // Fill board with random gems function fillBoard() { for (var x = 0; x < GRID_SIZE; x++) { for (var y = 0; y < GRID_SIZE; y++) { if (!gameBoard[x][y]) { var gemType = Math.floor(Math.random() * 6); var gem = new Gem(gemType, x, y); var worldPos = gridToWorld(x, y); gem.x = worldPos.x; gem.y = worldPos.y; gameBoard[x][y] = gem; game.addChild(gem); } } } } // Convert grid coordinates to world coordinates function gridToWorld(gridX, gridY) { return { x: BOARD_OFFSET_X + gridX * CELL_SIZE + CELL_SIZE / 2, y: BOARD_OFFSET_Y + gridY * CELL_SIZE + CELL_SIZE / 2 }; } // Convert world coordinates to grid coordinates function worldToGrid(worldX, worldY) { var gridX = Math.floor((worldX - BOARD_OFFSET_X) / CELL_SIZE); var gridY = Math.floor((worldY - BOARD_OFFSET_Y) / CELL_SIZE); if (gridX < 0 || gridX >= GRID_SIZE || gridY < 0 || gridY >= GRID_SIZE) { return null; } return { x: gridX, y: gridY }; } // Check if two grid positions are adjacent function areAdjacent(pos1, pos2) { var dx = Math.abs(pos1.x - pos2.x); var dy = Math.abs(pos1.y - pos2.y); return dx === 1 && dy === 0 || dx === 0 && dy === 1; } // Check for matches starting at position function checkMatches(startX, startY) { var gem = gameBoard[startX][startY]; if (!gem) return []; var matches = []; var gemType = gem.gemType; // Check horizontal matches var horizontalMatches = [gem]; // Check left for (var x = startX - 1; x >= 0; x--) { if (gameBoard[x][startY] && gameBoard[x][startY].gemType === gemType) { horizontalMatches.unshift(gameBoard[x][startY]); } else { break; } } // Check right for (var x = startX + 1; x < GRID_SIZE; x++) { if (gameBoard[x][startY] && gameBoard[x][startY].gemType === gemType) { horizontalMatches.push(gameBoard[x][startY]); } else { break; } } if (horizontalMatches.length >= 3) { matches = matches.concat(horizontalMatches); } // Check vertical matches var verticalMatches = [gem]; // Check up for (var y = startY - 1; y >= 0; y--) { if (gameBoard[startX][y] && gameBoard[startX][y].gemType === gemType) { verticalMatches.unshift(gameBoard[startX][y]); } else { break; } } // Check down for (var y = startY + 1; y < GRID_SIZE; y++) { if (gameBoard[startX][y] && gameBoard[startX][y].gemType === gemType) { verticalMatches.push(gameBoard[startX][y]); } else { break; } } if (verticalMatches.length >= 3) { matches = matches.concat(verticalMatches); } // Remove duplicates var uniqueMatches = []; for (var i = 0; i < matches.length; i++) { var found = false; for (var j = 0; j < uniqueMatches.length; j++) { if (matches[i] === uniqueMatches[j]) { found = true; break; } } if (!found) { uniqueMatches.push(matches[i]); } } return uniqueMatches; } // Find all matches on the board function findAllMatches() { var allMatches = []; var processedGems = []; for (var x = 0; x < GRID_SIZE; x++) { for (var y = 0; y < GRID_SIZE; y++) { if (gameBoard[x][y]) { var matches = checkMatches(x, y); for (var i = 0; i < matches.length; i++) { var gem = matches[i]; var found = false; for (var j = 0; j < processedGems.length; j++) { if (processedGems[j] === gem) { found = true; break; } } if (!found) { allMatches.push(gem); processedGems.push(gem); } } } } } return allMatches; } // Clear matched gems function clearMatches(matches) { if (matches.length === 0) return; LK.getSound('match').play(); var points = matches.length * 10 * comboMultiplier; score += points; scoreTxt.setText('Score: ' + score); for (var i = 0; i < matches.length; i++) { var gem = matches[i]; gameBoard[gem.gridX][gem.gridY] = null; gem.destroy(); } } // Apply gravity to make gems fall function applyGravity() { var moved = false; for (var x = 0; x < GRID_SIZE; x++) { for (var y = GRID_SIZE - 1; y >= 0; y--) { if (!gameBoard[x][y]) { // Find gem above to fall down for (var searchY = y - 1; searchY >= 0; searchY--) { if (gameBoard[x][searchY]) { var gem = gameBoard[x][searchY]; gameBoard[x][y] = gem; gameBoard[x][searchY] = null; gem.setGridPosition(x, y); var worldPos = gridToWorld(x, y); gem.animateToPosition(worldPos.x, worldPos.y, 300); moved = true; break; } } } } } return moved; } // Fill empty spaces with new gems function fillEmptySpaces() { for (var x = 0; x < GRID_SIZE; x++) { for (var y = 0; y < GRID_SIZE; y++) { if (!gameBoard[x][y]) { var gemType = Math.floor(Math.random() * 6); var gem = new Gem(gemType, x, y); var worldPos = gridToWorld(x, y); gem.x = worldPos.x; gem.y = worldPos.y - GRID_SIZE * CELL_SIZE; gameBoard[x][y] = gem; game.addChild(gem); gem.animateToPosition(worldPos.x, worldPos.y, 400); } } } } // Process cascading matches function processCascade() { LK.setTimeout(function () { var matches = findAllMatches(); if (matches.length > 0) { comboMultiplier++; clearMatches(matches); LK.setTimeout(function () { var moved = applyGravity(); fillEmptySpaces(); if (moved || matches.length > 0) { processCascade(); } else { comboMultiplier = 1; isSwapping = false; } }, 400); } else { comboMultiplier = 1; isSwapping = false; } }, 200); } // Swap two gems function swapGems(gem1, gem2) { if (isSwapping) return; isSwapping = true; LK.getSound('swap').play(); var tempX = gem1.gridX; var tempY = gem1.gridY; gem1.setGridPosition(gem2.gridX, gem2.gridY); gem2.setGridPosition(tempX, tempY); gameBoard[gem1.gridX][gem1.gridY] = gem1; gameBoard[gem2.gridX][gem2.gridY] = gem2; var pos1 = gridToWorld(gem1.gridX, gem1.gridY); var pos2 = gridToWorld(gem2.gridX, gem2.gridY); gem1.animateToPosition(pos1.x, pos1.y, 200); gem2.animateToPosition(pos2.x, pos2.y, 200); LK.setTimeout(function () { var matches = findAllMatches(); if (matches.length > 0) { clearMatches(matches); processCascade(); } else { // Invalid move, swap back var tempX = gem1.gridX; var tempY = gem1.gridY; gem1.setGridPosition(gem2.gridX, gem2.gridY); gem2.setGridPosition(tempX, tempY); gameBoard[gem1.gridX][gem1.gridY] = gem1; gameBoard[gem2.gridX][gem2.gridY] = gem2; var pos1 = gridToWorld(gem1.gridX, gem1.gridY); var pos2 = gridToWorld(gem2.gridX, gem2.gridY); gem1.animateToPosition(pos1.x, pos1.y, 200); gem2.animateToPosition(pos2.x, pos2.y, 200); LK.setTimeout(function () { isSwapping = false; }, 200); } }, 200); } // Game input handling game.down = function (x, y, obj) { if (isSwapping) return; var gridPos = worldToGrid(x, y); if (!gridPos) return; var clickedGem = gameBoard[gridPos.x][gridPos.y]; if (!clickedGem) return; draggedGem = clickedGem; dragStartPos = { x: x, y: y }; isDragging = true; draggedGem.alpha = 0.7; }; game.move = function (x, y, obj) { if (!isDragging || !draggedGem || isSwapping) return; // Move the dragged gem with finger/mouse var worldPos = gridToWorld(draggedGem.gridX, draggedGem.gridY); draggedGem.x = worldPos.x + (x - dragStartPos.x); draggedGem.y = worldPos.y + (y - dragStartPos.y); }; game.up = function (x, y, obj) { if (!isDragging || !draggedGem || isSwapping) return; var endGridPos = worldToGrid(x, y); var startGridPos = { x: draggedGem.gridX, y: draggedGem.gridY }; // Reset gem position var worldPos = gridToWorld(draggedGem.gridX, draggedGem.gridY); draggedGem.animateToPosition(worldPos.x, worldPos.y, 200); draggedGem.alpha = 1.0; // Check if we dragged to an adjacent valid position if (endGridPos && gameBoard[endGridPos.x][endGridPos.y] && areAdjacent(startGridPos, endGridPos)) { var targetGem = gameBoard[endGridPos.x][endGridPos.y]; swapGems(draggedGem, targetGem); } draggedGem = null; dragStartPos = null; isDragging = false; }; // Initialize the game initializeBoard(); fillBoard(); // Initial match clearing LK.setTimeout(function () { var matches = findAllMatches(); if (matches.length > 0) { clearMatches(matches); processCascade(); } }, 100);
===================================================================
--- original.js
+++ change.js
@@ -59,8 +59,11 @@
var BOARD_OFFSET_X = (2048 - GRID_SIZE * CELL_SIZE) / 2;
var BOARD_OFFSET_Y = 400;
var gameBoard = [];
var selectedGem = null;
+var draggedGem = null;
+var dragStartPos = null;
+var isDragging = false;
var isSwapping = false;
var score = 0;
var comboMultiplier = 1;
// Create board background
@@ -341,29 +344,42 @@
var gridPos = worldToGrid(x, y);
if (!gridPos) return;
var clickedGem = gameBoard[gridPos.x][gridPos.y];
if (!clickedGem) return;
- if (!selectedGem) {
- selectedGem = clickedGem;
- selectedGem.alpha = 0.7;
- } else if (selectedGem === clickedGem) {
- selectedGem.alpha = 1.0;
- selectedGem = null;
- } else if (areAdjacent({
- x: selectedGem.gridX,
- y: selectedGem.gridY
- }, {
- x: clickedGem.gridX,
- y: clickedGem.gridY
- })) {
- selectedGem.alpha = 1.0;
- swapGems(selectedGem, clickedGem);
- selectedGem = null;
- } else {
- selectedGem.alpha = 1.0;
- selectedGem = clickedGem;
- selectedGem.alpha = 0.7;
+ draggedGem = clickedGem;
+ dragStartPos = {
+ x: x,
+ y: y
+ };
+ isDragging = true;
+ draggedGem.alpha = 0.7;
+};
+game.move = function (x, y, obj) {
+ if (!isDragging || !draggedGem || isSwapping) return;
+ // Move the dragged gem with finger/mouse
+ var worldPos = gridToWorld(draggedGem.gridX, draggedGem.gridY);
+ draggedGem.x = worldPos.x + (x - dragStartPos.x);
+ draggedGem.y = worldPos.y + (y - dragStartPos.y);
+};
+game.up = function (x, y, obj) {
+ if (!isDragging || !draggedGem || isSwapping) return;
+ var endGridPos = worldToGrid(x, y);
+ var startGridPos = {
+ x: draggedGem.gridX,
+ y: draggedGem.gridY
+ };
+ // Reset gem position
+ var worldPos = gridToWorld(draggedGem.gridX, draggedGem.gridY);
+ draggedGem.animateToPosition(worldPos.x, worldPos.y, 200);
+ draggedGem.alpha = 1.0;
+ // Check if we dragged to an adjacent valid position
+ if (endGridPos && gameBoard[endGridPos.x][endGridPos.y] && areAdjacent(startGridPos, endGridPos)) {
+ var targetGem = gameBoard[endGridPos.x][endGridPos.y];
+ swapGems(draggedGem, targetGem);
}
+ draggedGem = null;
+ dragStartPos = null;
+ isDragging = false;
};
// Initialize the game
initializeBoard();
fillBoard();
İcersi boş
Rengi acık mavi gökyüzümsü olsun küçük bulutlar olsun
Alev spiral parçacık. In-Game asset. 2d. High contrast. No shadows
Su damlası patlama parçacık. In-Game asset. 2d. High contrast. No shadows
Karadelik vortex parçacık spiral. In-Game asset. 2d. High contrast. No shadows
Yeşil yaprak süzülen. In-Game asset. 2d. High contrast. No shadows
Yıldız patlama parlak. In-Game asset. 2d. High contrast. No shadows
Lav topu erimiş. In-Game asset. 2d. High contrast. No shadows
Yukarıdan aşağıya sonsuz döngü olucak şekilde
Çerçevesinde alev parçacıklari olsun ve çerçeve rengi içindeki alev renklerine uygun grandyan olsun
Bunun su olan versiyonunu yap
Arkaplanın rengini yeşil grandyan yap
Renkleri hafif kahverengi hafif siyah ve koyu olsun
Bunun güneş versiyonunu yap ve icersindeki alev görseli yerine güneş versiyonu olsun
Çerçevesi yuvarlak olsun ve orta kısmı boş olmasın
Havai fişek döngü spiral renkli. In-Game asset. 2d. High contrast. No shadows
Health bar, grandyan, green,. In-Game asset. 2d. High contrast. No shadows
Hiç birşeye dokunma sadece yeşil olan kısımları kırmızı ile yer değiştir