User prompt
bombalar dokununca 3x alan patlatsın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
oyuna bomba ekle
User prompt
Please fix the bug: 'SecurityError: Failed to read a named property 'removeChild' from 'Window': Blocked a frame with origin "null" from accessing a cross-origin frame.' in or related to this line: 'this.parent.removeChild(this);' Line Number: 256
Code edit (1 edits merged)
Please save this source code
User prompt
Sweet Crush Mania
Initial prompt
şeker patlatma oyunu yap
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Candy = Container.expand(function (type) {
var self = Container.call(this);
self.candyType = type;
self.gridX = 0;
self.gridY = 0;
self.isAnimating = false;
self.isMatched = false;
var candyAssets = ['candy_red', 'candy_blue', 'candy_green', 'candy_yellow', 'candy_purple', 'candy_orange'];
var candyGraphics = self.attachAsset(candyAssets[type], {
anchorX: 0.5,
anchorY: 0.5
});
self.setGridPosition = function (gridX, gridY) {
self.gridX = gridX;
self.gridY = gridY;
self.x = GRID_START_X + gridX * CELL_SIZE + CELL_SIZE / 2;
self.y = GRID_START_Y + gridY * CELL_SIZE + CELL_SIZE / 2;
};
self.animateToPosition = function (targetX, targetY, onComplete) {
self.isAnimating = true;
tween(self, {
x: targetX,
y: targetY
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isAnimating = false;
if (onComplete) onComplete();
}
});
};
self.animatePop = function (onComplete) {
self.isAnimating = true;
tween(self, {
scaleX: 1.3,
scaleY: 1.3,
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isAnimating = false;
if (onComplete) onComplete();
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2d1b69
});
/****
* Game Code
****/
var GRID_SIZE = 8;
var CELL_SIZE = 85;
var GRID_START_X = (2048 - GRID_SIZE * CELL_SIZE) / 2;
var GRID_START_Y = 400;
var grid = [];
var selectedCandy = null;
var isProcessingMatches = false;
var score = 0;
var targetScore = 1000;
var movesLeft = 30;
// Initialize score display
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize target score display
var targetTxt = new Text2('Target: ' + targetScore, {
size: 50,
fill: 0xFFFF88
});
targetTxt.anchor.set(0.5, 0);
targetTxt.y = 80;
LK.gui.top.addChild(targetTxt);
// Initialize moves display
var movesTxt = new Text2('Moves: ' + movesLeft, {
size: 50,
fill: 0x88FFFF
});
movesTxt.anchor.set(0.5, 0);
movesTxt.y = 140;
LK.gui.top.addChild(movesTxt);
// Create background grid
for (var x = 0; x < GRID_SIZE; x++) {
for (var y = 0; y < GRID_SIZE; y++) {
var bgCell = LK.getAsset('gridBG', {
anchorX: 0.5,
anchorY: 0.5
});
bgCell.x = GRID_START_X + x * CELL_SIZE + CELL_SIZE / 2;
bgCell.y = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
bgCell.alpha = 0.3;
game.addChild(bgCell);
}
}
// Initialize grid array
for (var x = 0; x < GRID_SIZE; x++) {
grid[x] = [];
for (var y = 0; y < GRID_SIZE; y++) {
grid[x][y] = null;
}
}
function createRandomCandy(x, y) {
var candyType = Math.floor(Math.random() * 6);
var candy = new Candy(candyType);
candy.setGridPosition(x, y);
grid[x][y] = candy;
game.addChild(candy);
return candy;
}
function fillGrid() {
for (var x = 0; x < GRID_SIZE; x++) {
for (var y = 0; y < GRID_SIZE; y++) {
if (!grid[x][y]) {
createRandomCandy(x, y);
}
}
}
}
function getCandyAt(x, y) {
if (x < 0 || x >= GRID_SIZE || y < 0 || y >= GRID_SIZE) {
return null;
}
return grid[x][y];
}
function swapCandies(candy1, candy2) {
if (!candy1 || !candy2) return;
var tempX = candy1.gridX;
var tempY = candy1.gridY;
grid[candy1.gridX][candy1.gridY] = candy2;
grid[candy2.gridX][candy2.gridY] = candy1;
candy1.gridX = candy2.gridX;
candy1.gridY = candy2.gridY;
candy2.gridX = tempX;
candy2.gridY = tempY;
var targetX1 = GRID_START_X + candy1.gridX * CELL_SIZE + CELL_SIZE / 2;
var targetY1 = GRID_START_Y + candy1.gridY * CELL_SIZE + CELL_SIZE / 2;
var targetX2 = GRID_START_X + candy2.gridX * CELL_SIZE + CELL_SIZE / 2;
var targetY2 = GRID_START_Y + candy2.gridY * CELL_SIZE + CELL_SIZE / 2;
candy1.animateToPosition(targetX1, targetY1);
candy2.animateToPosition(targetX2, targetY2);
}
function findMatches() {
var matches = [];
// Check horizontal matches
for (var y = 0; y < GRID_SIZE; y++) {
var count = 1;
var currentType = grid[0][y] ? grid[0][y].candyType : -1;
for (var x = 1; x < GRID_SIZE; x++) {
var candy = grid[x][y];
if (candy && candy.candyType === currentType) {
count++;
} else {
if (count >= 3) {
for (var i = x - count; i < x; i++) {
if (matches.indexOf(grid[i][y]) === -1) {
matches.push(grid[i][y]);
}
}
}
count = 1;
currentType = candy ? candy.candyType : -1;
}
}
if (count >= 3) {
for (var i = GRID_SIZE - count; i < GRID_SIZE; i++) {
if (matches.indexOf(grid[i][y]) === -1) {
matches.push(grid[i][y]);
}
}
}
}
// Check vertical matches
for (var x = 0; x < GRID_SIZE; x++) {
var count = 1;
var currentType = grid[x][0] ? grid[x][0].candyType : -1;
for (var y = 1; y < GRID_SIZE; y++) {
var candy = grid[x][y];
if (candy && candy.candyType === currentType) {
count++;
} else {
if (count >= 3) {
for (var i = y - count; i < y; i++) {
if (matches.indexOf(grid[x][i]) === -1) {
matches.push(grid[x][i]);
}
}
}
count = 1;
currentType = candy ? candy.candyType : -1;
}
}
if (count >= 3) {
for (var i = GRID_SIZE - count; i < GRID_SIZE; i++) {
if (matches.indexOf(grid[x][i]) === -1) {
matches.push(grid[x][i]);
}
}
}
}
return matches;
}
function removeMatches(matches) {
if (matches.length === 0) return;
LK.getSound('match').play();
score += matches.length * 10;
scoreTxt.setText('Score: ' + score);
for (var i = 0; i < matches.length; i++) {
var candy = matches[i];
candy.isMatched = true;
var finalCallback = i === matches.length - 1 ? function () {
applyGravity();
} : null;
candy.animatePop(function () {
if (this.parent) {
this.parent.removeChild(this);
}
});
grid[candy.gridX][candy.gridY] = null;
}
LK.setTimeout(function () {
applyGravity();
}, 250);
}
function applyGravity() {
var moved = false;
for (var x = 0; x < GRID_SIZE; x++) {
for (var y = GRID_SIZE - 1; y >= 0; y--) {
if (!grid[x][y]) {
// Find candy above to fall down
for (var aboveY = y - 1; aboveY >= 0; aboveY--) {
if (grid[x][aboveY]) {
var candy = grid[x][aboveY];
grid[x][y] = candy;
grid[x][aboveY] = null;
candy.gridY = y;
var targetY = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
candy.animateToPosition(candy.x, targetY);
moved = true;
break;
}
}
}
}
}
if (moved) {
LK.setTimeout(function () {
applyGravity();
}, 350);
} else {
fillEmptySpaces();
}
}
function fillEmptySpaces() {
var hasEmpty = false;
for (var x = 0; x < GRID_SIZE; x++) {
for (var y = 0; y < GRID_SIZE; y++) {
if (!grid[x][y]) {
createRandomCandy(x, y);
hasEmpty = true;
}
}
}
if (hasEmpty) {
LK.setTimeout(function () {
checkForNewMatches();
}, 100);
} else {
checkForNewMatches();
}
}
function checkForNewMatches() {
var matches = findMatches();
if (matches.length > 0) {
removeMatches(matches);
} else {
isProcessingMatches = false;
checkWinCondition();
}
}
function checkWinCondition() {
if (score >= targetScore) {
LK.showYouWin();
} else if (movesLeft <= 0) {
LK.showGameOver();
}
}
function isAdjacent(candy1, candy2) {
var dx = Math.abs(candy1.gridX - candy2.gridX);
var dy = Math.abs(candy1.gridY - candy2.gridY);
return dx === 1 && dy === 0 || dx === 0 && dy === 1;
}
function getGridPosition(x, y) {
var gridX = Math.floor((x - GRID_START_X) / CELL_SIZE);
var gridY = Math.floor((y - GRID_START_Y) / CELL_SIZE);
if (gridX < 0 || gridX >= GRID_SIZE || gridY < 0 || gridY >= GRID_SIZE) {
return null;
}
return {
x: gridX,
y: gridY
};
}
game.down = function (x, y, obj) {
if (isProcessingMatches) return;
var gridPos = getGridPosition(x, y);
if (!gridPos) return;
var candy = getCandyAt(gridPos.x, gridPos.y);
if (!candy || candy.isAnimating) return;
if (!selectedCandy) {
selectedCandy = candy;
candy.alpha = 0.7;
} else {
if (selectedCandy === candy) {
selectedCandy.alpha = 1.0;
selectedCandy = null;
} else if (isAdjacent(selectedCandy, candy)) {
selectedCandy.alpha = 1.0;
// Try the swap
var tempGrid = [];
for (var i = 0; i < GRID_SIZE; i++) {
tempGrid[i] = grid[i].slice();
}
swapCandies(selectedCandy, candy);
LK.setTimeout(function () {
var matches = findMatches();
if (matches.length > 0) {
movesLeft--;
movesTxt.setText('Moves: ' + movesLeft);
isProcessingMatches = true;
removeMatches(matches);
} else {
// Swap back if no matches
swapCandies(selectedCandy, candy);
}
selectedCandy = null;
}, 350);
} else {
selectedCandy.alpha = 1.0;
selectedCandy = candy;
candy.alpha = 0.7;
}
}
};
// Initialize the game board
fillGrid(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,365 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Candy = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.candyType = type;
+ self.gridX = 0;
+ self.gridY = 0;
+ self.isAnimating = false;
+ self.isMatched = false;
+ var candyAssets = ['candy_red', 'candy_blue', 'candy_green', 'candy_yellow', 'candy_purple', 'candy_orange'];
+ var candyGraphics = self.attachAsset(candyAssets[type], {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.setGridPosition = function (gridX, gridY) {
+ self.gridX = gridX;
+ self.gridY = gridY;
+ self.x = GRID_START_X + gridX * CELL_SIZE + CELL_SIZE / 2;
+ self.y = GRID_START_Y + gridY * CELL_SIZE + CELL_SIZE / 2;
+ };
+ self.animateToPosition = function (targetX, targetY, onComplete) {
+ self.isAnimating = true;
+ tween(self, {
+ x: targetX,
+ y: targetY
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ if (onComplete) onComplete();
+ }
+ });
+ };
+ self.animatePop = function (onComplete) {
+ self.isAnimating = true;
+ tween(self, {
+ scaleX: 1.3,
+ scaleY: 1.3,
+ alpha: 0
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ if (onComplete) onComplete();
+ }
+ });
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2d1b69
+});
+
+/****
+* Game Code
+****/
+var GRID_SIZE = 8;
+var CELL_SIZE = 85;
+var GRID_START_X = (2048 - GRID_SIZE * CELL_SIZE) / 2;
+var GRID_START_Y = 400;
+var grid = [];
+var selectedCandy = null;
+var isProcessingMatches = false;
+var score = 0;
+var targetScore = 1000;
+var movesLeft = 30;
+// Initialize score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Initialize target score display
+var targetTxt = new Text2('Target: ' + targetScore, {
+ size: 50,
+ fill: 0xFFFF88
+});
+targetTxt.anchor.set(0.5, 0);
+targetTxt.y = 80;
+LK.gui.top.addChild(targetTxt);
+// Initialize moves display
+var movesTxt = new Text2('Moves: ' + movesLeft, {
+ size: 50,
+ fill: 0x88FFFF
+});
+movesTxt.anchor.set(0.5, 0);
+movesTxt.y = 140;
+LK.gui.top.addChild(movesTxt);
+// Create background grid
+for (var x = 0; x < GRID_SIZE; x++) {
+ for (var y = 0; y < GRID_SIZE; y++) {
+ var bgCell = LK.getAsset('gridBG', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ bgCell.x = GRID_START_X + x * CELL_SIZE + CELL_SIZE / 2;
+ bgCell.y = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
+ bgCell.alpha = 0.3;
+ game.addChild(bgCell);
+ }
+}
+// Initialize grid array
+for (var x = 0; x < GRID_SIZE; x++) {
+ grid[x] = [];
+ for (var y = 0; y < GRID_SIZE; y++) {
+ grid[x][y] = null;
+ }
+}
+function createRandomCandy(x, y) {
+ var candyType = Math.floor(Math.random() * 6);
+ var candy = new Candy(candyType);
+ candy.setGridPosition(x, y);
+ grid[x][y] = candy;
+ game.addChild(candy);
+ return candy;
+}
+function fillGrid() {
+ for (var x = 0; x < GRID_SIZE; x++) {
+ for (var y = 0; y < GRID_SIZE; y++) {
+ if (!grid[x][y]) {
+ createRandomCandy(x, y);
+ }
+ }
+ }
+}
+function getCandyAt(x, y) {
+ if (x < 0 || x >= GRID_SIZE || y < 0 || y >= GRID_SIZE) {
+ return null;
+ }
+ return grid[x][y];
+}
+function swapCandies(candy1, candy2) {
+ if (!candy1 || !candy2) return;
+ var tempX = candy1.gridX;
+ var tempY = candy1.gridY;
+ grid[candy1.gridX][candy1.gridY] = candy2;
+ grid[candy2.gridX][candy2.gridY] = candy1;
+ candy1.gridX = candy2.gridX;
+ candy1.gridY = candy2.gridY;
+ candy2.gridX = tempX;
+ candy2.gridY = tempY;
+ var targetX1 = GRID_START_X + candy1.gridX * CELL_SIZE + CELL_SIZE / 2;
+ var targetY1 = GRID_START_Y + candy1.gridY * CELL_SIZE + CELL_SIZE / 2;
+ var targetX2 = GRID_START_X + candy2.gridX * CELL_SIZE + CELL_SIZE / 2;
+ var targetY2 = GRID_START_Y + candy2.gridY * CELL_SIZE + CELL_SIZE / 2;
+ candy1.animateToPosition(targetX1, targetY1);
+ candy2.animateToPosition(targetX2, targetY2);
+}
+function findMatches() {
+ var matches = [];
+ // Check horizontal matches
+ for (var y = 0; y < GRID_SIZE; y++) {
+ var count = 1;
+ var currentType = grid[0][y] ? grid[0][y].candyType : -1;
+ for (var x = 1; x < GRID_SIZE; x++) {
+ var candy = grid[x][y];
+ if (candy && candy.candyType === currentType) {
+ count++;
+ } else {
+ if (count >= 3) {
+ for (var i = x - count; i < x; i++) {
+ if (matches.indexOf(grid[i][y]) === -1) {
+ matches.push(grid[i][y]);
+ }
+ }
+ }
+ count = 1;
+ currentType = candy ? candy.candyType : -1;
+ }
+ }
+ if (count >= 3) {
+ for (var i = GRID_SIZE - count; i < GRID_SIZE; i++) {
+ if (matches.indexOf(grid[i][y]) === -1) {
+ matches.push(grid[i][y]);
+ }
+ }
+ }
+ }
+ // Check vertical matches
+ for (var x = 0; x < GRID_SIZE; x++) {
+ var count = 1;
+ var currentType = grid[x][0] ? grid[x][0].candyType : -1;
+ for (var y = 1; y < GRID_SIZE; y++) {
+ var candy = grid[x][y];
+ if (candy && candy.candyType === currentType) {
+ count++;
+ } else {
+ if (count >= 3) {
+ for (var i = y - count; i < y; i++) {
+ if (matches.indexOf(grid[x][i]) === -1) {
+ matches.push(grid[x][i]);
+ }
+ }
+ }
+ count = 1;
+ currentType = candy ? candy.candyType : -1;
+ }
+ }
+ if (count >= 3) {
+ for (var i = GRID_SIZE - count; i < GRID_SIZE; i++) {
+ if (matches.indexOf(grid[x][i]) === -1) {
+ matches.push(grid[x][i]);
+ }
+ }
+ }
+ }
+ return matches;
+}
+function removeMatches(matches) {
+ if (matches.length === 0) return;
+ LK.getSound('match').play();
+ score += matches.length * 10;
+ scoreTxt.setText('Score: ' + score);
+ for (var i = 0; i < matches.length; i++) {
+ var candy = matches[i];
+ candy.isMatched = true;
+ var finalCallback = i === matches.length - 1 ? function () {
+ applyGravity();
+ } : null;
+ candy.animatePop(function () {
+ if (this.parent) {
+ this.parent.removeChild(this);
+ }
+ });
+ grid[candy.gridX][candy.gridY] = null;
+ }
+ LK.setTimeout(function () {
+ applyGravity();
+ }, 250);
+}
+function applyGravity() {
+ var moved = false;
+ for (var x = 0; x < GRID_SIZE; x++) {
+ for (var y = GRID_SIZE - 1; y >= 0; y--) {
+ if (!grid[x][y]) {
+ // Find candy above to fall down
+ for (var aboveY = y - 1; aboveY >= 0; aboveY--) {
+ if (grid[x][aboveY]) {
+ var candy = grid[x][aboveY];
+ grid[x][y] = candy;
+ grid[x][aboveY] = null;
+ candy.gridY = y;
+ var targetY = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
+ candy.animateToPosition(candy.x, targetY);
+ moved = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if (moved) {
+ LK.setTimeout(function () {
+ applyGravity();
+ }, 350);
+ } else {
+ fillEmptySpaces();
+ }
+}
+function fillEmptySpaces() {
+ var hasEmpty = false;
+ for (var x = 0; x < GRID_SIZE; x++) {
+ for (var y = 0; y < GRID_SIZE; y++) {
+ if (!grid[x][y]) {
+ createRandomCandy(x, y);
+ hasEmpty = true;
+ }
+ }
+ }
+ if (hasEmpty) {
+ LK.setTimeout(function () {
+ checkForNewMatches();
+ }, 100);
+ } else {
+ checkForNewMatches();
+ }
+}
+function checkForNewMatches() {
+ var matches = findMatches();
+ if (matches.length > 0) {
+ removeMatches(matches);
+ } else {
+ isProcessingMatches = false;
+ checkWinCondition();
+ }
+}
+function checkWinCondition() {
+ if (score >= targetScore) {
+ LK.showYouWin();
+ } else if (movesLeft <= 0) {
+ LK.showGameOver();
+ }
+}
+function isAdjacent(candy1, candy2) {
+ var dx = Math.abs(candy1.gridX - candy2.gridX);
+ var dy = Math.abs(candy1.gridY - candy2.gridY);
+ return dx === 1 && dy === 0 || dx === 0 && dy === 1;
+}
+function getGridPosition(x, y) {
+ var gridX = Math.floor((x - GRID_START_X) / CELL_SIZE);
+ var gridY = Math.floor((y - GRID_START_Y) / CELL_SIZE);
+ if (gridX < 0 || gridX >= GRID_SIZE || gridY < 0 || gridY >= GRID_SIZE) {
+ return null;
+ }
+ return {
+ x: gridX,
+ y: gridY
+ };
+}
+game.down = function (x, y, obj) {
+ if (isProcessingMatches) return;
+ var gridPos = getGridPosition(x, y);
+ if (!gridPos) return;
+ var candy = getCandyAt(gridPos.x, gridPos.y);
+ if (!candy || candy.isAnimating) return;
+ if (!selectedCandy) {
+ selectedCandy = candy;
+ candy.alpha = 0.7;
+ } else {
+ if (selectedCandy === candy) {
+ selectedCandy.alpha = 1.0;
+ selectedCandy = null;
+ } else if (isAdjacent(selectedCandy, candy)) {
+ selectedCandy.alpha = 1.0;
+ // Try the swap
+ var tempGrid = [];
+ for (var i = 0; i < GRID_SIZE; i++) {
+ tempGrid[i] = grid[i].slice();
+ }
+ swapCandies(selectedCandy, candy);
+ LK.setTimeout(function () {
+ var matches = findMatches();
+ if (matches.length > 0) {
+ movesLeft--;
+ movesTxt.setText('Moves: ' + movesLeft);
+ isProcessingMatches = true;
+ removeMatches(matches);
+ } else {
+ // Swap back if no matches
+ swapCandies(selectedCandy, candy);
+ }
+ selectedCandy = null;
+ }, 350);
+ } else {
+ selectedCandy.alpha = 1.0;
+ selectedCandy = candy;
+ candy.alpha = 0.7;
+ }
+ }
+};
+// Initialize the game board
+fillGrid();
\ No newline at end of file
bomba. In-Game asset. 2d. High contrast. No shadows
arka yuvarlak ve açık mavi yap
arkası yuvarlak olsun
göz yaşını sil
gülen yüz arkası yuvarlak pembe renk. In-Game asset. 2d. High contrast. No shadows
kızgın bakan bir yüz çiz arkası yuvarlak kırmızı renk. In-Game asset. 2d. High contrast. No shadows
düşünen bir yüz arkası yuvarlak sarı renk olsun. In-Game asset. High contrast. No shadows. 2d