User prompt
Que haiga otro tipo de alimento que sea una papa
User prompt
Que no más de uno ataquen el jugadlr
User prompt
Que food me de 100 size
User prompt
Pero que haigan 15 gigantes
User prompt
Que no haigan tantos bots grandes
User prompt
Cuanto tenga size 50 a 300 se mueva más rapido
User prompt
Que uno alos 5000 se todavia bastante rapido alos 20000 se ponga lento
User prompt
que todavia sea un poquito rapido alos 1000 y alos 5000 se ponga lento
User prompt
Que den 200 punto el nuevo tipo de comida
User prompt
Que haiga otro tipo de comida
User prompt
Que haiga pavo comida quede 200 size
User prompt
Listo el juego
User prompt
Que el jugadlr siempre aparesca donde no halla casi bots
User prompt
Que el dado sea más grande
User prompt
Que el dado sea blanco
User prompt
Entonces alado del nombre pon un dado para un nombre ranmdon
User prompt
Que el incio de pantalla sea como el de sliter io
User prompt
Que el fondo de inicio de pantalla no se vea nada
User prompt
Que el fondo del inicio de pantalla sea azul
User prompt
Please fix the bug: 'Uncaught TypeError: LK.gui.prompt is not a function' in or related to this line: 'LK.gui.prompt({' Line Number: 293
User prompt
Que aparesca el teclado para poner el nombre
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of null (setting 'targetX')' in or related to this line: 'playerCell.targetX = dragPlayerStartX + dx * 8;' Line Number: 475
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of null (reading 'x')' in or related to this line: 'dragPlayerStartX = playerCell.x;' Line Number: 449
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'var fx = playerCell.x + Math.cos(angle) * dist;' Line Number: 412
User prompt
Que haiga un inicio de pantalla para poner el nombre y el inicio
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var AICell = Container.expand(function () { var self = Container.call(this); var cellGraphics = self.attachAsset('cell', { anchorX: 0.5, anchorY: 0.5 }); // self.size is set on spawnAICell for variety self.speed = 2 + Math.random(); self.targetX = Math.random() * 8192; self.targetY = Math.random() * 8192; self.alive = true; self.lastX = self.x; self.lastY = self.y; self.update = function () { if (!self.alive) { return; } // --- AI Hunt Player Logic --- // Only some AI cells hunt the player var huntingPlayer = false; if (self.huntsPlayer && typeof playerCell !== "undefined" && playerCell !== null) { var pdx = playerCell.x - self.x; var pdy = playerCell.y - self.y; var pdist = Math.sqrt(pdx * pdx + pdy * pdy); // Only hunt if AI is bigger than player by 20% if (self.size > playerCell.size * 1.2) { // Hunt if player is within 2000px (long range) if (pdist < 2000) { self.targetX = playerCell.x; self.targetY = playerCell.y; huntingPlayer = true; } } } // Move towards target var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { // Speed: all cells are fast except those with size > 1000, which are slow var speed; if (self.size > 1000) { speed = 0.8; } else { speed = 5.5; } self.x += dx / distance * speed; self.y += dy / distance * speed; } else { // Pick new random target self.targetX = Math.random() * 14000; self.targetY = Math.random() * 14000; } // Keep within bounds if (self.x < self.size / 2) { self.x = self.size / 2; } if (self.x > 14000 - self.size / 2) { self.x = 14000 - self.size / 2; } if (self.y < self.size / 2) { self.y = self.size / 2; } if (self.y > 14000 - self.size / 2) { self.y = 14000 - self.size / 2; } self.lastX = self.x; self.lastY = self.y; }; self.grow = function (amount) { var oldSize = self.size; self.size += amount; var scale = self.size / 50; tween(cellGraphics, { scaleX: scale, scaleY: scale }, { duration: 200, easing: tween.easeOut }); self.speed = Math.max(0.8, 2.5 - (self.size - 50) / 60); }; return self; }); var Food = Container.expand(function () { var self = Container.call(this); var foodGraphics = self.attachAsset('food', { anchorX: 0.5, anchorY: 0.5 }); self.size = 20; self.consumed = false; return self; }); var PlayerCell = Container.expand(function () { var self = Container.call(this); var cellGraphics = self.attachAsset('cell', { anchorX: 0.5, anchorY: 0.5 }); self.size = 50; self.speed = 3; self.targetX = self.x; self.targetY = self.y; self.grow = function (amount) { var oldSize = self.size; self.size += amount; // Update visual scale var scale = self.size / 50; tween(cellGraphics, { scaleX: scale, scaleY: scale }, { duration: 200, easing: tween.easeOut }); // Reduce speed as size increases self.speed = Math.max(1, 3 - (self.size - 50) / 50); LK.getSound('grow').play(); LK.setScore(Math.floor(self.size)); }; self.update = function () { // Slither.io style drag controls: playerCell.targetX/Y is set by drag logic in game.move // Move towards target position var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { // Speed: player is fast except when size > 1000, then slow var speed; if (self.size > 1000) { speed = 1.2; } else { speed = 7; } self.x += dx / distance * speed; self.y += dy / distance * speed; } // Keep within bounds if (self.x < self.size / 2) { self.x = self.size / 2; } if (self.x > 14000 - self.size / 2) { self.x = 14000 - self.size / 2; } if (self.y < self.size / 2) { self.y = self.size / 2; } if (self.y > 14000 - self.size / 2) { self.y = 14000 - self.size / 2; } }; return self; }); var Predator = Container.expand(function () { var self = Container.call(this); var predatorGraphics = self.attachAsset('predator', { anchorX: 0.5, anchorY: 0.5 }); self.size = 80; self.speed = 1; self.targetX = Math.random() * 8192; self.targetY = Math.random() * 8192; self.update = function () { // Move towards target var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { // Predators are always slow self.x += dx / distance * 1.2; self.y += dy / distance * 1.2; } else { // Pick new random target self.targetX = Math.random() * 14000; self.targetY = Math.random() * 14000; } // Chase player if close enough if (typeof playerCell !== "undefined" && playerCell !== null) { var playerDx = playerCell.x - self.x; var playerDy = playerCell.y - self.y; var playerDistance = Math.sqrt(playerDx * playerDx + playerDy * playerDy); if (playerDistance < 300 && playerCell.size < self.size) { self.x += playerDx / playerDistance * self.speed * 1.5; self.y += playerDy / playerDistance * self.speed * 1.5; } } // Keep within bounds if (self.x < 0) { self.x = 0; } if (self.x > 14000) { self.x = 14000; } if (self.y < 0) { self.y = 0; } if (self.y > 14000) { self.y = 14000; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2C3E50 }); /**** * Game Code ****/ var playerCell = null; var foods = []; var predators = []; var aiCells = []; var cellsEaten = 0; // --- Start Screen UI --- var startScreen = new Container(); var startBg = LK.getAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5 }); startBg.scaleX = 10; startBg.scaleY = 10; startBg.alpha = 0.92; startBg.x = 2048 / 2; startBg.y = 2732 / 2; startScreen.addChild(startBg); var titleTxt = new Text2("¡Célula Survival!", { size: 120, fill: "#fff" }); titleTxt.anchor.set(0.5, 0); titleTxt.x = 2048 / 2; titleTxt.y = 400; startScreen.addChild(titleTxt); var nameLabel = new Text2("Tu nombre:", { size: 64, fill: "#fff" }); nameLabel.anchor.set(0.5, 0); nameLabel.x = 2048 / 2; nameLabel.y = 700; startScreen.addChild(nameLabel); // Simple text input using LK.gui (simulated, as LK does not have a native input, so we use a Text2 and tap to edit) var playerName = ""; var nameInput = new Text2("Toca para escribir...", { size: 72, fill: 0xFFFFCC }); nameInput.anchor.set(0.5, 0); nameInput.x = 2048 / 2; nameInput.y = 800; startScreen.addChild(nameInput); // Show a start button var startBtn = new Text2("INICIAR", { size: 100, fill: 0x00FF99 }); startBtn.anchor.set(0.5, 0.5); startBtn.x = 2048 / 2; startBtn.y = 1100; startBtn.interactive = true; startBtn.buttonMode = true; startScreen.addChild(startBtn); var editingName = false; nameInput.interactive = true; nameInput.buttonMode = true; nameInput.down = function (x, y, obj) { editingName = true; nameInput.setText(playerName + "|"); }; game.down = function (x, y, obj) { // If editing name, simulate typing by adding a random letter (since we can't get real keyboard input) if (editingName) { // Simulate: tap = add random letter, long tap = backspace if (playerName.length < 10) { var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var letter = letters[Math.floor(Math.random() * letters.length)]; playerName += letter; } nameInput.setText(playerName + "|"); // If tap on left side, treat as backspace if (x < 2048 / 2 - 200 && playerName.length > 0) { playerName = playerName.substring(0, playerName.length - 1); nameInput.setText(playerName + "|"); } // If tap on right side, finish editing if (x > 2048 / 2 + 200) { editingName = false; nameInput.setText(playerName.length > 0 ? playerName : "Toca para escribir..."); } return; } }; startBtn.down = function (x, y, obj) { if (playerName.length === 0) { playerName = "Tú"; nameInput.setText(playerName); } // Hide start screen and start the game startScreen.visible = false; startScreen.interactive = false; startScreen.children.forEach(function (child) { child.visible = false; }); startGame(); }; game.addChild(startScreen); // --- Main game UI (hidden until start) --- var scoreTxt = new Text2('Size: 50', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Display for #1 (largest cell) score var topScoreTxt = new Text2('', { size: 48, fill: 0xFFD700 }); topScoreTxt.anchor.set(0.5, 0); topScoreTxt.y = 70; // Place below main score, avoid top 100px LK.gui.top.addChild(topScoreTxt); // Create a world container for all game objects (slither.io style) var world = new Container(); game.addChild(world); // --- Game start logic --- function startGame() { // Initialize player cell playerCell = new PlayerCell(); playerCell.x = 14000 / 2; playerCell.y = 14000 / 2; // Assign a name to the player cell var allNames = ["Nano", "Blob", "Zeta", "Mito", "Viru", "Giga", "Beta", "Toxi", "Rex", "Lumo", "Fago", "Proto", "Mega", "Pico", "Tera", "Vivo", "Cello", "Dino", "Mobi", "Rondo"]; playerCell.randomName = playerName && playerName.length > 0 ? playerName : allNames[Math.floor(Math.random() * allNames.length)]; world.addChild(playerCell); } // Generate initial food function spawnFood() { var food = new Food(); food.x = Math.random() * 14000; food.y = Math.random() * 14000; foods.push(food); world.addChild(food); } ; // Generate initial predators function spawnPredator() { var predator = new Predator(); predator.x = Math.random() * 14000; predator.y = Math.random() * 14000; // Assign a random name to the predator var allNames = ["Nano", "Blob", "Zeta", "Mito", "Viru", "Giga", "Beta", "Toxi", "Rex", "Lumo", "Fago", "Proto", "Mega", "Pico", "Tera", "Vivo", "Cello", "Dino", "Mobi", "Rondo"]; predator.randomName = allNames[Math.floor(Math.random() * allNames.length)]; predators.push(predator); world.addChild(predator); } // Generate AI cells function spawnAICell() { var ai = new AICell(); ai.x = Math.random() * 14000; ai.y = Math.random() * 14000; // Assign random size: 50, 70, 90, 150, 300, or 1000 var possibleSizes = [50, 70, 90, 150, 300, 1000]; var sizeIdx = Math.floor(Math.random() * possibleSizes.length); ai.size = possibleSizes[sizeIdx]; // Update scale to match new size var scale = ai.size / 50; if (ai.children && ai.children.length > 0) { var cellGraphics = ai.children[0]; cellGraphics.scaleX = scale; cellGraphics.scaleY = scale; } // Assign a random name to this AI cell var aiNames = ["Nano", "Blob", "Zeta", "Mito", "Viru", "Giga", "Beta", "Toxi", "Rex", "Lumo", "Fago", "Proto", "Mega", "Pico", "Tera", "Vivo", "Cello", "Dino", "Mobi", "Rondo"]; ai.randomName = aiNames[Math.floor(Math.random() * aiNames.length)]; // Only some AI cells will hunt the player // 40% of AI cells will hunt the player, others will ignore the player ai.huntsPlayer = Math.random() < 0.4; aiCells.push(ai); world.addChild(ai); } // Spawn initial food, most near the player, some random for (var i = 0; i < 80; i++) { if (i < 60) { // Near player: in a ring 300-900px from player var angle = Math.random() * Math.PI * 2; var dist = 300 + Math.random() * 600; var fx = playerCell.x + Math.cos(angle) * dist; var fy = playerCell.y + Math.sin(angle) * dist; fx = Math.max(20, Math.min(fx, 14000 - 20)); fy = Math.max(20, Math.min(fy, 14000 - 20)); var food = new Food(); food.x = fx; food.y = fy; foods.push(food); world.addChild(food); } else { spawnFood(); } } // Spawn initial predators for (var i = 0; i < 5; i++) { spawnPredator(); } // Spawn initial AI cells for (var i = 0; i < 60; i++) { spawnAICell(); } // Slither.io style swipe/drag controls var dragging = false; var dragTouchId = null; var lastTouchX = null; var lastTouchY = null; var dragStartX = null; var dragStartY = null; var dragPlayerStartX = null; var dragPlayerStartY = null; game.down = function (x, y, obj) { // Start dragging from anywhere except top left 100x100 if (!(x < 100 && y < 100)) { dragging = true; dragTouchId = obj && obj.event && obj.event.identifier !== undefined ? obj.event.identifier : null; dragStartX = x; dragStartY = y; dragPlayerStartX = playerCell.x; dragPlayerStartY = playerCell.y; lastTouchX = x; lastTouchY = y; } }; game.move = function (x, y, obj) { if (dragging && (dragTouchId === null || obj && obj.event && obj.event.identifier === dragTouchId)) { lastTouchX = x; lastTouchY = y; // Calculate drag vector relative to drag start var dx = x - dragStartX; var dy = y - dragStartY; // Set a max drag distance for control sensitivity var maxDrag = 400; var dragLen = Math.sqrt(dx * dx + dy * dy); if (dragLen > maxDrag) { dx = dx * maxDrag / dragLen; dy = dy * maxDrag / dragLen; } // Set the target position for the player cell based on drag playerCell.targetX = dragPlayerStartX + dx * 8; playerCell.targetY = dragPlayerStartY + dy * 8; } }; game.up = function (x, y, obj) { if (dragging && (dragTouchId === null || obj && obj.event && obj.event.identifier === dragTouchId)) { dragging = false; dragTouchId = null; lastTouchX = null; lastTouchY = null; dragStartX = null; dragStartY = null; dragPlayerStartX = null; dragPlayerStartY = null; } }; game.update = function () { if (!playerCell) { return; } // Camera logic: center world on playerCell, clamp to map bounds (slither.io style) var viewWidth = 2048; var viewHeight = 2732; var mapSize = 14000; // Calculate camera target position to center player var camTargetX = playerCell.x - viewWidth / 2; var camTargetY = playerCell.y - viewHeight / 2; // Clamp camera to map bounds camTargetX = Math.max(0, Math.min(camTargetX, mapSize - viewWidth)); camTargetY = Math.max(0, Math.min(camTargetY, mapSize - viewHeight)); // Smooth camera movement (slither.io style) if (typeof world.lastCamX === "undefined") world.lastCamX = camTargetX; if (typeof world.lastCamY === "undefined") world.lastCamY = camTargetY; world.lastCamX += (camTargetX - world.lastCamX) * 0.15; world.lastCamY += (camTargetY - world.lastCamY) * 0.15; // Move world container world.x = -Math.round(world.lastCamX); world.y = -Math.round(world.lastCamY); // AI cells update and logic for (var i = aiCells.length - 1; i >= 0; i--) { var ai = aiCells[i]; if (!ai.alive) { continue; } ai.update(); // AI eats food for (var j = foods.length - 1; j >= 0; j--) { var food = foods[j]; if (food.consumed) { continue; } var dx = ai.x - food.x; var dy = ai.y - food.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < ai.size / 2 + food.size / 2) { food.consumed = true; food.destroy(); foods.splice(j, 1); ai.grow(5); break; } } // AI eats other AI (io style) for (var k = aiCells.length - 1; k >= 0; k--) { if (i === k) { continue; } var other = aiCells[k]; if (!other.alive) { continue; } var dx = ai.x - other.x; var dy = ai.y - other.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < ai.size / 2 + other.size / 2) { if (ai.size > other.size * 1.2) { other.alive = false; other.destroy(); ai.grow(other.size / 2); aiCells.splice(k, 1); if (k < i) { i--; } // Adjust index if needed break; } } } // AI can eat player or be eaten by player var dxp = ai.x - playerCell.x; var dyp = ai.y - playerCell.y; var distp = Math.sqrt(dxp * dxp + dyp * dyp); if (distp < ai.size / 2 + playerCell.size / 2) { if (ai.size > playerCell.size * 1.2) { // Player is eaten by a larger AI cell LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } else if (playerCell.size > ai.size * 1.2) { // Player eats smaller AI cell ai.alive = false; ai.destroy(); aiCells.splice(i, 1); playerCell.grow(ai.size / 2); cellsEaten++; LK.getSound('eat').play(); scoreTxt.setText('Size: ' + Math.floor(playerCell.size) + ' | Eaten: ' + cellsEaten); break; } } } // Check food collisions for player for (var i = foods.length - 1; i >= 0; i--) { var food = foods[i]; if (food.consumed) { continue; } var dx = playerCell.x - food.x; var dy = playerCell.y - food.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < playerCell.size / 2 + food.size / 2) { // Consume food food.consumed = true; food.destroy(); foods.splice(i, 1); playerCell.grow(5); // Do not increment cellsEaten for food LK.getSound('eat').play(); // Update score display scoreTxt.setText('Size: ' + Math.floor(playerCell.size)); } } // Check predator collisions for (var i = 0; i < predators.length; i++) { var predator = predators[i]; var dx = playerCell.x - predator.x; var dy = playerCell.y - predator.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < playerCell.size / 2 + predator.size / 2) { if (predator.size > playerCell.size) { // Game over - eaten by predator LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } else if (playerCell.size > predator.size * 1.2) { // Player can eat predator predator.destroy(); predators.splice(i, 1); playerCell.grow(20); cellsEaten++; LK.getSound('eat').play(); scoreTxt.setText('Size: ' + Math.floor(playerCell.size) + ' | Eaten: ' + cellsEaten); // Spawn new predator spawnPredator(); i--; // Adjust index after removal } } } // Spawn new food periodically, but always near the player if (LK.ticks % 120 == 0 && foods.length < 65) { // Spawn food in a ring 300-700px from player, random angle var angle = Math.random() * Math.PI * 2; var dist = 300 + Math.random() * 400; var fx = playerCell.x + Math.cos(angle) * dist; var fy = playerCell.y + Math.sin(angle) * dist; // Clamp to map bounds fx = Math.max(20, Math.min(fx, 14000 - 20)); fy = Math.max(20, Math.min(fy, 14000 - 20)); var food = new Food(); food.x = fx; food.y = fy; foods.push(food); world.addChild(food); } // Add more predators as player grows if (LK.ticks % 600 == 0 && predators.length < 8) { spawnPredator(); } // Add more AI cells as the game progresses if (LK.ticks % 300 == 0 && aiCells.length < 12) { spawnAICell(); } // Win condition removed: score is now infinite // Find the largest cell (player, aiCells, predators) var topCell = playerCell; var topCellType = "Tú"; var topCellSize = playerCell ? playerCell.size : 0; var topCellName = null; // Check AI cells for (var i = 0; i < aiCells.length; i++) { if (aiCells[i].alive && aiCells[i].size > topCellSize) { topCell = aiCells[i]; topCellType = "Bot"; topCellSize = aiCells[i].size; topCellName = aiCells[i].randomName; } } // Check predators for (var i = 0; i < predators.length; i++) { if (predators[i].size > topCellSize) { topCell = predators[i]; topCellType = "Depredador"; topCellSize = predators[i].size; topCellName = null; } } // Show #1 score if (topCell === playerCell) { topScoreTxt.setText("#1: Tú (" + Math.floor(topCellSize) + ")"); } else if (topCellType === "Bot" && topCellName) { topScoreTxt.setText("#1: " + topCellName + " (" + Math.floor(topCellSize) + ")"); } else { topScoreTxt.setText("#1: " + topCellType + " (" + Math.floor(topCellSize) + ")"); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var AICell = Container.expand(function () {
var self = Container.call(this);
var cellGraphics = self.attachAsset('cell', {
anchorX: 0.5,
anchorY: 0.5
});
// self.size is set on spawnAICell for variety
self.speed = 2 + Math.random();
self.targetX = Math.random() * 8192;
self.targetY = Math.random() * 8192;
self.alive = true;
self.lastX = self.x;
self.lastY = self.y;
self.update = function () {
if (!self.alive) {
return;
}
// --- AI Hunt Player Logic ---
// Only some AI cells hunt the player
var huntingPlayer = false;
if (self.huntsPlayer && typeof playerCell !== "undefined" && playerCell !== null) {
var pdx = playerCell.x - self.x;
var pdy = playerCell.y - self.y;
var pdist = Math.sqrt(pdx * pdx + pdy * pdy);
// Only hunt if AI is bigger than player by 20%
if (self.size > playerCell.size * 1.2) {
// Hunt if player is within 2000px (long range)
if (pdist < 2000) {
self.targetX = playerCell.x;
self.targetY = playerCell.y;
huntingPlayer = true;
}
}
}
// Move towards target
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
// Speed: all cells are fast except those with size > 1000, which are slow
var speed;
if (self.size > 1000) {
speed = 0.8;
} else {
speed = 5.5;
}
self.x += dx / distance * speed;
self.y += dy / distance * speed;
} else {
// Pick new random target
self.targetX = Math.random() * 14000;
self.targetY = Math.random() * 14000;
}
// Keep within bounds
if (self.x < self.size / 2) {
self.x = self.size / 2;
}
if (self.x > 14000 - self.size / 2) {
self.x = 14000 - self.size / 2;
}
if (self.y < self.size / 2) {
self.y = self.size / 2;
}
if (self.y > 14000 - self.size / 2) {
self.y = 14000 - self.size / 2;
}
self.lastX = self.x;
self.lastY = self.y;
};
self.grow = function (amount) {
var oldSize = self.size;
self.size += amount;
var scale = self.size / 50;
tween(cellGraphics, {
scaleX: scale,
scaleY: scale
}, {
duration: 200,
easing: tween.easeOut
});
self.speed = Math.max(0.8, 2.5 - (self.size - 50) / 60);
};
return self;
});
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphics = self.attachAsset('food', {
anchorX: 0.5,
anchorY: 0.5
});
self.size = 20;
self.consumed = false;
return self;
});
var PlayerCell = Container.expand(function () {
var self = Container.call(this);
var cellGraphics = self.attachAsset('cell', {
anchorX: 0.5,
anchorY: 0.5
});
self.size = 50;
self.speed = 3;
self.targetX = self.x;
self.targetY = self.y;
self.grow = function (amount) {
var oldSize = self.size;
self.size += amount;
// Update visual scale
var scale = self.size / 50;
tween(cellGraphics, {
scaleX: scale,
scaleY: scale
}, {
duration: 200,
easing: tween.easeOut
});
// Reduce speed as size increases
self.speed = Math.max(1, 3 - (self.size - 50) / 50);
LK.getSound('grow').play();
LK.setScore(Math.floor(self.size));
};
self.update = function () {
// Slither.io style drag controls: playerCell.targetX/Y is set by drag logic in game.move
// Move towards target position
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
// Speed: player is fast except when size > 1000, then slow
var speed;
if (self.size > 1000) {
speed = 1.2;
} else {
speed = 7;
}
self.x += dx / distance * speed;
self.y += dy / distance * speed;
}
// Keep within bounds
if (self.x < self.size / 2) {
self.x = self.size / 2;
}
if (self.x > 14000 - self.size / 2) {
self.x = 14000 - self.size / 2;
}
if (self.y < self.size / 2) {
self.y = self.size / 2;
}
if (self.y > 14000 - self.size / 2) {
self.y = 14000 - self.size / 2;
}
};
return self;
});
var Predator = Container.expand(function () {
var self = Container.call(this);
var predatorGraphics = self.attachAsset('predator', {
anchorX: 0.5,
anchorY: 0.5
});
self.size = 80;
self.speed = 1;
self.targetX = Math.random() * 8192;
self.targetY = Math.random() * 8192;
self.update = function () {
// Move towards target
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
// Predators are always slow
self.x += dx / distance * 1.2;
self.y += dy / distance * 1.2;
} else {
// Pick new random target
self.targetX = Math.random() * 14000;
self.targetY = Math.random() * 14000;
}
// Chase player if close enough
if (typeof playerCell !== "undefined" && playerCell !== null) {
var playerDx = playerCell.x - self.x;
var playerDy = playerCell.y - self.y;
var playerDistance = Math.sqrt(playerDx * playerDx + playerDy * playerDy);
if (playerDistance < 300 && playerCell.size < self.size) {
self.x += playerDx / playerDistance * self.speed * 1.5;
self.y += playerDy / playerDistance * self.speed * 1.5;
}
}
// Keep within bounds
if (self.x < 0) {
self.x = 0;
}
if (self.x > 14000) {
self.x = 14000;
}
if (self.y < 0) {
self.y = 0;
}
if (self.y > 14000) {
self.y = 14000;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
var playerCell = null;
var foods = [];
var predators = [];
var aiCells = [];
var cellsEaten = 0;
// --- Start Screen UI ---
var startScreen = new Container();
var startBg = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5
});
startBg.scaleX = 10;
startBg.scaleY = 10;
startBg.alpha = 0.92;
startBg.x = 2048 / 2;
startBg.y = 2732 / 2;
startScreen.addChild(startBg);
var titleTxt = new Text2("¡Célula Survival!", {
size: 120,
fill: "#fff"
});
titleTxt.anchor.set(0.5, 0);
titleTxt.x = 2048 / 2;
titleTxt.y = 400;
startScreen.addChild(titleTxt);
var nameLabel = new Text2("Tu nombre:", {
size: 64,
fill: "#fff"
});
nameLabel.anchor.set(0.5, 0);
nameLabel.x = 2048 / 2;
nameLabel.y = 700;
startScreen.addChild(nameLabel);
// Simple text input using LK.gui (simulated, as LK does not have a native input, so we use a Text2 and tap to edit)
var playerName = "";
var nameInput = new Text2("Toca para escribir...", {
size: 72,
fill: 0xFFFFCC
});
nameInput.anchor.set(0.5, 0);
nameInput.x = 2048 / 2;
nameInput.y = 800;
startScreen.addChild(nameInput);
// Show a start button
var startBtn = new Text2("INICIAR", {
size: 100,
fill: 0x00FF99
});
startBtn.anchor.set(0.5, 0.5);
startBtn.x = 2048 / 2;
startBtn.y = 1100;
startBtn.interactive = true;
startBtn.buttonMode = true;
startScreen.addChild(startBtn);
var editingName = false;
nameInput.interactive = true;
nameInput.buttonMode = true;
nameInput.down = function (x, y, obj) {
editingName = true;
nameInput.setText(playerName + "|");
};
game.down = function (x, y, obj) {
// If editing name, simulate typing by adding a random letter (since we can't get real keyboard input)
if (editingName) {
// Simulate: tap = add random letter, long tap = backspace
if (playerName.length < 10) {
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var letter = letters[Math.floor(Math.random() * letters.length)];
playerName += letter;
}
nameInput.setText(playerName + "|");
// If tap on left side, treat as backspace
if (x < 2048 / 2 - 200 && playerName.length > 0) {
playerName = playerName.substring(0, playerName.length - 1);
nameInput.setText(playerName + "|");
}
// If tap on right side, finish editing
if (x > 2048 / 2 + 200) {
editingName = false;
nameInput.setText(playerName.length > 0 ? playerName : "Toca para escribir...");
}
return;
}
};
startBtn.down = function (x, y, obj) {
if (playerName.length === 0) {
playerName = "Tú";
nameInput.setText(playerName);
}
// Hide start screen and start the game
startScreen.visible = false;
startScreen.interactive = false;
startScreen.children.forEach(function (child) {
child.visible = false;
});
startGame();
};
game.addChild(startScreen);
// --- Main game UI (hidden until start) ---
var scoreTxt = new Text2('Size: 50', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Display for #1 (largest cell) score
var topScoreTxt = new Text2('', {
size: 48,
fill: 0xFFD700
});
topScoreTxt.anchor.set(0.5, 0);
topScoreTxt.y = 70; // Place below main score, avoid top 100px
LK.gui.top.addChild(topScoreTxt);
// Create a world container for all game objects (slither.io style)
var world = new Container();
game.addChild(world);
// --- Game start logic ---
function startGame() {
// Initialize player cell
playerCell = new PlayerCell();
playerCell.x = 14000 / 2;
playerCell.y = 14000 / 2;
// Assign a name to the player cell
var allNames = ["Nano", "Blob", "Zeta", "Mito", "Viru", "Giga", "Beta", "Toxi", "Rex", "Lumo", "Fago", "Proto", "Mega", "Pico", "Tera", "Vivo", "Cello", "Dino", "Mobi", "Rondo"];
playerCell.randomName = playerName && playerName.length > 0 ? playerName : allNames[Math.floor(Math.random() * allNames.length)];
world.addChild(playerCell);
}
// Generate initial food
function spawnFood() {
var food = new Food();
food.x = Math.random() * 14000;
food.y = Math.random() * 14000;
foods.push(food);
world.addChild(food);
}
;
// Generate initial predators
function spawnPredator() {
var predator = new Predator();
predator.x = Math.random() * 14000;
predator.y = Math.random() * 14000;
// Assign a random name to the predator
var allNames = ["Nano", "Blob", "Zeta", "Mito", "Viru", "Giga", "Beta", "Toxi", "Rex", "Lumo", "Fago", "Proto", "Mega", "Pico", "Tera", "Vivo", "Cello", "Dino", "Mobi", "Rondo"];
predator.randomName = allNames[Math.floor(Math.random() * allNames.length)];
predators.push(predator);
world.addChild(predator);
}
// Generate AI cells
function spawnAICell() {
var ai = new AICell();
ai.x = Math.random() * 14000;
ai.y = Math.random() * 14000;
// Assign random size: 50, 70, 90, 150, 300, or 1000
var possibleSizes = [50, 70, 90, 150, 300, 1000];
var sizeIdx = Math.floor(Math.random() * possibleSizes.length);
ai.size = possibleSizes[sizeIdx];
// Update scale to match new size
var scale = ai.size / 50;
if (ai.children && ai.children.length > 0) {
var cellGraphics = ai.children[0];
cellGraphics.scaleX = scale;
cellGraphics.scaleY = scale;
}
// Assign a random name to this AI cell
var aiNames = ["Nano", "Blob", "Zeta", "Mito", "Viru", "Giga", "Beta", "Toxi", "Rex", "Lumo", "Fago", "Proto", "Mega", "Pico", "Tera", "Vivo", "Cello", "Dino", "Mobi", "Rondo"];
ai.randomName = aiNames[Math.floor(Math.random() * aiNames.length)];
// Only some AI cells will hunt the player
// 40% of AI cells will hunt the player, others will ignore the player
ai.huntsPlayer = Math.random() < 0.4;
aiCells.push(ai);
world.addChild(ai);
}
// Spawn initial food, most near the player, some random
for (var i = 0; i < 80; i++) {
if (i < 60) {
// Near player: in a ring 300-900px from player
var angle = Math.random() * Math.PI * 2;
var dist = 300 + Math.random() * 600;
var fx = playerCell.x + Math.cos(angle) * dist;
var fy = playerCell.y + Math.sin(angle) * dist;
fx = Math.max(20, Math.min(fx, 14000 - 20));
fy = Math.max(20, Math.min(fy, 14000 - 20));
var food = new Food();
food.x = fx;
food.y = fy;
foods.push(food);
world.addChild(food);
} else {
spawnFood();
}
}
// Spawn initial predators
for (var i = 0; i < 5; i++) {
spawnPredator();
}
// Spawn initial AI cells
for (var i = 0; i < 60; i++) {
spawnAICell();
}
// Slither.io style swipe/drag controls
var dragging = false;
var dragTouchId = null;
var lastTouchX = null;
var lastTouchY = null;
var dragStartX = null;
var dragStartY = null;
var dragPlayerStartX = null;
var dragPlayerStartY = null;
game.down = function (x, y, obj) {
// Start dragging from anywhere except top left 100x100
if (!(x < 100 && y < 100)) {
dragging = true;
dragTouchId = obj && obj.event && obj.event.identifier !== undefined ? obj.event.identifier : null;
dragStartX = x;
dragStartY = y;
dragPlayerStartX = playerCell.x;
dragPlayerStartY = playerCell.y;
lastTouchX = x;
lastTouchY = y;
}
};
game.move = function (x, y, obj) {
if (dragging && (dragTouchId === null || obj && obj.event && obj.event.identifier === dragTouchId)) {
lastTouchX = x;
lastTouchY = y;
// Calculate drag vector relative to drag start
var dx = x - dragStartX;
var dy = y - dragStartY;
// Set a max drag distance for control sensitivity
var maxDrag = 400;
var dragLen = Math.sqrt(dx * dx + dy * dy);
if (dragLen > maxDrag) {
dx = dx * maxDrag / dragLen;
dy = dy * maxDrag / dragLen;
}
// Set the target position for the player cell based on drag
playerCell.targetX = dragPlayerStartX + dx * 8;
playerCell.targetY = dragPlayerStartY + dy * 8;
}
};
game.up = function (x, y, obj) {
if (dragging && (dragTouchId === null || obj && obj.event && obj.event.identifier === dragTouchId)) {
dragging = false;
dragTouchId = null;
lastTouchX = null;
lastTouchY = null;
dragStartX = null;
dragStartY = null;
dragPlayerStartX = null;
dragPlayerStartY = null;
}
};
game.update = function () {
if (!playerCell) {
return;
}
// Camera logic: center world on playerCell, clamp to map bounds (slither.io style)
var viewWidth = 2048;
var viewHeight = 2732;
var mapSize = 14000;
// Calculate camera target position to center player
var camTargetX = playerCell.x - viewWidth / 2;
var camTargetY = playerCell.y - viewHeight / 2;
// Clamp camera to map bounds
camTargetX = Math.max(0, Math.min(camTargetX, mapSize - viewWidth));
camTargetY = Math.max(0, Math.min(camTargetY, mapSize - viewHeight));
// Smooth camera movement (slither.io style)
if (typeof world.lastCamX === "undefined") world.lastCamX = camTargetX;
if (typeof world.lastCamY === "undefined") world.lastCamY = camTargetY;
world.lastCamX += (camTargetX - world.lastCamX) * 0.15;
world.lastCamY += (camTargetY - world.lastCamY) * 0.15;
// Move world container
world.x = -Math.round(world.lastCamX);
world.y = -Math.round(world.lastCamY);
// AI cells update and logic
for (var i = aiCells.length - 1; i >= 0; i--) {
var ai = aiCells[i];
if (!ai.alive) {
continue;
}
ai.update();
// AI eats food
for (var j = foods.length - 1; j >= 0; j--) {
var food = foods[j];
if (food.consumed) {
continue;
}
var dx = ai.x - food.x;
var dy = ai.y - food.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < ai.size / 2 + food.size / 2) {
food.consumed = true;
food.destroy();
foods.splice(j, 1);
ai.grow(5);
break;
}
}
// AI eats other AI (io style)
for (var k = aiCells.length - 1; k >= 0; k--) {
if (i === k) {
continue;
}
var other = aiCells[k];
if (!other.alive) {
continue;
}
var dx = ai.x - other.x;
var dy = ai.y - other.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < ai.size / 2 + other.size / 2) {
if (ai.size > other.size * 1.2) {
other.alive = false;
other.destroy();
ai.grow(other.size / 2);
aiCells.splice(k, 1);
if (k < i) {
i--;
} // Adjust index if needed
break;
}
}
}
// AI can eat player or be eaten by player
var dxp = ai.x - playerCell.x;
var dyp = ai.y - playerCell.y;
var distp = Math.sqrt(dxp * dxp + dyp * dyp);
if (distp < ai.size / 2 + playerCell.size / 2) {
if (ai.size > playerCell.size * 1.2) {
// Player is eaten by a larger AI cell
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
} else if (playerCell.size > ai.size * 1.2) {
// Player eats smaller AI cell
ai.alive = false;
ai.destroy();
aiCells.splice(i, 1);
playerCell.grow(ai.size / 2);
cellsEaten++;
LK.getSound('eat').play();
scoreTxt.setText('Size: ' + Math.floor(playerCell.size) + ' | Eaten: ' + cellsEaten);
break;
}
}
}
// Check food collisions for player
for (var i = foods.length - 1; i >= 0; i--) {
var food = foods[i];
if (food.consumed) {
continue;
}
var dx = playerCell.x - food.x;
var dy = playerCell.y - food.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < playerCell.size / 2 + food.size / 2) {
// Consume food
food.consumed = true;
food.destroy();
foods.splice(i, 1);
playerCell.grow(5);
// Do not increment cellsEaten for food
LK.getSound('eat').play();
// Update score display
scoreTxt.setText('Size: ' + Math.floor(playerCell.size));
}
}
// Check predator collisions
for (var i = 0; i < predators.length; i++) {
var predator = predators[i];
var dx = playerCell.x - predator.x;
var dy = playerCell.y - predator.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < playerCell.size / 2 + predator.size / 2) {
if (predator.size > playerCell.size) {
// Game over - eaten by predator
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
} else if (playerCell.size > predator.size * 1.2) {
// Player can eat predator
predator.destroy();
predators.splice(i, 1);
playerCell.grow(20);
cellsEaten++;
LK.getSound('eat').play();
scoreTxt.setText('Size: ' + Math.floor(playerCell.size) + ' | Eaten: ' + cellsEaten);
// Spawn new predator
spawnPredator();
i--; // Adjust index after removal
}
}
}
// Spawn new food periodically, but always near the player
if (LK.ticks % 120 == 0 && foods.length < 65) {
// Spawn food in a ring 300-700px from player, random angle
var angle = Math.random() * Math.PI * 2;
var dist = 300 + Math.random() * 400;
var fx = playerCell.x + Math.cos(angle) * dist;
var fy = playerCell.y + Math.sin(angle) * dist;
// Clamp to map bounds
fx = Math.max(20, Math.min(fx, 14000 - 20));
fy = Math.max(20, Math.min(fy, 14000 - 20));
var food = new Food();
food.x = fx;
food.y = fy;
foods.push(food);
world.addChild(food);
}
// Add more predators as player grows
if (LK.ticks % 600 == 0 && predators.length < 8) {
spawnPredator();
}
// Add more AI cells as the game progresses
if (LK.ticks % 300 == 0 && aiCells.length < 12) {
spawnAICell();
}
// Win condition removed: score is now infinite
// Find the largest cell (player, aiCells, predators)
var topCell = playerCell;
var topCellType = "Tú";
var topCellSize = playerCell ? playerCell.size : 0;
var topCellName = null;
// Check AI cells
for (var i = 0; i < aiCells.length; i++) {
if (aiCells[i].alive && aiCells[i].size > topCellSize) {
topCell = aiCells[i];
topCellType = "Bot";
topCellSize = aiCells[i].size;
topCellName = aiCells[i].randomName;
}
}
// Check predators
for (var i = 0; i < predators.length; i++) {
if (predators[i].size > topCellSize) {
topCell = predators[i];
topCellType = "Depredador";
topCellSize = predators[i].size;
topCellName = null;
}
}
// Show #1 score
if (topCell === playerCell) {
topScoreTxt.setText("#1: Tú (" + Math.floor(topCellSize) + ")");
} else if (topCellType === "Bot" && topCellName) {
topScoreTxt.setText("#1: " + topCellName + " (" + Math.floor(topCellSize) + ")");
} else {
topScoreTxt.setText("#1: " + topCellType + " (" + Math.floor(topCellSize) + ")");
}
};
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Cell Growth" and with the description "Control a growing cell that consumes food particles to increase in size while avoiding larger predators in this survival game.". No text on banner!
Alimento. In-Game asset. 2d. High contrast. No shadows
Celula. In-Game asset. 2d. High contrast. No shadows
Celula de rojos. In-Game asset. 2d. High contrast. No shadows
Pavo pierna. In-Game asset. 2d. High contrast. No shadows
Papa alimento. In-Game asset. 2d. High contrast. No shadows