User prompt
Kaydırma sadece “Swipe” yazan alanda değil, tüm ekranda yapılabilsin. Swipe yazısını kaldır.
User prompt
Bombayı patlattığımda oluşan boşluk geç kapanıyor. Patlayan yem yok olunca diğerleri hemen kuyruğun kalanıyla birleşsin. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Oyun alanını en yukarı al. UI yazıları hemen oyun alanının altında olsun.
User prompt
Bomba her 5 yemde bir spawn olsun. 5 sn içinde alınmazsa yok olsun. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
“Swipe” yazısını 5 kat büyüt. Ekranın üstünde yazan “Next color” UI yazısını 4 birim sola al.
User prompt
Oyun alanın altında kalan tüm alan Swipe’ı algılasın ve yılanı kontrol edebilsin.
User prompt
Sağ ve sol oyun alanı sınırları ekranın kenarlarına gelecek şekilde oyun alanını büyüt.
User prompt
Oynanabilir alanı kare yap ve biraz daha aşağı alıp Swipe alanını küçült, UI alanını büyüt. UI alanında score solda yazsın, sonraki renk sağda yazsın ve font 2 daha büyüsün. Swipe alanının ortasında oyuncuya bilgi bermek amacıyla çok göz almayabin şekilde “SWIPE” yazsın.
User prompt
Yılanın hızını her 5 yemde bir 0.1 yerine 0.05 artır.
User prompt
Görsellikle alakalı komutlarımdan önceki eski görselliğe ve assetlere geri dön.
User prompt
Görselleri piksel yerine mobil oyunlara uygun 2D çizimler ile değiştir.
User prompt
Lokomotif ve vagonlar için 2D görsel üret.
User prompt
Yılanın başını lokomotif, yemleri de vagon görselleriyle değiştir.
User prompt
Yılın ve yemlerin boyutunu 2 katına çıkar.
User prompt
Şu an seçili olan yemdeyken patlattığımda o yemin sahip olduğu renkteki diğer yemler de patlıyor. Patlatmak için tıkladığımda spesifik olarak sadece seçili olan yem yok olsun. Diğerleri kalsın.
User prompt
Şu an bomba aldığımda seçili olan yemdeyken tek tıkladığımda yem yok olmuyor. Tek tıkladığımda seçili olan yem yok olsun.
User prompt
Bombayı patlattığımda sadece seçili olan renkteki yem patlasın. Diğer yemler yalnızca aynı renkten 3 veya daha fazla yan yana geldiğinde patlasın. Patlatma çift tıklama yerine tek tıklamayla olsun.
User prompt
Yılanın hızını her 5 yemde bir 0.5 yerine 0.1 artır.
User prompt
Yılanın hızını her 5 yemde 1.5 yerine 0.5 artır.
User prompt
Yılanın hızını her 5 yemde 1.5 artır.
User prompt
Yılanın 3 veya daha az kuyruk parçası varsa bomba oluşturma.
User prompt
Make the playable area the top half of the screen. Place the UI (Score, etc.) at the very top, outside the playable area. The playable area should start right after the UI ends and extend vertically to the middle of the screen. The bottom half of the screen should be reserved for swipe and tap input. Outline the playable area with a white border.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Pickup = Container.expand(function (color, x, y) {
var self = Container.call(this);
self.color = color;
self.gridX = x;
self.gridY = y;
self.isBomb = color === 'bomb';
var assetId = self.isBomb ? 'bombPickup' : 'pickup' + color.charAt(0).toUpperCase() + color.slice(1);
self.graphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x * GRID_SIZE + GRID_SIZE / 2;
self.y = y * GRID_SIZE + GRID_SIZE / 2 + PLAYABLE_START_Y;
return self;
});
var SnakeHead = Container.expand(function (x, y) {
var self = Container.call(this);
self.gridX = x;
self.gridY = y;
self.direction = {
x: 1,
y: 0
};
self.graphics = self.attachAsset('snakeHead', {
anchorX: 0.5,
anchorY: 0.5
});
self.setPosition = function (gridX, gridY) {
self.gridX = gridX;
self.gridY = gridY;
self.x = gridX * GRID_SIZE + GRID_SIZE / 2;
self.y = gridY * GRID_SIZE + GRID_SIZE / 2 + PLAYABLE_START_Y;
};
return self;
});
var SnakeSegment = Container.expand(function (color, x, y) {
var self = Container.call(this);
self.color = color;
self.gridX = x;
self.gridY = y;
self.isHighlighted = false;
var assetId = 'snakeSegment' + color.charAt(0).toUpperCase() + color.slice(1);
self.graphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.setPosition = function (gridX, gridY) {
self.gridX = gridX;
self.gridY = gridY;
self.x = gridX * GRID_SIZE + GRID_SIZE / 2;
self.y = gridY * GRID_SIZE + GRID_SIZE / 2 + PLAYABLE_START_Y;
};
self.highlight = function (highlight) {
self.isHighlighted = highlight;
if (highlight) {
self.graphics.alpha = 0.7;
self.graphics.scaleX = 1.2;
self.graphics.scaleY = 1.2;
} else {
self.graphics.alpha = 1.0;
self.graphics.scaleX = 1.0;
self.graphics.scaleY = 1.0;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
var GRID_SIZE = 50;
var UI_HEIGHT = 120; // Height reserved for UI at top
var PLAYABLE_HEIGHT = (2732 - UI_HEIGHT) / 2; // Top half minus UI
var GRID_WIDTH = Math.floor(2048 / GRID_SIZE);
var GRID_HEIGHT = Math.floor(PLAYABLE_HEIGHT / GRID_SIZE);
var PLAYABLE_START_Y = UI_HEIGHT;
var snake = [];
var snakeHead = null;
var pickups = [];
var gameSpeed = 150;
var moveTimer = 0;
var colors = ['red', 'yellow', 'blue'];
var nextPickupColor = colors[Math.floor(Math.random() * colors.length)];
var bombMode = false;
var bombIndex = 0;
var bombTimer = 0;
var gameOver = false;
var foodCounter = 0; // Track number of foods eaten
var baseSpeed = 150; // Base game speed
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var nextColorTxt = new Text2('Next: Red', {
size: 50,
fill: 0xFFFFFF
});
nextColorTxt.anchor.set(1, 0);
nextColorTxt.x = -20;
nextColorTxt.y = 20;
LK.gui.topRight.addChild(nextColorTxt);
function initializeGame() {
// Create snake head
snakeHead = new SnakeHead(Math.floor(GRID_WIDTH / 2), Math.floor(GRID_HEIGHT / 2));
game.addChild(snakeHead);
snakeHead.setPosition(snakeHead.gridX, snakeHead.gridY);
// Create initial tail segments
for (var i = 1; i <= 3; i++) {
var color = colors[Math.floor(Math.random() * colors.length)];
var segment = new SnakeSegment(color, snakeHead.gridX - i, snakeHead.gridY);
snake.push(segment);
game.addChild(segment);
segment.setPosition(segment.gridX, segment.gridY);
}
spawnRandomPickup();
updateNextColorDisplay();
}
function spawnRandomPickup() {
var attempts = 0;
var x, y;
do {
x = Math.floor(Math.random() * GRID_WIDTH);
y = Math.floor(Math.random() * GRID_HEIGHT);
attempts++;
} while (isPositionOccupied(x, y) && attempts < 100);
if (attempts < 100) {
// Only spawn bomb if snake has more than 3 tail segments
var isBomb = snake.length > 3 && Math.random() < 0.15; // 15% chance for bomb
var color = isBomb ? 'bomb' : nextPickupColor;
var pickup = new Pickup(color, x, y);
pickups.push(pickup);
game.addChild(pickup);
if (!isBomb) {
nextPickupColor = colors[Math.floor(Math.random() * colors.length)];
updateNextColorDisplay();
}
}
}
function isPositionOccupied(x, y) {
if (snakeHead.gridX === x && snakeHead.gridY === y) return true;
for (var i = 0; i < snake.length; i++) {
if (snake[i].gridX === x && snake[i].gridY === y) return true;
}
for (var j = 0; j < pickups.length; j++) {
if (pickups[j].gridX === x && pickups[j].gridY === y) return true;
}
return false;
}
function updateNextColorDisplay() {
nextColorTxt.setText('Next: ' + nextPickupColor.charAt(0).toUpperCase() + nextPickupColor.slice(1));
}
function moveSnake() {
if (gameOver || bombMode) return;
var newX = snakeHead.gridX + snakeHead.direction.x;
var newY = snakeHead.gridY + snakeHead.direction.y;
// Wrap around screen edges
if (newX < 0) newX = GRID_WIDTH - 1;
if (newX >= GRID_WIDTH) newX = 0;
if (newY < 0) newY = GRID_HEIGHT - 1;
if (newY >= GRID_HEIGHT) newY = 0;
// Check for self collision
for (var i = 0; i < snake.length; i++) {
if (snake[i].gridX === newX && snake[i].gridY === newY) {
gameOver = true;
LK.showGameOver();
return;
}
}
// Move tail segments
if (snake.length > 0) {
for (var j = snake.length - 1; j > 0; j--) {
snake[j].setPosition(snake[j - 1].gridX, snake[j - 1].gridY);
}
snake[0].setPosition(snakeHead.gridX, snakeHead.gridY);
}
// Move head
snakeHead.setPosition(newX, newY);
// Check for pickup collision
for (var k = pickups.length - 1; k >= 0; k--) {
var pickup = pickups[k];
if (pickup.gridX === newX && pickup.gridY === newY) {
if (pickup.isBomb) {
handleBombPickup();
} else {
handleColorPickup(pickup.color);
}
pickup.destroy();
pickups.splice(k, 1);
spawnRandomPickup();
break;
}
}
checkForMatches();
}
function handleColorPickup(color) {
LK.getSound('collect').play();
// Get the position of the last tail segment, or head if no tail exists
var lastX, lastY;
if (snake.length > 0) {
lastX = snake[snake.length - 1].gridX;
lastY = snake[snake.length - 1].gridY;
} else {
lastX = snakeHead.gridX;
lastY = snakeHead.gridY;
}
var newSegment = new SnakeSegment(color, lastX, lastY);
snake.push(newSegment);
game.addChild(newSegment);
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
// Increment food counter and check for speed increase
foodCounter++;
if (foodCounter % 5 === 0) {
// Increase speed by reducing gameSpeed (making it 0.1x faster)
gameSpeed = Math.max(30, gameSpeed - gameSpeed * 0.1); // Prevent speed from getting too fast
}
}
function handleBombPickup() {
if (snake.length === 0) return;
LK.getSound('bomb').play();
bombMode = true;
bombIndex = 0;
bombTimer = 0;
// Highlight first segment
snake[bombIndex].highlight(true);
}
function processBombMovement() {
if (!bombMode) return;
bombTimer++;
if (bombTimer >= 30) {
// Move every 30 ticks (0.5 seconds)
snake[bombIndex].highlight(false);
bombIndex++;
if (bombIndex >= snake.length) {
bombIndex = 0;
}
snake[bombIndex].highlight(true);
bombTimer = 0;
}
}
function triggerBomb() {
if (!bombMode || snake.length === 0) return;
var targetColor = snake[bombIndex].color;
snake[bombIndex].highlight(false);
bombMode = false;
// Find all pickups with the target color
var pickupsToRemove = [];
for (var i = 0; i < pickups.length; i++) {
if (pickups[i].color === targetColor && !pickups[i].isBomb) {
pickupsToRemove.push(i);
}
}
// Find all snake segments with the target color
var segmentsToRemove = [];
for (var s = 0; s < snake.length; s++) {
if (snake[s].color === targetColor) {
segmentsToRemove.push(s);
}
}
var hasItemsToExplode = pickupsToRemove.length > 0 || segmentsToRemove.length > 0;
if (hasItemsToExplode) {
LK.getSound('explode').play();
// Create explosion effect on each pickup before destroying
for (var j = 0; j < pickupsToRemove.length; j++) {
var pickupIndex = pickupsToRemove[j];
var pickup = pickups[pickupIndex];
// Tween explosion effect
tween(pickup.graphics, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut
});
}
// Create explosion effect on snake segments
for (var seg = 0; seg < segmentsToRemove.length; seg++) {
var segmentIndex = segmentsToRemove[seg];
var segment = snake[segmentIndex];
// Tween explosion effect
tween(segment.graphics, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut
});
}
// Remove pickups and segments after animation delay
LK.setTimeout(function () {
// Remove pickups in reverse order to maintain indices
for (var k = pickupsToRemove.length - 1; k >= 0; k--) {
var index = pickupsToRemove[k];
pickups[index].destroy();
pickups.splice(index, 1);
}
// Remove snake segments in reverse order to maintain indices
for (var r = segmentsToRemove.length - 1; r >= 0; r--) {
var segIndex = segmentsToRemove[r];
snake[segIndex].destroy();
snake.splice(segIndex, 1);
}
// Award points
var totalItems = pickupsToRemove.length + segmentsToRemove.length;
var points = totalItems * 10;
LK.setScore(LK.getScore() + points);
scoreTxt.setText('Score: ' + LK.getScore());
// Flash effect
LK.effects.flashScreen(0xffffff, 300);
// Spawn new pickups to replace destroyed ones
for (var m = 0; m < pickupsToRemove.length; m++) {
spawnRandomPickup();
}
}, 300);
}
}
function checkForMatches() {
var matchFound = false;
var toRemove = [];
for (var i = 0; i < snake.length - 2; i++) {
var count = 1;
var currentColor = snake[i].color;
for (var j = i + 1; j < snake.length; j++) {
if (snake[j].color === currentColor) {
count++;
} else {
break;
}
}
if (count >= 3) {
for (var k = i; k < i + count; k++) {
toRemove.push(k);
}
matchFound = true;
i += count - 1;
}
}
if (toRemove.length > 0) {
LK.getSound('explode').play();
// Remove matched segments
for (var m = toRemove.length - 1; m >= 0; m--) {
var index = toRemove[m];
snake[index].destroy();
snake.splice(index, 1);
}
// Award points
var points = toRemove.length * 10;
LK.setScore(LK.getScore() + points);
scoreTxt.setText('Score: ' + LK.getScore());
// Flash effect
LK.effects.flashScreen(0xffffff, 200);
}
return matchFound;
}
// Swipe detection variables
var swipeStartX = 0;
var swipeStartY = 0;
var minSwipeDistance = 50;
var isSwipeStarted = false;
function handleSwipe(startX, startY, endX, endY) {
if (gameOver) return;
if (bombMode) {
return;
}
var deltaX = endX - startX;
var deltaY = endY - startY;
var swipeDistance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// Check if swipe is long enough
if (swipeDistance < minSwipeDistance) return;
if (Math.abs(deltaX) > Math.abs(deltaY)) {
// Horizontal swipe
if (deltaX > 0 && snakeHead.direction.x !== -1) {
// Swipe right
snakeHead.direction = {
x: 1,
y: 0
};
} else if (deltaX < 0 && snakeHead.direction.x !== 1) {
// Swipe left
snakeHead.direction = {
x: -1,
y: 0
};
}
} else {
// Vertical swipe
if (deltaY > 0 && snakeHead.direction.y !== -1) {
// Swipe down
snakeHead.direction = {
x: 0,
y: 1
};
} else if (deltaY < 0 && snakeHead.direction.y !== 1) {
// Swipe up
snakeHead.direction = {
x: 0,
y: -1
};
}
}
}
game.down = function (x, y, obj) {
// Only handle input in bottom half of screen (below playable area)
if (y < PLAYABLE_START_Y + PLAYABLE_HEIGHT) return;
// Single-click bomb trigger
if (bombMode) {
triggerBomb();
return;
}
swipeStartX = x;
swipeStartY = y;
isSwipeStarted = true;
};
game.up = function (x, y, obj) {
// Only handle input in bottom half of screen (below playable area)
if (y < PLAYABLE_START_Y + PLAYABLE_HEIGHT) return;
if (isSwipeStarted) {
handleSwipe(swipeStartX, swipeStartY, x, y);
isSwipeStarted = false;
}
};
game.update = function () {
if (gameOver) return;
processBombMovement();
moveTimer++;
if (moveTimer >= gameSpeed / 16.67) {
moveSnake();
moveTimer = 0;
}
};
// Create playable area border
var playableBorder = new Container();
game.addChild(playableBorder);
// Create border lines
var borderTop = LK.getAsset('snakeHead', {
anchorX: 0,
anchorY: 0,
scaleX: GRID_WIDTH * GRID_SIZE / 40,
scaleY: 0.05,
tint: 0xFFFFFF
});
borderTop.x = 0;
borderTop.y = PLAYABLE_START_Y;
playableBorder.addChild(borderTop);
var borderBottom = LK.getAsset('snakeHead', {
anchorX: 0,
anchorY: 0,
scaleX: GRID_WIDTH * GRID_SIZE / 40,
scaleY: 0.05,
tint: 0xFFFFFF
});
borderBottom.x = 0;
borderBottom.y = PLAYABLE_START_Y + PLAYABLE_HEIGHT;
playableBorder.addChild(borderBottom);
var borderLeft = LK.getAsset('snakeHead', {
anchorX: 0,
anchorY: 0,
scaleX: 0.05,
scaleY: PLAYABLE_HEIGHT / 40,
tint: 0xFFFFFF
});
borderLeft.x = 0;
borderLeft.y = PLAYABLE_START_Y;
playableBorder.addChild(borderLeft);
var borderRight = LK.getAsset('snakeHead', {
anchorX: 0,
anchorY: 0,
scaleX: 0.05,
scaleY: PLAYABLE_HEIGHT / 40,
tint: 0xFFFFFF
});
borderRight.x = GRID_WIDTH * GRID_SIZE;
borderRight.y = PLAYABLE_START_Y;
playableBorder.addChild(borderRight);
// Initialize the game
initializeGame();
; ===================================================================
--- original.js
+++ change.js
@@ -267,9 +267,17 @@
if (pickups[i].color === targetColor && !pickups[i].isBomb) {
pickupsToRemove.push(i);
}
}
- if (pickupsToRemove.length > 0) {
+ // Find all snake segments with the target color
+ var segmentsToRemove = [];
+ for (var s = 0; s < snake.length; s++) {
+ if (snake[s].color === targetColor) {
+ segmentsToRemove.push(s);
+ }
+ }
+ var hasItemsToExplode = pickupsToRemove.length > 0 || segmentsToRemove.length > 0;
+ if (hasItemsToExplode) {
LK.getSound('explode').play();
// Create explosion effect on each pickup before destroying
for (var j = 0; j < pickupsToRemove.length; j++) {
var pickupIndex = pickupsToRemove[j];
@@ -283,18 +291,39 @@
duration: 300,
easing: tween.easeOut
});
}
- // Remove pickups after animation delay
+ // Create explosion effect on snake segments
+ for (var seg = 0; seg < segmentsToRemove.length; seg++) {
+ var segmentIndex = segmentsToRemove[seg];
+ var segment = snake[segmentIndex];
+ // Tween explosion effect
+ tween(segment.graphics, {
+ scaleX: 2,
+ scaleY: 2,
+ alpha: 0
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ }
+ // Remove pickups and segments after animation delay
LK.setTimeout(function () {
- // Remove in reverse order to maintain indices
+ // Remove pickups in reverse order to maintain indices
for (var k = pickupsToRemove.length - 1; k >= 0; k--) {
var index = pickupsToRemove[k];
pickups[index].destroy();
pickups.splice(index, 1);
}
+ // Remove snake segments in reverse order to maintain indices
+ for (var r = segmentsToRemove.length - 1; r >= 0; r--) {
+ var segIndex = segmentsToRemove[r];
+ snake[segIndex].destroy();
+ snake.splice(segIndex, 1);
+ }
// Award points
- var points = pickupsToRemove.length * 10;
+ var totalItems = pickupsToRemove.length + segmentsToRemove.length;
+ var points = totalItems * 10;
LK.setScore(LK.getScore() + points);
scoreTxt.setText('Score: ' + LK.getScore());
// Flash effect
LK.effects.flashScreen(0xffffff, 300);