User prompt
shopta slowdown ile gigachadin metinlerini birbiriyle değiştir
User prompt
invetoriyde 1 tek gigichadşi seçbiliyoz soptada aynı hemde en üst butonda ortada olmalı oda bozuk
User prompt
eğer süperimiz varssa ve ölürsek artık süper kullanamıyoruz
User prompt
öldüğümüz zamn süper gimesin ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
peki snake coin göstergesinin üstünde olacaktı süper gücün bitmesine klan süre ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
süper gücün ne kadar zamnı kaldığını gösteren sayac ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
özellikler çalışmıyor
User prompt
invetory de use çalışmıyor isetden söyleyelim güçleirn özelliklerini slowdn 5 dk yavaşlama fast gigachad gigacahadin daha hızlı gelmesi 2x points SCOİN i 2x çarpma ve özelliklerin hepsi 5dk lik ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
özellikleri kullanamıyoruz ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
shoptakileri satın alabilmemizi ekle ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
ayrıca shopta satın alamıyoruz
User prompt
oyunda invantoryde close olmasın ve coin yazan heryeri SCOİN olarak değiştir
User prompt
oyuna envanter ekle satın aldığımız şeyler için ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
ve shop da aldıklarımız bir yerde gözüksün ve kaç tane olduğunu basıınca o özellik açılsın
User prompt
scorey ve coins i Snake Coin (SCOİN) olarak değiştir
User prompt
oyunda gizli bir buton yap score nin üstünde bunun üstüne basınca sonsuz para gelsin
User prompt
shop butonuna 2. kez tıklanınca shop penceresi kapansın
User prompt
close butonu olmasın
User prompt
ama oraya uyarla ve büyüt
User prompt
shop penceresini direk sen küçültüp scorenin soluna koy
User prompt
close ye basınca oyun kaldığı yerden devam etsin
User prompt
close mağaza penceresini kapatacak
User prompt
close kapatmıyor
User prompt
mağaza yerindeki close çalışmıyor
User prompt
close buttonu çalışmıyor ve hep orada duran o yılanı kaldır
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var DirectionalButton = Container.expand(function (direction, assetId) { var self = Container.call(this); var graphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.direction = direction; // Add visual feedback when pressed self.down = function (x, y, obj) { if (!isGameRunning) { return; } // Prevent multiple rapid presses if (self.isPressed) { return; } self.isPressed = true; // Visual feedback - make button slightly smaller tween(self, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); // Change snake direction immediately changeDirection(self.direction); }; self.up = function (x, y, obj) { // Reset pressed state self.isPressed = false; // Return button to normal size tween(self, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100 }); }; return self; }); var EnemySnake = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('enemySnake', { anchorX: 0.5, anchorY: 0.5 }); graphics.tint = 0xff4444; // Red tint for enemy self.moveSpeed = 1.5; self.direction = Math.random() * Math.PI * 2; self.chaseTimer = 0; self.isBeingRepelled = false; self.repelTimer = 0; self.update = function () { // Check if being repelled by friendly snakes self.isBeingRepelled = false; for (var i = 0; i < friendlySnakes.length; i++) { var friendlySnake = friendlySnakes[i]; var dist = Math.sqrt(Math.pow(self.x - friendlySnake.x, 2) + Math.pow(self.y - friendlySnake.y, 2)); if (dist < 150) { // Repel range self.isBeingRepelled = true; // Move away from friendly snake var angle = Math.atan2(self.y - friendlySnake.y, self.x - friendlySnake.x); self.direction = angle; break; } } // If not being repelled, chase the player if (!self.isBeingRepelled && snake.length > 0) { self.chaseTimer++; if (self.chaseTimer >= 30) { // Update chase direction every 0.5 seconds var playerHead = snake[0]; var playerScreenPos = gridToScreen(playerHead.x, playerHead.y); var angle = Math.atan2(playerScreenPos.y - self.y, playerScreenPos.x - self.x); self.direction = angle; self.chaseTimer = 0; } } // Move in current direction self.x += Math.cos(self.direction) * self.moveSpeed; self.y += Math.sin(self.direction) * self.moveSpeed; // Bounce off walls if (self.x < boardOffsetX || self.x > boardOffsetX + BOARD_WIDTH * GRID_SIZE) { self.direction = Math.PI - self.direction; } if (self.y < boardOffsetY || self.y > boardOffsetY + BOARD_HEIGHT * GRID_SIZE) { self.direction = -self.direction; } // Keep within bounds self.x = Math.max(boardOffsetX, Math.min(boardOffsetX + BOARD_WIDTH * GRID_SIZE, self.x)); self.y = Math.max(boardOffsetY, Math.min(boardOffsetY + BOARD_HEIGHT * GRID_SIZE, self.y)); }; return self; }); var Food = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('food', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Simple pulsing animation var scale = 1 + Math.sin(LK.ticks * 0.1) * 0.1; self.scaleX = scale; self.scaleY = scale; }; return self; }); var FriendlySnake = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('friendlySnake', { anchorX: 0.5, anchorY: 0.5 }); self.moveSpeed = 2; self.direction = Math.random() * Math.PI * 2; self.dropTimer = 0; self.maxDrops = 3; self.dropsLeft = 3; self.hasKilledEnemy = false; self.update = function () { // Check for nearby enemy snakes to chase var isChasing = false; var closestEnemy = null; var closestDistance = Infinity; for (var i = 0; i < enemySnakes.length; i++) { var enemySnake = enemySnakes[i]; var dist = Math.sqrt(Math.pow(self.x - enemySnake.x, 2) + Math.pow(self.y - enemySnake.y, 2)); if (dist < 200) { // Detection range - notify GIGACHAD! if (!gigaChadNotified && enemySnakes.length > 0) { gigaChadNotified = true; if (!gigaChad) { gigaChad = game.addChild(new GigaChad()); } gigaChad.summon(); } if (dist < closestDistance) { closestDistance = dist; closestEnemy = enemySnake; isChasing = true; } } } // If chasing an enemy, move towards it if (isChasing && closestEnemy) { var angle = Math.atan2(closestEnemy.y - self.y, closestEnemy.x - self.x); self.direction = angle; self.moveSpeed = 3; // Increase speed when chasing } else { self.moveSpeed = 2; // Normal speed when not chasing } // Move in current direction self.x += Math.cos(self.direction) * self.moveSpeed; self.y += Math.sin(self.direction) * self.moveSpeed; // Check if we killed an enemy snake for (var i = enemySnakes.length - 1; i >= 0; i--) { var enemySnake = enemySnakes[i]; var dist = Math.sqrt(Math.pow(self.x - enemySnake.x, 2) + Math.pow(self.y - enemySnake.y, 2)); if (dist < 50) { // Kill range // Enemy snake is killed enemySnake.destroy(); enemySnakes.splice(i, 1); LK.setScore(LK.getScore() + 100); // Bonus for friendly snake killing enemy scoreTxt.setText('Score: ' + LK.getScore()); // Mark this friendly snake as having killed an enemy self.hasKilledEnemy = true; break; } } // Bounce off walls if (self.x < boardOffsetX || self.x > boardOffsetX + BOARD_WIDTH * GRID_SIZE) { self.direction = Math.PI - self.direction; } if (self.y < boardOffsetY || self.y > boardOffsetY + BOARD_HEIGHT * GRID_SIZE) { self.direction = -self.direction; } // Keep within bounds self.x = Math.max(boardOffsetX, Math.min(boardOffsetX + BOARD_WIDTH * GRID_SIZE, self.x)); self.y = Math.max(boardOffsetY, Math.min(boardOffsetY + BOARD_HEIGHT * GRID_SIZE, self.y)); // Drop food periodically self.dropTimer++; if (self.dropTimer >= 120 && self.dropsLeft > 0) { // Every 2 seconds self.dropFood(); self.dropTimer = 0; self.dropsLeft--; } // Remove after all drops are done - but only if hasn't killed an enemy if (self.dropsLeft <= 0 && !self.hasKilledEnemy) { tween(self, { alpha: 0 }, { duration: 1000, onFinish: function onFinish() { self.destroy(); var index = friendlySnakes.indexOf(self); if (index > -1) { friendlySnakes.splice(index, 1); } } }); } }; self.dropFood = function () { var dropType = Math.random() < 0.3 ? 'level2' : 'normal'; var newFood; if (dropType === 'level2') { newFood = game.addChild(new Level2Food()); } else { newFood = game.addChild(new Food()); } // Convert screen position to grid position and clamp to board bounds var gridX = Math.round((self.x - boardOffsetX) / GRID_SIZE); var gridY = Math.round((self.y - boardOffsetY) / GRID_SIZE); // Ensure food stays within board bounds gridX = Math.max(0, Math.min(BOARD_WIDTH - 1, gridX)); gridY = Math.max(0, Math.min(BOARD_HEIGHT - 1, gridY)); // Set food position based on clamped grid coordinates var screenPos = gridToScreen(gridX, gridY); newFood.x = screenPos.x; newFood.y = screenPos.y; newFood.gridX = gridX; newFood.gridY = gridY; // Add to food array foodItems.push(newFood); }; return self; }); var GigaChad = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('gigachad', { anchorX: 0.5, anchorY: 0.5 }); self.isActive = false; self.destroyTimer = 0; self.destroyDelay = shopEffects.speedGigachad.active ? 300 : 600; // 5 seconds if fast, 10 seconds normal self.summon = function () { if (self.isActive) return; // Already summoned self.isActive = true; self.destroyTimer = 0; // Position GIGACHAD at center of board self.x = boardOffsetX + BOARD_WIDTH * GRID_SIZE / 2; self.y = boardOffsetY + BOARD_HEIGHT * GRID_SIZE / 2; // Make GIGACHAD appear with dramatic effect self.alpha = 0; self.scaleX = 0.1; self.scaleY = 0.1; tween(self, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 500, easing: tween.bounceOut }); // Play summon sound LK.getSound('gigachadSummon').play(); // Flash screen to show GIGACHAD arrival LK.effects.flashScreen(0xFFD700, 1000); // Gold flash // Destroy all enemies immediately upon arrival self.destroyAllEnemies(); }; self.update = function () { if (!self.isActive) return; self.destroyTimer++; // Pulsing effect while active var pulse = 1 + Math.sin(LK.ticks * 0.2) * 0.1; self.scaleX = pulse; self.scaleY = pulse; // Auto-deactivate after completing task (enemies destroyed immediately on summon) if (self.destroyTimer >= self.destroyDelay) { // GIGACHAD disappears after completing his task tween(self, { alpha: 0, scaleX: 0.1, scaleY: 0.1 }, { duration: 1000, easing: tween.easeIn, onFinish: function onFinish() { self.isActive = false; self.destroyTimer = 0; } }); } }; self.destroyAllEnemies = function () { // Destroy all enemy snakes immediately for (var i = enemySnakes.length - 1; i >= 0; i--) { var enemySnake = enemySnakes[i]; // Flash enemy red before destroying tween(enemySnake, { tint: 0xFF0000, alpha: 0 }, { duration: 200, onFinish: function onFinish() { enemySnake.destroy(); } }); } // Clear enemy snakes array enemySnakes = []; // Play destroy sound LK.getSound('gigachadDestroy').play(); // Flash screen red for destruction LK.effects.flashScreen(0xFF0000, 1500); // Add massive score bonus LK.setScore(LK.getScore() + 500); scoreTxt.setText('Score: ' + LK.getScore()); }; return self; }); var Level2Food = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('level2Food', { anchorX: 0.5, anchorY: 0.5 }); self.foodType = 'level2'; self.update = function () { // Special pulsing animation for level 2 food var scale = 1 + Math.sin(LK.ticks * 0.15) * 0.3; self.scaleX = scale; self.scaleY = scale; // Color cycling effect var colorPhase = LK.ticks * 0.1 % (Math.PI * 2); var red = Math.floor(128 + 127 * Math.sin(colorPhase)); var green = Math.floor(128 + 127 * Math.sin(colorPhase + Math.PI * 2 / 3)); var blue = Math.floor(128 + 127 * Math.sin(colorPhase + Math.PI * 4 / 3)); graphics.tint = red << 16 | green << 8 | blue; }; return self; }); var Merchant = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('friendlySnake', { anchorX: 0.5, anchorY: 0.5 }); graphics.tint = 0xFFD700; // Gold tint for merchant // Shop items with costs self.shopItems = { slowdown: { cost: 150, name: "Slowdown (5min)", active: false, duration: 18000 }, // 5 minutes at 60fps speedGigachad: { cost: 200, name: "Fast GIGACHAD", active: false }, doublePoints: { cost: 200, name: "2x Points", active: false, duration: 18000 } // 5 minutes at 60fps }; self.down = function (x, y, obj) { self.openShop(); }; self.openShop = function () { // Simple shop interface using score display var playerCoins = storage.coins || 0; var shopText = "SHOP (Coins: " + playerCoins + ")\n"; shopText += "1. Slowdown 5min - " + self.shopItems.slowdown.cost + " coins\n"; shopText += "2. Fast GIGACHAD - " + self.shopItems.speedGigachad.cost + " coins\n"; shopText += "3. 2x Points - " + self.shopItems.doublePoints.cost + " coins"; // Flash screen to show shop is open LK.effects.flashScreen(0xFFD700, 500); }; return self; }); var ShopButton = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('shopButton', { anchorX: 0.5, anchorY: 0.5 }); graphics.tint = 0x4CAF50; // Green tint for shop button self.down = function (x, y, obj) { if (!isGameRunning) { return; } // Visual feedback - make button slightly smaller tween(self, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); // Pause game and open full-screen shop isShopOpen = true; self.openFullScreenShop(); }; self.up = function (x, y, obj) { // Return button to normal size tween(self, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100 }); }; self.openFullScreenShop = function () { // Create full-screen shop container shopContainer = new Container(); shopContainer.x = 0; shopContainer.y = 0; game.addChild(shopContainer); // Create semi-transparent background var shopBg = LK.getAsset('shopButton', { anchorX: 0, anchorY: 0, scaleX: 10.24, scaleY: 34.15 }); shopBg.tint = 0x000000; shopBg.alpha = 0.8; shopContainer.addChild(shopBg); // Get player coins var playerCoins = storage.coins || 0; // Create shop title var titleText = new Text2('SHOP', { size: 150, fill: 0xFFD700 }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 300; shopContainer.addChild(titleText); // Create coins display var coinsText = new Text2('Coins: ' + playerCoins, { size: 80, fill: 0xFFFFFF }); coinsText.anchor.set(0.5, 0.5); coinsText.x = 1024; coinsText.y = 450; shopContainer.addChild(coinsText); // Create shop items var yPos = 700; var itemSpacing = 200; // Slowdown item var slowdownButton = LK.getAsset('shopButton', { anchorX: 0.5, anchorY: 0.5 }); slowdownButton.x = 1024; slowdownButton.y = yPos; slowdownButton.tint = playerCoins >= 150 ? 0x4CAF50 : 0x666666; shopContainer.addChild(slowdownButton); var slowdownText = new Text2('Slowdown 5min - 150 coins', { size: 50, fill: 0xFFFFFF }); slowdownText.anchor.set(0.5, 0.5); slowdownText.x = 1024; slowdownText.y = yPos; shopContainer.addChild(slowdownText); // Speed GIGACHAD item yPos += itemSpacing; var speedButton = LK.getAsset('shopButton', { anchorX: 0.5, anchorY: 0.5 }); speedButton.x = 1024; speedButton.y = yPos; speedButton.tint = playerCoins >= 200 ? 0x4CAF50 : 0x666666; shopContainer.addChild(speedButton); var speedText = new Text2('Fast GIGACHAD - 200 coins', { size: 50, fill: 0xFFFFFF }); speedText.anchor.set(0.5, 0.5); speedText.x = 1024; speedText.y = yPos; shopContainer.addChild(speedText); // Double Points item yPos += itemSpacing; var doubleButton = LK.getAsset('shopButton', { anchorX: 0.5, anchorY: 0.5 }); doubleButton.x = 1024; doubleButton.y = yPos; doubleButton.tint = playerCoins >= 200 ? 0x4CAF50 : 0x666666; shopContainer.addChild(doubleButton); var doubleText = new Text2('2x Points - 200 coins', { size: 50, fill: 0xFFFFFF }); doubleText.anchor.set(0.5, 0.5); doubleText.x = 1024; doubleText.y = yPos; shopContainer.addChild(doubleText); // Close button var closeButton = LK.getAsset('shopButton', { anchorX: 0.5, anchorY: 0.5 }); closeButton.x = 1024; closeButton.y = 2400; closeButton.tint = 0xFF4444; shopContainer.addChild(closeButton); var closeText = new Text2('CLOSE', { size: 60, fill: 0xFFFFFF }); closeText.anchor.set(0.5, 0.5); closeText.x = 1024; closeText.y = 2400; shopContainer.addChild(closeText); // Add shop interaction handlers self.handleShopClick = function (x, y) { // Check which button was clicked var localPos = shopContainer.toLocal({ x: x, y: y }); // Close button clicked if (Math.abs(localPos.x - 1024) < 100 && Math.abs(localPos.y - 2400) < 100) { self.closeShop(); return; } // Check item buttons var itemY = 700; // Slowdown button if (Math.abs(localPos.x - 1024) < 100 && Math.abs(localPos.y - itemY) < 40) { if (playerCoins >= 150) { storage.coins = playerCoins - 150; shopEffects.slowdown.active = true; shopEffects.slowdown.timer = 0; self.closeShop(); } return; } // Speed GIGACHAD button itemY += 200; if (Math.abs(localPos.x - 1024) < 100 && Math.abs(localPos.y - itemY) < 40) { if (playerCoins >= 200) { storage.coins = playerCoins - 200; shopEffects.speedGigachad.active = true; self.closeShop(); } return; } // Double points button itemY += 200; if (Math.abs(localPos.x - 1024) < 100 && Math.abs(localPos.y - itemY) < 40) { if (playerCoins >= 200) { storage.coins = playerCoins - 200; shopEffects.doublePoints.active = true; shopEffects.doublePoints.timer = 0; self.closeShop(); } return; } }; self.closeShop = function () { isShopOpen = false; if (shopContainer) { shopContainer.destroy(); shopContainer = null; } }; }; return self; }); var Snake = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('snakeHead', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ // Game configuration var GRID_SIZE = 40; var BOARD_WIDTH = 35; var BOARD_HEIGHT = 50; var MOVE_DELAY = 8; // Frames between moves // Game state variables var snake = []; var snakeDirection = { x: 1, y: 0 }; var nextDirection = { x: 1, y: 0 }; var food = null; var moveCounter = 0; var isGameRunning = true; var friendlySnakes = []; var friendlySnakeTimer = 0; var enemySnakes = []; var enemySnakeTimer = 0; var foodItems = []; var gigaChad = null; var gigaChadNotified = false; var shopButton = null; var shopEffects = { slowdown: { active: false, timer: 0 }, speedGigachad: { active: false }, doublePoints: { active: false, timer: 0 } }; var isShopOpen = false; var shopContainer = null; // Calculate board position to center it horizontally and leave space for controls at bottom var boardOffsetX = (2048 - BOARD_WIDTH * GRID_SIZE) / 2; var boardOffsetY = 100; // Start closer to top, leaving space for controls at bottom // Create score display var scoreTxt = new Text2('Score: 0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0.5); // Position score centered horizontally and at control buttons level scoreTxt.x = 2048 / 2; // Center horizontally scoreTxt.y = 2732 - 300; // Same vertical level as control buttons game.addChild(scoreTxt); // Initialize snake with only head function initializeSnake() { snake = []; // Create head using new Snake class var head = game.addChild(new Snake()); head.x = boardOffsetX + 12 * GRID_SIZE; head.y = boardOffsetY + 25 * GRID_SIZE; snake.push({ x: 12, y: 25, obj: head }); } // Convert grid coordinates to screen coordinates function gridToScreen(gridX, gridY) { return { x: boardOffsetX + gridX * GRID_SIZE, y: boardOffsetY + gridY * GRID_SIZE }; } // Generate random food position function spawnFood() { var validPositions = []; // Find all valid positions (not occupied by snake) for (var x = 0; x < BOARD_WIDTH; x++) { for (var y = 0; y < BOARD_HEIGHT; y++) { var occupied = false; for (var i = 0; i < snake.length; i++) { if (snake[i].x === x && snake[i].y === y) { occupied = true; break; } } if (!occupied) { validPositions.push({ x: x, y: y }); } } } if (validPositions.length > 0) { var randomIndex = Math.floor(Math.random() * validPositions.length); var pos = validPositions[randomIndex]; if (food) { food.destroy(); } food = game.addChild(new Food()); var screenPos = gridToScreen(pos.x, pos.y); food.x = screenPos.x; food.y = screenPos.y; food.gridX = pos.x; food.gridY = pos.y; foodItems.push(food); } } // Check if position is valid (within bounds and not colliding with snake) function isValidPosition(x, y) { // Check bounds if (x < 0 || x >= BOARD_WIDTH || y < 0 || y >= BOARD_HEIGHT) { return false; } // No body collision check needed for head-only snake return true; } // Move snake function moveSnake() { if (!isGameRunning) { return; } // Direction is already updated immediately in changeDirection function // Calculate new head position var head = snake[0]; var newHeadX = head.x + snakeDirection.x; var newHeadY = head.y + snakeDirection.y; // Check if new position is valid if (!isValidPosition(newHeadX, newHeadY)) { // Game over isGameRunning = false; LK.getSound('gameOver').play(); LK.showGameOver(); return; } // Check if any food is eaten var ateFood = false; for (var i = foodItems.length - 1; i >= 0; i--) { var currentFood = foodItems[i]; if (currentFood && newHeadX === currentFood.gridX && newHeadY === currentFood.gridY) { ateFood = true; var points = currentFood.foodType === 'level2' ? 20 : 10; // Apply double points effect if active if (shopEffects.doublePoints.active) { points *= 2; } // Convert points to coins for shop var coins = storage.coins || 0; storage.coins = coins + Math.floor(points / 10); // 1 coin per 10 points LK.setScore(LK.getScore() + points); scoreTxt.setText('Score: ' + LK.getScore()); LK.getSound('eat').play(); // Flash food before removing tween(currentFood, { alpha: 0 }, { duration: 200, onFinish: function onFinish() { currentFood.destroy(); } }); foodItems.splice(i, 1); if (currentFood === food) { food = null; spawnFood(); } break; } } // Simply move the existing head to new position (no growth) var headObj = snake[0].obj; var screenPos = gridToScreen(newHeadX, newHeadY); headObj.x = screenPos.x; headObj.y = screenPos.y; snake[0].x = newHeadX; snake[0].y = newHeadY; } // Handle direction changes function changeDirection(newDir) { // Prevent immediate reversal if (newDir.x === -snakeDirection.x && newDir.y === -snakeDirection.y) { return; } // Prevent diagonal movement - only allow pure horizontal or vertical movement if (newDir.x !== 0 && newDir.y !== 0) { return; } // Apply direction change immediately for responsive controls snakeDirection.x = newDir.x; snakeDirection.y = newDir.y; nextDirection.x = newDir.x; nextDirection.y = newDir.y; } // Remove touch controls - snake can only be controlled by buttons // Create visible walls around the game board function createWalls() { // Top and bottom walls for (var x = -1; x <= BOARD_WIDTH; x++) { // Top wall var topWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5 })); topWall.x = boardOffsetX + x * GRID_SIZE; topWall.y = boardOffsetY - GRID_SIZE; // Bottom wall var bottomWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5 })); bottomWall.x = boardOffsetX + x * GRID_SIZE; bottomWall.y = boardOffsetY + BOARD_HEIGHT * GRID_SIZE; } // Left and right walls for (var y = -1; y <= BOARD_HEIGHT; y++) { // Left wall var leftWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5 })); leftWall.x = boardOffsetX - GRID_SIZE; leftWall.y = boardOffsetY + y * GRID_SIZE; // Right wall var rightWall = game.addChild(LK.getAsset('wall', { anchorX: 0.5, anchorY: 0.5 })); rightWall.x = boardOffsetX + BOARD_WIDTH * GRID_SIZE; rightWall.y = boardOffsetY + y * GRID_SIZE; } } // Create directional control buttons var upButton = game.addChild(new DirectionalButton({ x: 0, y: -1 }, 'upButton')); var downButton = game.addChild(new DirectionalButton({ x: 0, y: 1 }, 'downButton')); var leftButton = game.addChild(new DirectionalButton({ x: -1, y: 0 }, 'leftButton')); var rightButton = game.addChild(new DirectionalButton({ x: 1, y: 0 }, 'rightButton')); // Position buttons in bottom right corner var buttonSpacing = 140; var buttonBaseX = 2048 - 200; var buttonBaseY = 2732 - 300; // Up button upButton.x = buttonBaseX; upButton.y = buttonBaseY - buttonSpacing; // Down button downButton.x = buttonBaseX; downButton.y = buttonBaseY + buttonSpacing; // Left button leftButton.x = buttonBaseX - buttonSpacing; leftButton.y = buttonBaseY; // Right button rightButton.x = buttonBaseX + buttonSpacing; rightButton.y = buttonBaseY; // Add text labels to buttons var upText = new Text2('↑', { size: 60, fill: 0xFFFFFF }); upText.anchor.set(0.5, 0.5); upText.x = upButton.x; upText.y = upButton.y; game.addChild(upText); var downText = new Text2('↓', { size: 60, fill: 0xFFFFFF }); downText.anchor.set(0.5, 0.5); downText.x = downButton.x; downText.y = downButton.y; game.addChild(downText); var leftText = new Text2('←', { size: 60, fill: 0xFFFFFF }); leftText.anchor.set(0.5, 0.5); leftText.x = leftButton.x; leftText.y = leftButton.y; game.addChild(leftText); var rightText = new Text2('→', { size: 60, fill: 0xFFFFFF }); rightText.anchor.set(0.5, 0.5); rightText.x = rightButton.x; rightText.y = rightButton.y; game.addChild(rightText); // Initialize game createWalls(); initializeSnake(); spawnFood(); // Merchant functionality is handled through the shop button // Create shop button at bottom center shopButton = game.addChild(new ShopButton()); shopButton.x = 2048 / 2; // Center horizontally shopButton.y = 2732 - 150; // Bottom of screen with some margin // Add shop button text var shopText = new Text2('SHOP', { size: 40, fill: 0xFFFFFF }); shopText.anchor.set(0.5, 0.5); shopText.x = shopButton.x; shopText.y = shopButton.y; game.addChild(shopText); // Add shop interaction handler game.down = function (x, y, obj) { if (isShopOpen && shopButton) { shopButton.handleShopClick(x, y); } }; // Main game loop game.update = function () { if (!isGameRunning || isShopOpen) { return; } moveCounter++; var currentMoveDelay = MOVE_DELAY; if (shopEffects.slowdown.active) { currentMoveDelay = MOVE_DELAY * 2; // Double the delay = half the speed } if (moveCounter >= currentMoveDelay) { moveCounter = 0; moveSnake(); } // Spawn friendly snakes every 10 seconds (600 frames at 60fps) friendlySnakeTimer++; if (friendlySnakeTimer >= 600) { friendlySnakeTimer = 0; var friendlySnake = game.addChild(new FriendlySnake()); // Spawn at random edge position within board bounds only var edge = Math.floor(Math.random() * 4); switch (edge) { case 0: // Top - ensure spawn within board width friendlySnake.x = boardOffsetX + (Math.random() * (BOARD_WIDTH - 2) + 1) * GRID_SIZE; friendlySnake.y = boardOffsetY + GRID_SIZE; break; case 1: // Right - ensure spawn within board height friendlySnake.x = boardOffsetX + (BOARD_WIDTH - 1) * GRID_SIZE; friendlySnake.y = boardOffsetY + (Math.random() * (BOARD_HEIGHT - 2) + 1) * GRID_SIZE; break; case 2: // Bottom - ensure spawn within board width friendlySnake.x = boardOffsetX + (Math.random() * (BOARD_WIDTH - 2) + 1) * GRID_SIZE; friendlySnake.y = boardOffsetY + (BOARD_HEIGHT - 1) * GRID_SIZE; break; case 3: // Left - ensure spawn within board height friendlySnake.x = boardOffsetX + GRID_SIZE; friendlySnake.y = boardOffsetY + (Math.random() * (BOARD_HEIGHT - 2) + 1) * GRID_SIZE; break; } friendlySnakes.push(friendlySnake); } // Spawn enemy snakes every 8 seconds (480 frames at 60fps) enemySnakeTimer++; if (enemySnakeTimer >= 480) { enemySnakeTimer = 0; var enemySnake = game.addChild(new EnemySnake()); // Spawn at random edge position within board bounds only var edge = Math.floor(Math.random() * 4); switch (edge) { case 0: // Top - ensure spawn within board width enemySnake.x = boardOffsetX + (Math.random() * (BOARD_WIDTH - 2) + 1) * GRID_SIZE; enemySnake.y = boardOffsetY + GRID_SIZE; break; case 1: // Right - ensure spawn within board height enemySnake.x = boardOffsetX + (BOARD_WIDTH - 1) * GRID_SIZE; enemySnake.y = boardOffsetY + (Math.random() * (BOARD_HEIGHT - 2) + 1) * GRID_SIZE; break; case 2: // Bottom - ensure spawn within board width enemySnake.x = boardOffsetX + (Math.random() * (BOARD_WIDTH - 2) + 1) * GRID_SIZE; enemySnake.y = boardOffsetY + (BOARD_HEIGHT - 1) * GRID_SIZE; break; case 3: // Left - ensure spawn within board height enemySnake.x = boardOffsetX + GRID_SIZE; enemySnake.y = boardOffsetY + (Math.random() * (BOARD_HEIGHT - 2) + 1) * GRID_SIZE; break; } enemySnakes.push(enemySnake); } // Check collision between player and enemy snakes if (snake.length > 0) { var playerHead = snake[0]; var playerScreenPos = gridToScreen(playerHead.x, playerHead.y); for (var i = enemySnakes.length - 1; i >= 0; i--) { var enemySnake = enemySnakes[i]; var dist = Math.sqrt(Math.pow(playerScreenPos.x - enemySnake.x, 2) + Math.pow(playerScreenPos.y - enemySnake.y, 2)); if (dist < 60) { // Collision detected // Check if friendly snake is protecting var isProtected = false; for (var j = 0; j < friendlySnakes.length; j++) { var friendlySnake = friendlySnakes[j]; var friendlyDist = Math.sqrt(Math.pow(playerScreenPos.x - friendlySnake.x, 2) + Math.pow(playerScreenPos.y - friendlySnake.y, 2)); if (friendlyDist < 100) { // Protection range isProtected = true; // Remove the enemy snake as it's defeated by friendly snake enemySnake.destroy(); enemySnakes.splice(i, 1); LK.setScore(LK.getScore() + 50); // Bonus for protection scoreTxt.setText('Score: ' + LK.getScore()); break; } } if (!isProtected) { // Game over - player eaten by enemy snake isGameRunning = false; LK.getSound('gameOver').play(); LK.showGameOver(); return; } } } } // Reset GIGACHAD notification if no enemies remain if (enemySnakes.length === 0) { gigaChadNotified = false; } // Update shop effects if (shopEffects.slowdown.active) { shopEffects.slowdown.timer++; if (shopEffects.slowdown.timer >= 18000) { // 5 minutes shopEffects.slowdown.active = false; shopEffects.slowdown.timer = 0; } } if (shopEffects.doublePoints.active) { shopEffects.doublePoints.timer++; if (shopEffects.doublePoints.timer >= 18000) { // 5 minutes shopEffects.doublePoints.active = false; shopEffects.doublePoints.timer = 0; } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var DirectionalButton = Container.expand(function (direction, assetId) {
var self = Container.call(this);
var graphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction;
// Add visual feedback when pressed
self.down = function (x, y, obj) {
if (!isGameRunning) {
return;
}
// Prevent multiple rapid presses
if (self.isPressed) {
return;
}
self.isPressed = true;
// Visual feedback - make button slightly smaller
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
// Change snake direction immediately
changeDirection(self.direction);
};
self.up = function (x, y, obj) {
// Reset pressed state
self.isPressed = false;
// Return button to normal size
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
};
return self;
});
var EnemySnake = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('enemySnake', {
anchorX: 0.5,
anchorY: 0.5
});
graphics.tint = 0xff4444; // Red tint for enemy
self.moveSpeed = 1.5;
self.direction = Math.random() * Math.PI * 2;
self.chaseTimer = 0;
self.isBeingRepelled = false;
self.repelTimer = 0;
self.update = function () {
// Check if being repelled by friendly snakes
self.isBeingRepelled = false;
for (var i = 0; i < friendlySnakes.length; i++) {
var friendlySnake = friendlySnakes[i];
var dist = Math.sqrt(Math.pow(self.x - friendlySnake.x, 2) + Math.pow(self.y - friendlySnake.y, 2));
if (dist < 150) {
// Repel range
self.isBeingRepelled = true;
// Move away from friendly snake
var angle = Math.atan2(self.y - friendlySnake.y, self.x - friendlySnake.x);
self.direction = angle;
break;
}
}
// If not being repelled, chase the player
if (!self.isBeingRepelled && snake.length > 0) {
self.chaseTimer++;
if (self.chaseTimer >= 30) {
// Update chase direction every 0.5 seconds
var playerHead = snake[0];
var playerScreenPos = gridToScreen(playerHead.x, playerHead.y);
var angle = Math.atan2(playerScreenPos.y - self.y, playerScreenPos.x - self.x);
self.direction = angle;
self.chaseTimer = 0;
}
}
// Move in current direction
self.x += Math.cos(self.direction) * self.moveSpeed;
self.y += Math.sin(self.direction) * self.moveSpeed;
// Bounce off walls
if (self.x < boardOffsetX || self.x > boardOffsetX + BOARD_WIDTH * GRID_SIZE) {
self.direction = Math.PI - self.direction;
}
if (self.y < boardOffsetY || self.y > boardOffsetY + BOARD_HEIGHT * GRID_SIZE) {
self.direction = -self.direction;
}
// Keep within bounds
self.x = Math.max(boardOffsetX, Math.min(boardOffsetX + BOARD_WIDTH * GRID_SIZE, self.x));
self.y = Math.max(boardOffsetY, Math.min(boardOffsetY + BOARD_HEIGHT * GRID_SIZE, self.y));
};
return self;
});
var Food = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('food', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Simple pulsing animation
var scale = 1 + Math.sin(LK.ticks * 0.1) * 0.1;
self.scaleX = scale;
self.scaleY = scale;
};
return self;
});
var FriendlySnake = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('friendlySnake', {
anchorX: 0.5,
anchorY: 0.5
});
self.moveSpeed = 2;
self.direction = Math.random() * Math.PI * 2;
self.dropTimer = 0;
self.maxDrops = 3;
self.dropsLeft = 3;
self.hasKilledEnemy = false;
self.update = function () {
// Check for nearby enemy snakes to chase
var isChasing = false;
var closestEnemy = null;
var closestDistance = Infinity;
for (var i = 0; i < enemySnakes.length; i++) {
var enemySnake = enemySnakes[i];
var dist = Math.sqrt(Math.pow(self.x - enemySnake.x, 2) + Math.pow(self.y - enemySnake.y, 2));
if (dist < 200) {
// Detection range - notify GIGACHAD!
if (!gigaChadNotified && enemySnakes.length > 0) {
gigaChadNotified = true;
if (!gigaChad) {
gigaChad = game.addChild(new GigaChad());
}
gigaChad.summon();
}
if (dist < closestDistance) {
closestDistance = dist;
closestEnemy = enemySnake;
isChasing = true;
}
}
}
// If chasing an enemy, move towards it
if (isChasing && closestEnemy) {
var angle = Math.atan2(closestEnemy.y - self.y, closestEnemy.x - self.x);
self.direction = angle;
self.moveSpeed = 3; // Increase speed when chasing
} else {
self.moveSpeed = 2; // Normal speed when not chasing
}
// Move in current direction
self.x += Math.cos(self.direction) * self.moveSpeed;
self.y += Math.sin(self.direction) * self.moveSpeed;
// Check if we killed an enemy snake
for (var i = enemySnakes.length - 1; i >= 0; i--) {
var enemySnake = enemySnakes[i];
var dist = Math.sqrt(Math.pow(self.x - enemySnake.x, 2) + Math.pow(self.y - enemySnake.y, 2));
if (dist < 50) {
// Kill range
// Enemy snake is killed
enemySnake.destroy();
enemySnakes.splice(i, 1);
LK.setScore(LK.getScore() + 100); // Bonus for friendly snake killing enemy
scoreTxt.setText('Score: ' + LK.getScore());
// Mark this friendly snake as having killed an enemy
self.hasKilledEnemy = true;
break;
}
}
// Bounce off walls
if (self.x < boardOffsetX || self.x > boardOffsetX + BOARD_WIDTH * GRID_SIZE) {
self.direction = Math.PI - self.direction;
}
if (self.y < boardOffsetY || self.y > boardOffsetY + BOARD_HEIGHT * GRID_SIZE) {
self.direction = -self.direction;
}
// Keep within bounds
self.x = Math.max(boardOffsetX, Math.min(boardOffsetX + BOARD_WIDTH * GRID_SIZE, self.x));
self.y = Math.max(boardOffsetY, Math.min(boardOffsetY + BOARD_HEIGHT * GRID_SIZE, self.y));
// Drop food periodically
self.dropTimer++;
if (self.dropTimer >= 120 && self.dropsLeft > 0) {
// Every 2 seconds
self.dropFood();
self.dropTimer = 0;
self.dropsLeft--;
}
// Remove after all drops are done - but only if hasn't killed an enemy
if (self.dropsLeft <= 0 && !self.hasKilledEnemy) {
tween(self, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
self.destroy();
var index = friendlySnakes.indexOf(self);
if (index > -1) {
friendlySnakes.splice(index, 1);
}
}
});
}
};
self.dropFood = function () {
var dropType = Math.random() < 0.3 ? 'level2' : 'normal';
var newFood;
if (dropType === 'level2') {
newFood = game.addChild(new Level2Food());
} else {
newFood = game.addChild(new Food());
}
// Convert screen position to grid position and clamp to board bounds
var gridX = Math.round((self.x - boardOffsetX) / GRID_SIZE);
var gridY = Math.round((self.y - boardOffsetY) / GRID_SIZE);
// Ensure food stays within board bounds
gridX = Math.max(0, Math.min(BOARD_WIDTH - 1, gridX));
gridY = Math.max(0, Math.min(BOARD_HEIGHT - 1, gridY));
// Set food position based on clamped grid coordinates
var screenPos = gridToScreen(gridX, gridY);
newFood.x = screenPos.x;
newFood.y = screenPos.y;
newFood.gridX = gridX;
newFood.gridY = gridY;
// Add to food array
foodItems.push(newFood);
};
return self;
});
var GigaChad = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('gigachad', {
anchorX: 0.5,
anchorY: 0.5
});
self.isActive = false;
self.destroyTimer = 0;
self.destroyDelay = shopEffects.speedGigachad.active ? 300 : 600; // 5 seconds if fast, 10 seconds normal
self.summon = function () {
if (self.isActive) return; // Already summoned
self.isActive = true;
self.destroyTimer = 0;
// Position GIGACHAD at center of board
self.x = boardOffsetX + BOARD_WIDTH * GRID_SIZE / 2;
self.y = boardOffsetY + BOARD_HEIGHT * GRID_SIZE / 2;
// Make GIGACHAD appear with dramatic effect
self.alpha = 0;
self.scaleX = 0.1;
self.scaleY = 0.1;
tween(self, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.bounceOut
});
// Play summon sound
LK.getSound('gigachadSummon').play();
// Flash screen to show GIGACHAD arrival
LK.effects.flashScreen(0xFFD700, 1000); // Gold flash
// Destroy all enemies immediately upon arrival
self.destroyAllEnemies();
};
self.update = function () {
if (!self.isActive) return;
self.destroyTimer++;
// Pulsing effect while active
var pulse = 1 + Math.sin(LK.ticks * 0.2) * 0.1;
self.scaleX = pulse;
self.scaleY = pulse;
// Auto-deactivate after completing task (enemies destroyed immediately on summon)
if (self.destroyTimer >= self.destroyDelay) {
// GIGACHAD disappears after completing his task
tween(self, {
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 1000,
easing: tween.easeIn,
onFinish: function onFinish() {
self.isActive = false;
self.destroyTimer = 0;
}
});
}
};
self.destroyAllEnemies = function () {
// Destroy all enemy snakes immediately
for (var i = enemySnakes.length - 1; i >= 0; i--) {
var enemySnake = enemySnakes[i];
// Flash enemy red before destroying
tween(enemySnake, {
tint: 0xFF0000,
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
enemySnake.destroy();
}
});
}
// Clear enemy snakes array
enemySnakes = [];
// Play destroy sound
LK.getSound('gigachadDestroy').play();
// Flash screen red for destruction
LK.effects.flashScreen(0xFF0000, 1500);
// Add massive score bonus
LK.setScore(LK.getScore() + 500);
scoreTxt.setText('Score: ' + LK.getScore());
};
return self;
});
var Level2Food = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('level2Food', {
anchorX: 0.5,
anchorY: 0.5
});
self.foodType = 'level2';
self.update = function () {
// Special pulsing animation for level 2 food
var scale = 1 + Math.sin(LK.ticks * 0.15) * 0.3;
self.scaleX = scale;
self.scaleY = scale;
// Color cycling effect
var colorPhase = LK.ticks * 0.1 % (Math.PI * 2);
var red = Math.floor(128 + 127 * Math.sin(colorPhase));
var green = Math.floor(128 + 127 * Math.sin(colorPhase + Math.PI * 2 / 3));
var blue = Math.floor(128 + 127 * Math.sin(colorPhase + Math.PI * 4 / 3));
graphics.tint = red << 16 | green << 8 | blue;
};
return self;
});
var Merchant = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('friendlySnake', {
anchorX: 0.5,
anchorY: 0.5
});
graphics.tint = 0xFFD700; // Gold tint for merchant
// Shop items with costs
self.shopItems = {
slowdown: {
cost: 150,
name: "Slowdown (5min)",
active: false,
duration: 18000
},
// 5 minutes at 60fps
speedGigachad: {
cost: 200,
name: "Fast GIGACHAD",
active: false
},
doublePoints: {
cost: 200,
name: "2x Points",
active: false,
duration: 18000
} // 5 minutes at 60fps
};
self.down = function (x, y, obj) {
self.openShop();
};
self.openShop = function () {
// Simple shop interface using score display
var playerCoins = storage.coins || 0;
var shopText = "SHOP (Coins: " + playerCoins + ")\n";
shopText += "1. Slowdown 5min - " + self.shopItems.slowdown.cost + " coins\n";
shopText += "2. Fast GIGACHAD - " + self.shopItems.speedGigachad.cost + " coins\n";
shopText += "3. 2x Points - " + self.shopItems.doublePoints.cost + " coins";
// Flash screen to show shop is open
LK.effects.flashScreen(0xFFD700, 500);
};
return self;
});
var ShopButton = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
graphics.tint = 0x4CAF50; // Green tint for shop button
self.down = function (x, y, obj) {
if (!isGameRunning) {
return;
}
// Visual feedback - make button slightly smaller
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
// Pause game and open full-screen shop
isShopOpen = true;
self.openFullScreenShop();
};
self.up = function (x, y, obj) {
// Return button to normal size
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
};
self.openFullScreenShop = function () {
// Create full-screen shop container
shopContainer = new Container();
shopContainer.x = 0;
shopContainer.y = 0;
game.addChild(shopContainer);
// Create semi-transparent background
var shopBg = LK.getAsset('shopButton', {
anchorX: 0,
anchorY: 0,
scaleX: 10.24,
scaleY: 34.15
});
shopBg.tint = 0x000000;
shopBg.alpha = 0.8;
shopContainer.addChild(shopBg);
// Get player coins
var playerCoins = storage.coins || 0;
// Create shop title
var titleText = new Text2('SHOP', {
size: 150,
fill: 0xFFD700
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
shopContainer.addChild(titleText);
// Create coins display
var coinsText = new Text2('Coins: ' + playerCoins, {
size: 80,
fill: 0xFFFFFF
});
coinsText.anchor.set(0.5, 0.5);
coinsText.x = 1024;
coinsText.y = 450;
shopContainer.addChild(coinsText);
// Create shop items
var yPos = 700;
var itemSpacing = 200;
// Slowdown item
var slowdownButton = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
slowdownButton.x = 1024;
slowdownButton.y = yPos;
slowdownButton.tint = playerCoins >= 150 ? 0x4CAF50 : 0x666666;
shopContainer.addChild(slowdownButton);
var slowdownText = new Text2('Slowdown 5min - 150 coins', {
size: 50,
fill: 0xFFFFFF
});
slowdownText.anchor.set(0.5, 0.5);
slowdownText.x = 1024;
slowdownText.y = yPos;
shopContainer.addChild(slowdownText);
// Speed GIGACHAD item
yPos += itemSpacing;
var speedButton = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
speedButton.x = 1024;
speedButton.y = yPos;
speedButton.tint = playerCoins >= 200 ? 0x4CAF50 : 0x666666;
shopContainer.addChild(speedButton);
var speedText = new Text2('Fast GIGACHAD - 200 coins', {
size: 50,
fill: 0xFFFFFF
});
speedText.anchor.set(0.5, 0.5);
speedText.x = 1024;
speedText.y = yPos;
shopContainer.addChild(speedText);
// Double Points item
yPos += itemSpacing;
var doubleButton = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
doubleButton.x = 1024;
doubleButton.y = yPos;
doubleButton.tint = playerCoins >= 200 ? 0x4CAF50 : 0x666666;
shopContainer.addChild(doubleButton);
var doubleText = new Text2('2x Points - 200 coins', {
size: 50,
fill: 0xFFFFFF
});
doubleText.anchor.set(0.5, 0.5);
doubleText.x = 1024;
doubleText.y = yPos;
shopContainer.addChild(doubleText);
// Close button
var closeButton = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
closeButton.x = 1024;
closeButton.y = 2400;
closeButton.tint = 0xFF4444;
shopContainer.addChild(closeButton);
var closeText = new Text2('CLOSE', {
size: 60,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeText.x = 1024;
closeText.y = 2400;
shopContainer.addChild(closeText);
// Add shop interaction handlers
self.handleShopClick = function (x, y) {
// Check which button was clicked
var localPos = shopContainer.toLocal({
x: x,
y: y
});
// Close button clicked
if (Math.abs(localPos.x - 1024) < 100 && Math.abs(localPos.y - 2400) < 100) {
self.closeShop();
return;
}
// Check item buttons
var itemY = 700;
// Slowdown button
if (Math.abs(localPos.x - 1024) < 100 && Math.abs(localPos.y - itemY) < 40) {
if (playerCoins >= 150) {
storage.coins = playerCoins - 150;
shopEffects.slowdown.active = true;
shopEffects.slowdown.timer = 0;
self.closeShop();
}
return;
}
// Speed GIGACHAD button
itemY += 200;
if (Math.abs(localPos.x - 1024) < 100 && Math.abs(localPos.y - itemY) < 40) {
if (playerCoins >= 200) {
storage.coins = playerCoins - 200;
shopEffects.speedGigachad.active = true;
self.closeShop();
}
return;
}
// Double points button
itemY += 200;
if (Math.abs(localPos.x - 1024) < 100 && Math.abs(localPos.y - itemY) < 40) {
if (playerCoins >= 200) {
storage.coins = playerCoins - 200;
shopEffects.doublePoints.active = true;
shopEffects.doublePoints.timer = 0;
self.closeShop();
}
return;
}
};
self.closeShop = function () {
isShopOpen = false;
if (shopContainer) {
shopContainer.destroy();
shopContainer = null;
}
};
};
return self;
});
var Snake = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('snakeHead', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Game configuration
var GRID_SIZE = 40;
var BOARD_WIDTH = 35;
var BOARD_HEIGHT = 50;
var MOVE_DELAY = 8; // Frames between moves
// Game state variables
var snake = [];
var snakeDirection = {
x: 1,
y: 0
};
var nextDirection = {
x: 1,
y: 0
};
var food = null;
var moveCounter = 0;
var isGameRunning = true;
var friendlySnakes = [];
var friendlySnakeTimer = 0;
var enemySnakes = [];
var enemySnakeTimer = 0;
var foodItems = [];
var gigaChad = null;
var gigaChadNotified = false;
var shopButton = null;
var shopEffects = {
slowdown: {
active: false,
timer: 0
},
speedGigachad: {
active: false
},
doublePoints: {
active: false,
timer: 0
}
};
var isShopOpen = false;
var shopContainer = null;
// Calculate board position to center it horizontally and leave space for controls at bottom
var boardOffsetX = (2048 - BOARD_WIDTH * GRID_SIZE) / 2;
var boardOffsetY = 100; // Start closer to top, leaving space for controls at bottom
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0.5);
// Position score centered horizontally and at control buttons level
scoreTxt.x = 2048 / 2; // Center horizontally
scoreTxt.y = 2732 - 300; // Same vertical level as control buttons
game.addChild(scoreTxt);
// Initialize snake with only head
function initializeSnake() {
snake = [];
// Create head using new Snake class
var head = game.addChild(new Snake());
head.x = boardOffsetX + 12 * GRID_SIZE;
head.y = boardOffsetY + 25 * GRID_SIZE;
snake.push({
x: 12,
y: 25,
obj: head
});
}
// Convert grid coordinates to screen coordinates
function gridToScreen(gridX, gridY) {
return {
x: boardOffsetX + gridX * GRID_SIZE,
y: boardOffsetY + gridY * GRID_SIZE
};
}
// Generate random food position
function spawnFood() {
var validPositions = [];
// Find all valid positions (not occupied by snake)
for (var x = 0; x < BOARD_WIDTH; x++) {
for (var y = 0; y < BOARD_HEIGHT; y++) {
var occupied = false;
for (var i = 0; i < snake.length; i++) {
if (snake[i].x === x && snake[i].y === y) {
occupied = true;
break;
}
}
if (!occupied) {
validPositions.push({
x: x,
y: y
});
}
}
}
if (validPositions.length > 0) {
var randomIndex = Math.floor(Math.random() * validPositions.length);
var pos = validPositions[randomIndex];
if (food) {
food.destroy();
}
food = game.addChild(new Food());
var screenPos = gridToScreen(pos.x, pos.y);
food.x = screenPos.x;
food.y = screenPos.y;
food.gridX = pos.x;
food.gridY = pos.y;
foodItems.push(food);
}
}
// Check if position is valid (within bounds and not colliding with snake)
function isValidPosition(x, y) {
// Check bounds
if (x < 0 || x >= BOARD_WIDTH || y < 0 || y >= BOARD_HEIGHT) {
return false;
}
// No body collision check needed for head-only snake
return true;
}
// Move snake
function moveSnake() {
if (!isGameRunning) {
return;
}
// Direction is already updated immediately in changeDirection function
// Calculate new head position
var head = snake[0];
var newHeadX = head.x + snakeDirection.x;
var newHeadY = head.y + snakeDirection.y;
// Check if new position is valid
if (!isValidPosition(newHeadX, newHeadY)) {
// Game over
isGameRunning = false;
LK.getSound('gameOver').play();
LK.showGameOver();
return;
}
// Check if any food is eaten
var ateFood = false;
for (var i = foodItems.length - 1; i >= 0; i--) {
var currentFood = foodItems[i];
if (currentFood && newHeadX === currentFood.gridX && newHeadY === currentFood.gridY) {
ateFood = true;
var points = currentFood.foodType === 'level2' ? 20 : 10;
// Apply double points effect if active
if (shopEffects.doublePoints.active) {
points *= 2;
}
// Convert points to coins for shop
var coins = storage.coins || 0;
storage.coins = coins + Math.floor(points / 10); // 1 coin per 10 points
LK.setScore(LK.getScore() + points);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('eat').play();
// Flash food before removing
tween(currentFood, {
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
currentFood.destroy();
}
});
foodItems.splice(i, 1);
if (currentFood === food) {
food = null;
spawnFood();
}
break;
}
}
// Simply move the existing head to new position (no growth)
var headObj = snake[0].obj;
var screenPos = gridToScreen(newHeadX, newHeadY);
headObj.x = screenPos.x;
headObj.y = screenPos.y;
snake[0].x = newHeadX;
snake[0].y = newHeadY;
}
// Handle direction changes
function changeDirection(newDir) {
// Prevent immediate reversal
if (newDir.x === -snakeDirection.x && newDir.y === -snakeDirection.y) {
return;
}
// Prevent diagonal movement - only allow pure horizontal or vertical movement
if (newDir.x !== 0 && newDir.y !== 0) {
return;
}
// Apply direction change immediately for responsive controls
snakeDirection.x = newDir.x;
snakeDirection.y = newDir.y;
nextDirection.x = newDir.x;
nextDirection.y = newDir.y;
}
// Remove touch controls - snake can only be controlled by buttons
// Create visible walls around the game board
function createWalls() {
// Top and bottom walls
for (var x = -1; x <= BOARD_WIDTH; x++) {
// Top wall
var topWall = game.addChild(LK.getAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
}));
topWall.x = boardOffsetX + x * GRID_SIZE;
topWall.y = boardOffsetY - GRID_SIZE;
// Bottom wall
var bottomWall = game.addChild(LK.getAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
}));
bottomWall.x = boardOffsetX + x * GRID_SIZE;
bottomWall.y = boardOffsetY + BOARD_HEIGHT * GRID_SIZE;
}
// Left and right walls
for (var y = -1; y <= BOARD_HEIGHT; y++) {
// Left wall
var leftWall = game.addChild(LK.getAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
}));
leftWall.x = boardOffsetX - GRID_SIZE;
leftWall.y = boardOffsetY + y * GRID_SIZE;
// Right wall
var rightWall = game.addChild(LK.getAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
}));
rightWall.x = boardOffsetX + BOARD_WIDTH * GRID_SIZE;
rightWall.y = boardOffsetY + y * GRID_SIZE;
}
}
// Create directional control buttons
var upButton = game.addChild(new DirectionalButton({
x: 0,
y: -1
}, 'upButton'));
var downButton = game.addChild(new DirectionalButton({
x: 0,
y: 1
}, 'downButton'));
var leftButton = game.addChild(new DirectionalButton({
x: -1,
y: 0
}, 'leftButton'));
var rightButton = game.addChild(new DirectionalButton({
x: 1,
y: 0
}, 'rightButton'));
// Position buttons in bottom right corner
var buttonSpacing = 140;
var buttonBaseX = 2048 - 200;
var buttonBaseY = 2732 - 300;
// Up button
upButton.x = buttonBaseX;
upButton.y = buttonBaseY - buttonSpacing;
// Down button
downButton.x = buttonBaseX;
downButton.y = buttonBaseY + buttonSpacing;
// Left button
leftButton.x = buttonBaseX - buttonSpacing;
leftButton.y = buttonBaseY;
// Right button
rightButton.x = buttonBaseX + buttonSpacing;
rightButton.y = buttonBaseY;
// Add text labels to buttons
var upText = new Text2('↑', {
size: 60,
fill: 0xFFFFFF
});
upText.anchor.set(0.5, 0.5);
upText.x = upButton.x;
upText.y = upButton.y;
game.addChild(upText);
var downText = new Text2('↓', {
size: 60,
fill: 0xFFFFFF
});
downText.anchor.set(0.5, 0.5);
downText.x = downButton.x;
downText.y = downButton.y;
game.addChild(downText);
var leftText = new Text2('←', {
size: 60,
fill: 0xFFFFFF
});
leftText.anchor.set(0.5, 0.5);
leftText.x = leftButton.x;
leftText.y = leftButton.y;
game.addChild(leftText);
var rightText = new Text2('→', {
size: 60,
fill: 0xFFFFFF
});
rightText.anchor.set(0.5, 0.5);
rightText.x = rightButton.x;
rightText.y = rightButton.y;
game.addChild(rightText);
// Initialize game
createWalls();
initializeSnake();
spawnFood();
// Merchant functionality is handled through the shop button
// Create shop button at bottom center
shopButton = game.addChild(new ShopButton());
shopButton.x = 2048 / 2; // Center horizontally
shopButton.y = 2732 - 150; // Bottom of screen with some margin
// Add shop button text
var shopText = new Text2('SHOP', {
size: 40,
fill: 0xFFFFFF
});
shopText.anchor.set(0.5, 0.5);
shopText.x = shopButton.x;
shopText.y = shopButton.y;
game.addChild(shopText);
// Add shop interaction handler
game.down = function (x, y, obj) {
if (isShopOpen && shopButton) {
shopButton.handleShopClick(x, y);
}
};
// Main game loop
game.update = function () {
if (!isGameRunning || isShopOpen) {
return;
}
moveCounter++;
var currentMoveDelay = MOVE_DELAY;
if (shopEffects.slowdown.active) {
currentMoveDelay = MOVE_DELAY * 2; // Double the delay = half the speed
}
if (moveCounter >= currentMoveDelay) {
moveCounter = 0;
moveSnake();
}
// Spawn friendly snakes every 10 seconds (600 frames at 60fps)
friendlySnakeTimer++;
if (friendlySnakeTimer >= 600) {
friendlySnakeTimer = 0;
var friendlySnake = game.addChild(new FriendlySnake());
// Spawn at random edge position within board bounds only
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top - ensure spawn within board width
friendlySnake.x = boardOffsetX + (Math.random() * (BOARD_WIDTH - 2) + 1) * GRID_SIZE;
friendlySnake.y = boardOffsetY + GRID_SIZE;
break;
case 1:
// Right - ensure spawn within board height
friendlySnake.x = boardOffsetX + (BOARD_WIDTH - 1) * GRID_SIZE;
friendlySnake.y = boardOffsetY + (Math.random() * (BOARD_HEIGHT - 2) + 1) * GRID_SIZE;
break;
case 2:
// Bottom - ensure spawn within board width
friendlySnake.x = boardOffsetX + (Math.random() * (BOARD_WIDTH - 2) + 1) * GRID_SIZE;
friendlySnake.y = boardOffsetY + (BOARD_HEIGHT - 1) * GRID_SIZE;
break;
case 3:
// Left - ensure spawn within board height
friendlySnake.x = boardOffsetX + GRID_SIZE;
friendlySnake.y = boardOffsetY + (Math.random() * (BOARD_HEIGHT - 2) + 1) * GRID_SIZE;
break;
}
friendlySnakes.push(friendlySnake);
}
// Spawn enemy snakes every 8 seconds (480 frames at 60fps)
enemySnakeTimer++;
if (enemySnakeTimer >= 480) {
enemySnakeTimer = 0;
var enemySnake = game.addChild(new EnemySnake());
// Spawn at random edge position within board bounds only
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top - ensure spawn within board width
enemySnake.x = boardOffsetX + (Math.random() * (BOARD_WIDTH - 2) + 1) * GRID_SIZE;
enemySnake.y = boardOffsetY + GRID_SIZE;
break;
case 1:
// Right - ensure spawn within board height
enemySnake.x = boardOffsetX + (BOARD_WIDTH - 1) * GRID_SIZE;
enemySnake.y = boardOffsetY + (Math.random() * (BOARD_HEIGHT - 2) + 1) * GRID_SIZE;
break;
case 2:
// Bottom - ensure spawn within board width
enemySnake.x = boardOffsetX + (Math.random() * (BOARD_WIDTH - 2) + 1) * GRID_SIZE;
enemySnake.y = boardOffsetY + (BOARD_HEIGHT - 1) * GRID_SIZE;
break;
case 3:
// Left - ensure spawn within board height
enemySnake.x = boardOffsetX + GRID_SIZE;
enemySnake.y = boardOffsetY + (Math.random() * (BOARD_HEIGHT - 2) + 1) * GRID_SIZE;
break;
}
enemySnakes.push(enemySnake);
}
// Check collision between player and enemy snakes
if (snake.length > 0) {
var playerHead = snake[0];
var playerScreenPos = gridToScreen(playerHead.x, playerHead.y);
for (var i = enemySnakes.length - 1; i >= 0; i--) {
var enemySnake = enemySnakes[i];
var dist = Math.sqrt(Math.pow(playerScreenPos.x - enemySnake.x, 2) + Math.pow(playerScreenPos.y - enemySnake.y, 2));
if (dist < 60) {
// Collision detected
// Check if friendly snake is protecting
var isProtected = false;
for (var j = 0; j < friendlySnakes.length; j++) {
var friendlySnake = friendlySnakes[j];
var friendlyDist = Math.sqrt(Math.pow(playerScreenPos.x - friendlySnake.x, 2) + Math.pow(playerScreenPos.y - friendlySnake.y, 2));
if (friendlyDist < 100) {
// Protection range
isProtected = true;
// Remove the enemy snake as it's defeated by friendly snake
enemySnake.destroy();
enemySnakes.splice(i, 1);
LK.setScore(LK.getScore() + 50); // Bonus for protection
scoreTxt.setText('Score: ' + LK.getScore());
break;
}
}
if (!isProtected) {
// Game over - player eaten by enemy snake
isGameRunning = false;
LK.getSound('gameOver').play();
LK.showGameOver();
return;
}
}
}
}
// Reset GIGACHAD notification if no enemies remain
if (enemySnakes.length === 0) {
gigaChadNotified = false;
}
// Update shop effects
if (shopEffects.slowdown.active) {
shopEffects.slowdown.timer++;
if (shopEffects.slowdown.timer >= 18000) {
// 5 minutes
shopEffects.slowdown.active = false;
shopEffects.slowdown.timer = 0;
}
}
if (shopEffects.doublePoints.active) {
shopEffects.doublePoints.timer++;
if (shopEffects.doublePoints.timer >= 18000) {
// 5 minutes
shopEffects.doublePoints.active = false;
shopEffects.doublePoints.timer = 0;
}
}
};
robotik yap
wall block. In-Game asset. 2d. High contrast. No shadows
energy ball. In-Game asset. 2d. High contrast. No shadows
frendly robotic snake. In-Game asset. 2d. High contrast. No shadows
rainbow energy. In-Game asset. 2d. High contrast. No shadows
enemy robotic snake. In-Game asset. 2d. High contrast. No shadows
Robotic GigaChad snake. In-Game asset. 2d. High contrast. No shadows
yellow and orange cube 2d. In-Game asset. 2d. High contrast. No shadows
button red 2d. In-Game asset. 2d. High contrast. No shadows