User prompt
Grafikleri iyileştirsene ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Kontrolleri geliştir
User prompt
Biraz ses eklermisin yeme sesi ölüm sesi vb.
User prompt
Bu oyunu günümüze uyarlıyarak yap
User prompt
Biraz hızlı yılan ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Yilanın hızını biraz daha arttır ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Haritayı biraz küçült
User prompt
Yılan hızlı hareket etsin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Yilan daha akıcı hareket etsin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'ReferenceError: tween is not defined' in or related to this line: 'tween.to(snake[0], {' Line Number: 181 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (3 edits merged)
Please save this source code
User prompt
bu oyun mobilde de oyunansın
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'kahıwh is not defined' in or related to this line: 'kahıwh;' Line Number: 55
Code edit (2 edits merged)
Please save this source code
User prompt
yılan kasmadan hareket etsin ama biraz yavaş hareket etsin google oyunlardaki yılan gibi
User prompt
yılanın hızını biraz azalt
User prompt
yılan biraz daha kasmadan hareket etmesini sağlarmısın
Initial prompt
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Apple = Container.expand(function () { var self = Container.call(this); var appleGraphics = self.attachAsset('apple', { anchorX: 0.5, anchorY: 0.5 }); self.spawn = function () { var gridSize = 30; var padding = 80; // Increased padding for mobile visibility var maxX = Math.floor((2048 - padding * 2) / gridSize); var maxY = Math.floor((2732 - padding * 2) / gridSize); self.x = padding + Math.floor(Math.random() * maxX) * gridSize + gridSize / 2; self.y = padding + Math.floor(Math.random() * maxY) * gridSize + gridSize / 2; }; return self; }); var SnakeHead = Container.expand(function () { var self = Container.call(this); var headGraphics = self.attachAsset('snakeHead', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var SnakeSegment = Container.expand(function () { var self = Container.call(this); var segmentGraphics = self.attachAsset('snakeSegment', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1B5E20 }); /**** * Game Code ****/ var gridSize = 30; var snake = []; var snakeDirection = { x: 1, y: 0 }; var nextDirection = { x: 1, y: 0 }; var apple = null; var gameSpeed = 8; // Faster movement var moveCounter = 0; var isMoving = false; // Track if snake is currently moving var isGameRunning = true; var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize snake with 3 segments function initializeSnake() { snake = []; var startX = 1024; var startY = 1366; // Create head var head = game.addChild(new SnakeHead()); head.x = startX; head.y = startY; snake.push(head); // Create initial body segments for (var i = 1; i < 3; i++) { var segment = game.addChild(new SnakeSegment()); segment.x = startX - i * gridSize; segment.y = startY; snake.push(segment); } } // Create apple function createApple() { if (apple) { apple.destroy(); } apple = game.addChild(new Apple()); apple.spawn(); // Make sure apple doesn't spawn on snake var appleOnSnake = true; var attempts = 0; while (appleOnSnake && attempts < 50) { appleOnSnake = false; for (var i = 0; i < snake.length; i++) { if (Math.abs(apple.x - snake[i].x) < gridSize && Math.abs(apple.y - snake[i].y) < gridSize) { appleOnSnake = true; apple.spawn(); break; } } attempts++; } } // Move snake function moveSnake() { if (!isGameRunning || isMoving) { return; } isMoving = true; snakeDirection.x = nextDirection.x; snakeDirection.y = nextDirection.y; var head = snake[0]; var newX = head.x + snakeDirection.x * gridSize; var newY = head.y + snakeDirection.y * gridSize; // Check wall collisions if (newX < 20 || newX > 2028 || newY < 20 || newY > 2712) { isMoving = false; gameOver(); return; } // Check self collision for (var i = 1; i < snake.length; i++) { if (Math.abs(newX - snake[i].x) < gridSize && Math.abs(newY - snake[i].y) < gridSize) { isMoving = false; gameOver(); return; } } // Check apple collision var ateApple = false; if (apple && Math.abs(newX - apple.x) < gridSize && Math.abs(newY - apple.y) < gridSize) { ateApple = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText('Score: ' + LK.getScore()); LK.getSound('eat').play(); createApple(); } // Store old positions for smooth animation var oldPositions = []; for (var i = 0; i < snake.length; i++) { oldPositions[i] = { x: snake[i].x, y: snake[i].y }; } // Move all segments if (!ateApple) { // Remove tail if not growing var tail = snake.pop(); tail.destroy(); } // Add new head var newHead = game.addChild(new SnakeHead()); newHead.x = head.x; // Start at current position newHead.y = head.y; snake.unshift(newHead); // Convert old head to body segment if (snake.length > 1) { var oldHead = snake[1]; var newSegment = game.addChild(new SnakeSegment()); newSegment.x = oldHead.x; newSegment.y = oldHead.y; snake[1] = newSegment; oldHead.destroy(); } // Animate movement smoothly var animationDuration = 150; // Faster animation for quicker movement tween(snake[0], { x: newX, y: newY }, { duration: animationDuration, easing: tween.easeOut }); // Animate body segments to follow with slight delay for more natural movement for (var i = 1; i < snake.length; i++) { if (i < oldPositions.length) { tween(snake[i], { x: oldPositions[i - 1].x, y: oldPositions[i - 1].y }, { duration: animationDuration, easing: tween.easeOut }); } } // Reset movement flag after animation completes LK.setTimeout(function () { isMoving = false; }, animationDuration); } function gameOver() { isGameRunning = false; LK.showGameOver(); } // Touch controls var touchStartX = 0; var touchStartY = 0; var minSwipeDistance = 30; game.down = function (x, y, obj) { touchStartX = x; touchStartY = y; }; game.up = function (x, y, obj) { if (!isGameRunning) { return; } var deltaX = x - touchStartX; var deltaY = y - touchStartY; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); // Handle tap (short touch) for direction change if (distance < minSwipeDistance) { // Tap to turn - cycle through directions based on current direction if (snakeDirection.x === 1) { // Moving right, turn down nextDirection = { x: 0, y: 1 }; } else if (snakeDirection.x === -1) { // Moving left, turn up nextDirection = { x: 0, y: -1 }; } else if (snakeDirection.y === 1) { // Moving down, turn left nextDirection = { x: -1, y: 0 }; } else if (snakeDirection.y === -1) { // Moving up, turn right nextDirection = { x: 1, y: 0 }; } return; } // Determine swipe direction if (Math.abs(deltaX) > Math.abs(deltaY)) { // Horizontal swipe if (deltaX > 0 && snakeDirection.x === 0) { // Swipe right nextDirection = { x: 1, y: 0 }; } else if (deltaX < 0 && snakeDirection.x === 0) { // Swipe left nextDirection = { x: -1, y: 0 }; } } else { // Vertical swipe if (deltaY > 0 && snakeDirection.y === 0) { // Swipe down nextDirection = { x: 0, y: 1 }; } else if (deltaY < 0 && snakeDirection.y === 0) { // Swipe up nextDirection = { x: 0, y: -1 }; } } }; // Initialize game initializeSnake(); createApple(); // Game update loop game.update = function () { if (!isGameRunning) { return; } moveCounter++; if (moveCounter >= gameSpeed && !isMoving) { moveCounter = 0; moveSnake(); } };
===================================================================
--- original.js
+++ change.js
@@ -12,9 +12,9 @@
anchorX: 0.5,
anchorY: 0.5
});
self.spawn = function () {
- var gridSize = 40;
+ var gridSize = 30;
var padding = 80; // Increased padding for mobile visibility
var maxX = Math.floor((2048 - padding * 2) / gridSize);
var maxY = Math.floor((2732 - padding * 2) / gridSize);
self.x = padding + Math.floor(Math.random() * maxX) * gridSize + gridSize / 2;
@@ -48,9 +48,9 @@
/****
* Game Code
****/
-var gridSize = 40;
+var gridSize = 30;
var snake = [];
var snakeDirection = {
x: 1,
y: 0