/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var AllyAnt = Container.expand(function (weaponType) { var self = Container.call(this); var antGraphics = self.attachAsset('ant', { anchorX: 0.5, anchorY: 0.5 }); // Tint ally ants slightly different color antGraphics.tint = 0x00CCFF; self.health = 80; self.maxHealth = 80; self.speed = 2; self.weapon = weaponType; self.attackDamage = weaponType === 'sword' ? 40 : weaponType === 'axe' ? 35 : 25; self.lastAttackTime = 0; self.targetEnemy = null; self.isMoving = false; self.targetX = self.x; self.targetY = self.y; // Create weapon visual var weaponGraphics = self.attachAsset(weaponType, { anchorX: 0.5, anchorY: 0.5, x: 20, y: -10 }); self.takeDamage = function (damage) { self.health = Math.max(0, self.health - damage); LK.effects.flashObject(self, 0xFF0000, 300); }; self.findNearestEnemy = function () { var nearestEnemy = null; var nearestDistance = Infinity; // Check spiders for (var i = 0; i < strongSpiders.length; i++) { var spider = strongSpiders[i]; var distance = Math.sqrt(Math.pow(self.x - spider.x, 2) + Math.pow(self.y - spider.y, 2)); if (distance < nearestDistance) { nearestDistance = distance; nearestEnemy = spider; } } // Check beetles for (var i = 0; i < strongBeetles.length; i++) { var beetle = strongBeetles[i]; var distance = Math.sqrt(Math.pow(self.x - beetle.x, 2) + Math.pow(self.y - beetle.y, 2)); if (distance < nearestDistance) { nearestDistance = distance; nearestEnemy = beetle; } } return nearestEnemy; }; self.update = function () { // Find and attack nearest enemy self.targetEnemy = self.findNearestEnemy(); if (self.targetEnemy) { var dx = self.targetEnemy.x - self.x; var dy = self.targetEnemy.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 60) { // Move towards enemy self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } else { // Attack enemy if (LK.ticks - self.lastAttackTime > 60) { self.targetEnemy.health -= self.attackDamage; LK.effects.flashObject(self.targetEnemy, 0xFF0000, 200); self.lastAttackTime = LK.ticks; } } } // Keep within bounds if (self.x < 50) self.x = 50; if (self.x > 1998) self.x = 1998; if (self.y < 50) self.y = 50; if (self.y > 2682) self.y = 2682; }; return self; }); var Ant = Container.expand(function () { var self = Container.call(this); var antGraphics = self.attachAsset('ant', { anchorX: 0.5, anchorY: 0.5 }); self.health = 100; self.maxHealth = 100; self.speed = 3; self.isMoving = false; self.targetX = 0; self.targetY = 0; self.weapon = null; self.attackDamage = 10; self.moveTo = function (x, y) { self.targetX = x; self.targetY = y; self.isMoving = true; }; self.takeDamage = function (damage) { self.health = Math.max(0, self.health - damage); LK.effects.flashObject(self, 0xFF0000, 300); }; self.equipWeapon = function (weaponType) { self.weapon = weaponType; if (weaponType === 'sword') self.attackDamage = 25;else if (weaponType === 'axe') self.attackDamage = 20;else self.attackDamage = 10; }; self.update = function () { if (self.isMoving) { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > self.speed) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } else { self.x = self.targetX; self.y = self.targetY; self.isMoving = false; } } }; return self; }); var Beetle = Container.expand(function () { var self = Container.call(this); var beetleGraphics = self.attachAsset('beetle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0.8; self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; self.attackDamage = 20; self.health = 50; self.lastAttackTime = 0; self.update = function () { self.changeDirectionTimer++; if (self.changeDirectionTimer > 150) { self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; } self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; // Keep within bounds if (self.x < 50) self.x = 50; if (self.x > 1998) self.x = 1998; if (self.y < 50) self.y = 50; if (self.y > 2682) self.y = 2682; }; return self; }); var Predator = Container.expand(function () { var self = Container.call(this); var predatorGraphics = self.attachAsset('predator', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1; self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; self.update = function () { self.changeDirectionTimer++; if (self.changeDirectionTimer > 120) { self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; } self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; // Keep predator within game bounds if (self.x < 50) self.x = 50; if (self.x > 1998) self.x = 1998; if (self.y < 50) self.y = 50; if (self.y > 2682) self.y = 2682; }; return self; }); var Resource = Container.expand(function (type) { var self = Container.call(this); self.type = type; self.value = 1; var assetName = 'foodCrumb'; if (type === 'twig') assetName = 'twig';else if (type === 'leaf') assetName = 'leaf';else if (type === 'water') assetName = 'waterDrop'; var resourceGraphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); if (type === 'twig') self.value = 2;else if (type === 'leaf') self.value = 3;else if (type === 'water') self.value = 5; return self; }); var Spider = Container.expand(function () { var self = Container.call(this); var spiderGraphics = self.attachAsset('spider', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1.5; self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; self.attackDamage = 15; self.health = 30; self.lastAttackTime = 0; self.update = function () { self.changeDirectionTimer++; if (self.changeDirectionTimer > 90) { self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; } self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; // Keep within bounds if (self.x < 50) self.x = 50; if (self.x > 1998) self.x = 1998; if (self.y < 50) self.y = 50; if (self.y > 2682) self.y = 2682; }; return self; }); var StrongBeetle = Container.expand(function () { var self = Container.call(this); var beetleGraphics = self.attachAsset('beetle', { anchorX: 0.5, anchorY: 0.5 }); // Make stronger beetles larger and darker beetleGraphics.scaleX = 1.5; beetleGraphics.scaleY = 1.5; beetleGraphics.tint = 0x330000; self.speed = 1.5; self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; self.attackDamage = 40; self.health = 150; self.maxHealth = 150; self.lastAttackTime = 0; self.update = function () { // Aggressive targeting towards player and allies var nearestTarget = null; var nearestDistance = Infinity; // Check distance to player ant var distanceToPlayer = Math.sqrt(Math.pow(self.x - ant.x, 2) + Math.pow(self.y - ant.y, 2)); if (distanceToPlayer < 400) { nearestTarget = ant; nearestDistance = distanceToPlayer; } // Check distance to ally ants for (var i = 0; i < allyAnts.length; i++) { var ally = allyAnts[i]; var distance = Math.sqrt(Math.pow(self.x - ally.x, 2) + Math.pow(self.y - ally.y, 2)); if (distance < nearestDistance) { nearestDistance = distance; nearestTarget = ally; } } if (nearestTarget && nearestDistance < 350) { // Move towards target var dx = nearestTarget.x - self.x; var dy = nearestTarget.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } else { // Random movement self.changeDirectionTimer++; if (self.changeDirectionTimer > 80) { self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; } self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; } // Keep within bounds if (self.x < 50) self.x = 50; if (self.x > 1998) self.x = 1998; if (self.y < 50) self.y = 50; if (self.y > 2682) self.y = 2682; }; return self; }); var StrongSpider = Container.expand(function () { var self = Container.call(this); var spiderGraphics = self.attachAsset('spider', { anchorX: 0.5, anchorY: 0.5 }); // Make stronger spiders larger and darker spiderGraphics.scaleX = 1.5; spiderGraphics.scaleY = 1.5; spiderGraphics.tint = 0x660000; self.speed = 2; self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; self.attackDamage = 35; self.health = 120; self.maxHealth = 120; self.lastAttackTime = 0; self.targetPlayer = false; self.update = function () { // Aggressive targeting towards player and allies var nearestTarget = null; var nearestDistance = Infinity; // Check distance to player ant var distanceToPlayer = Math.sqrt(Math.pow(self.x - ant.x, 2) + Math.pow(self.y - ant.y, 2)); if (distanceToPlayer < 400) { nearestTarget = ant; nearestDistance = distanceToPlayer; } // Check distance to ally ants for (var i = 0; i < allyAnts.length; i++) { var ally = allyAnts[i]; var distance = Math.sqrt(Math.pow(self.x - ally.x, 2) + Math.pow(self.y - ally.y, 2)); if (distance < nearestDistance) { nearestDistance = distance; nearestTarget = ally; } } if (nearestTarget && nearestDistance < 300) { // Move towards target var dx = nearestTarget.x - self.x; var dy = nearestTarget.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } else { // Random movement self.changeDirectionTimer++; if (self.changeDirectionTimer > 60) { self.direction = Math.random() * Math.PI * 2; self.changeDirectionTimer = 0; } self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * self.speed; } // Keep within bounds if (self.x < 50) self.x = 50; if (self.x > 1998) self.x = 1998; if (self.y < 50) self.y = 50; if (self.y > 2682) self.y = 2682; }; return self; }); var Weapon = Container.expand(function (type) { var self = Container.call(this); self.type = type; var weaponGraphics = self.attachAsset(type, { anchorX: 0.5, anchorY: 0.5 }); return self; }); var WeatherEvent = Container.expand(function (type) { var self = Container.call(this); self.type = type; self.damage = 0; if (type === 'acidRain') { var rainGraphics = self.attachAsset('acidRain', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.damage = 10; } else if (type === 'stone') { var stoneGraphics = self.attachAsset('fallingStone', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 6; self.damage = 25; } else if (type === 'lightning') { var lightningGraphics = self.attachAsset('lightning', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0; self.damage = 30; self.lifeTime = 30; } self.update = function () { if (self.type !== 'lightning') { self.y += self.speed; } else { self.lifeTime--; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x90EE90 }); /**** * Game Code ****/ // Weather assets // Weapon assets // Health bar assets // New insect enemies // Anthill interior var ant; var anthill; var resources = []; var predators = []; var spiders = []; var beetles = []; var weatherEvents = []; var weapons = []; var colonyStrength = 0; var maxColonyStrength = 100; var gamePhase = 'selection'; // 'selection', 'exploration', 'defense', 'anthill' var isInsideAnthill = false; var defensePhaseTriggered = false; var allyAnts = []; var strongSpiders = []; var strongBeetles = []; var defenseWaveTimer = 0; var defenseWavesSpawned = 0; var maxDefenseWaves = 3; var craftingTable; var anthillInterior; var difficulty = 'normal'; // 'normal' or 'hard' var difficultySelected = false; var normalButton; var hardButton; var difficultyTitle; // UI Elements var healthBarBg; var healthBar; var strengthText; var resourceCountText; var weaponText; var collectedResources = 0; var weatherTimer = 0; var currentWeather = 'clear'; // Initialize anthill (hidden initially) anthill = game.addChild(LK.getAsset('anthill', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 2400 })); anthill.visible = false; // Initialize ant (hidden initially) ant = game.addChild(new Ant()); ant.x = anthill.x; ant.y = anthill.y - 100; ant.visible = false; // Initialize difficulty selection UI difficultyTitle = new Text2('Selecciona Dificultad', { size: 80, fill: 0xFFFFFF }); difficultyTitle.anchor.set(0.5, 0.5); difficultyTitle.x = 1024; difficultyTitle.y = 800; game.addChild(difficultyTitle); normalButton = LK.getAsset('healthBackground', { anchorX: 0.5, anchorY: 0.5, x: 724, y: 1200, scaleX: 2, scaleY: 3 }); game.addChild(normalButton); var normalText = new Text2('NORMAL', { size: 60, fill: 0x00FF00 }); normalText.anchor.set(0.5, 0.5); normalText.x = 724; normalText.y = 1200; game.addChild(normalText); hardButton = LK.getAsset('healthBackground', { anchorX: 0.5, anchorY: 0.5, x: 1324, y: 1200, scaleX: 2, scaleY: 3 }); game.addChild(hardButton); var hardText = new Text2('DIFICIL', { size: 60, fill: 0xFF0000 }); hardText.anchor.set(0.5, 0.5); hardText.x = 1324; hardText.y = 1200; game.addChild(hardText); // Initialize UI (hidden initially) healthBarBg = LK.gui.top.addChild(LK.getAsset('healthBackground', { x: 200, y: 100 })); healthBarBg.visible = false; healthBar = LK.gui.top.addChild(LK.getAsset('healthBar', { x: 200, y: 100 })); healthBar.visible = false; strengthText = new Text2('Colony Strength: 0/100', { size: 40, fill: 0xFFFFFF }); strengthText.anchor.set(0, 0); strengthText.x = 50; strengthText.y = 150; strengthText.visible = false; LK.gui.top.addChild(strengthText); resourceCountText = new Text2('Resources: 0', { size: 40, fill: 0xFFFFFF }); resourceCountText.anchor.set(0, 0); resourceCountText.x = 50; resourceCountText.y = 200; resourceCountText.visible = false; LK.gui.top.addChild(resourceCountText); weaponText = new Text2('Weapon: None', { size: 40, fill: 0xFFFFFF }); weaponText.anchor.set(0, 0); weaponText.x = 50; weaponText.y = 250; weaponText.visible = false; LK.gui.top.addChild(weaponText); // Spawn initial resources function spawnResource() { var types = ['food', 'twig', 'leaf', 'water']; var randomType = types[Math.floor(Math.random() * types.length)]; var resource = game.addChild(new Resource(randomType)); resource.x = Math.random() * 1800 + 124; resource.y = Math.random() * 2000 + 200; // Avoid spawning too close to anthill var distanceToAnthill = Math.sqrt(Math.pow(resource.x - anthill.x, 2) + Math.pow(resource.y - anthill.y, 2)); if (distanceToAnthill < 300) { resource.x = Math.random() * 1000 + 100; resource.y = Math.random() * 1500 + 200; } resources.push(resource); } // Spawn initial predators function spawnPredator() { var predator = game.addChild(new Predator()); predator.x = Math.random() * 1800 + 124; predator.y = Math.random() * 1800 + 200; predators.push(predator); } function spawnSpider() { var spider = game.addChild(new Spider()); spider.x = Math.random() * 1800 + 124; spider.y = Math.random() * 1800 + 200; spiders.push(spider); } function spawnBeetle() { var beetle = game.addChild(new Beetle()); beetle.x = Math.random() * 1800 + 124; beetle.y = Math.random() * 1800 + 200; beetles.push(beetle); } function spawnWeatherEvent() { var types = ['acidRain', 'stone', 'lightning']; var randomType = types[Math.floor(Math.random() * types.length)]; var weather = game.addChild(new WeatherEvent(randomType)); if (randomType === 'lightning') { weather.x = Math.random() * 1800 + 124; weather.y = 100; LK.getSound('lightning').play(); } else { weather.x = Math.random() * 1800 + 124; weather.y = 0; } weatherEvents.push(weather); } function setupAnthillInterior() { anthillInterior = game.addChild(LK.getAsset('anthillInterior', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); anthillInterior.visible = false; craftingTable = game.addChild(LK.getAsset('craftingTable', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1200 })); craftingTable.visible = false; } // Initialize world for (var i = 0; i < 15; i++) { spawnResource(); } for (var i = 0; i < 3; i++) { spawnPredator(); } for (var i = 0; i < 2; i++) { spawnSpider(); } for (var i = 0; i < 2; i++) { spawnBeetle(); } setupAnthillInterior(); function startGame() { gamePhase = 'exploration'; difficultySelected = true; // Hide difficulty selection UI difficultyTitle.destroy(); normalButton.destroy(); hardButton.destroy(); // Show game UI healthBarBg.visible = true; healthBar.visible = true; strengthText.visible = true; resourceCountText.visible = true; weaponText.visible = true; anthill.visible = true; ant.visible = true; // Apply difficulty adjustments if (difficulty === 'hard') { // Hard mode adjustments for (var i = 0; i < 3; i++) { spawnSpider(); } for (var i = 0; i < 3; i++) { spawnBeetle(); } // Reduce ant health in hard mode ant.health = 70; ant.maxHealth = 70; } } // Resource spawn timer var resourceSpawnTimer = 0; game.down = function (x, y, obj) { if (gamePhase === 'selection') { // Check if clicking on normal button var distanceToNormal = Math.sqrt(Math.pow(x - normalButton.x, 2) + Math.pow(y - normalButton.y, 2)); if (distanceToNormal < 150) { difficulty = 'normal'; startGame(); } // Check if clicking on hard button var distanceToHard = Math.sqrt(Math.pow(x - hardButton.x, 2) + Math.pow(y - hardButton.y, 2)); if (distanceToHard < 150) { difficulty = 'hard'; startGame(); } } else if (ant.health > 0) { if (isInsideAnthill) { // Check if clicking on crafting table var distanceToCrafting = Math.sqrt(Math.pow(x - craftingTable.x, 2) + Math.pow(y - craftingTable.y, 2)); if (distanceToCrafting < 100 && collectedResources >= 5) { // Craft weapon var weaponTypes = ['axe', 'sword', 'shield']; var randomWeapon = weaponTypes[Math.floor(Math.random() * weaponTypes.length)]; ant.equipWeapon(randomWeapon); collectedResources -= 5; LK.getSound('craft').play(); } else { ant.moveTo(x, y); } } else { // Check if clicking on anthill to enter var distanceToAnthill = Math.sqrt(Math.pow(x - anthill.x, 2) + Math.pow(y - anthill.y, 2)); if (distanceToAnthill < 100) { isInsideAnthill = true; ant.x = 1024; ant.y = 1500; anthillInterior.visible = true; craftingTable.visible = true; // Hide exterior elements anthill.visible = false; for (var i = 0; i < resources.length; i++) { resources[i].visible = false; } for (var i = 0; i < predators.length; i++) { predators[i].visible = false; } for (var i = 0; i < spiders.length; i++) { spiders[i].visible = false; } for (var i = 0; i < beetles.length; i++) { beetles[i].visible = false; } } else { ant.moveTo(x, y); } } } }; game.update = function () { if (gamePhase === 'selection') { // Don't update game logic during difficulty selection return; } // Update health bar var healthPercent = ant.health / ant.maxHealth; healthBar.scaleX = healthPercent; // Update UI text strengthText.setText('Colony Strength: ' + colonyStrength + '/' + maxColonyStrength); resourceCountText.setText('Resources: ' + collectedResources); weaponText.setText('Weapon: ' + (ant.weapon || 'None')); if (!isInsideAnthill) { // Weather system weatherTimer++; var weatherSpawnRate = difficulty === 'hard' ? 250 : 400; var weatherChance = difficulty === 'hard' ? 0.5 : 0.3; if (weatherTimer > weatherSpawnRate) { if (Math.random() < weatherChance) { spawnWeatherEvent(); } weatherTimer = 0; } // Update weather events for (var i = weatherEvents.length - 1; i >= 0; i--) { var weather = weatherEvents[i]; if (weather.type === 'lightning' && weather.lifeTime <= 0) { weather.destroy(); weatherEvents.splice(i, 1); } else if (weather.y > 2800) { weather.destroy(); weatherEvents.splice(i, 1); } else if (ant.intersects(weather)) { ant.takeDamage(weather.damage); LK.getSound('impact').play(); weather.destroy(); weatherEvents.splice(i, 1); } } // Spawn new resources periodically resourceSpawnTimer++; if (resourceSpawnTimer > 300 && resources.length < 20) { spawnResource(); resourceSpawnTimer = 0; } // Check for resource collection for (var i = resources.length - 1; i >= 0; i--) { var resource = resources[i]; if (ant.intersects(resource) && resource.visible) { LK.getSound('collect').play(); colonyStrength = Math.min(maxColonyStrength, colonyStrength + resource.value); collectedResources++; LK.setScore(LK.getScore() + resource.value * 10); // Flash effect LK.effects.flashObject(ant, 0x00FF00, 300); resource.destroy(); resources.splice(i, 1); } } // Check for predator collisions for (var i = 0; i < predators.length; i++) { var predator = predators[i]; if (ant.intersects(predator) && predator.visible) { LK.getSound('danger').play(); ant.takeDamage(15); // Push ant away from predator var dx = ant.x - predator.x; var dy = ant.y - predator.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { ant.x += dx / distance * 100; ant.y += dy / distance * 100; } } } // Check for spider collisions and combat for (var i = spiders.length - 1; i >= 0; i--) { var spider = spiders[i]; var distanceToSpider = Math.sqrt(Math.pow(ant.x - spider.x, 2) + Math.pow(ant.y - spider.y, 2)); // Attack with weapon at distance if (ant.weapon && distanceToSpider < 120 && spider.visible) { // Attack spider with weapon at range spider.health -= ant.attackDamage; LK.effects.flashObject(spider, 0xFF0000, 200); if (spider.health <= 0) { // Spider defeated LK.effects.flashObject(ant, 0x00FF00, 300); LK.setScore(LK.getScore() + 50); spider.destroy(); spiders.splice(i, 1); continue; } } // Only take damage if actually touching else if (ant.intersects(spider) && spider.visible) { LK.getSound('danger').play(); ant.takeDamage(spider.attackDamage); // Push ant away var dx = ant.x - spider.x; var dy = ant.y - spider.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { ant.x += dx / distance * 80; ant.y += dy / distance * 80; } } } // Check for beetle collisions and combat for (var i = beetles.length - 1; i >= 0; i--) { var beetle = beetles[i]; var distanceToBeetle = Math.sqrt(Math.pow(ant.x - beetle.x, 2) + Math.pow(ant.y - beetle.y, 2)); // Attack with weapon at distance if (ant.weapon && distanceToBeetle < 120 && beetle.visible) { // Attack beetle with weapon at range beetle.health -= ant.attackDamage; LK.effects.flashObject(beetle, 0xFF0000, 200); if (beetle.health <= 0) { // Beetle defeated LK.effects.flashObject(ant, 0x00FF00, 300); LK.setScore(LK.getScore() + 75); beetle.destroy(); beetles.splice(i, 1); continue; } } // Only take damage if actually touching else if (ant.intersects(beetle) && beetle.visible) { LK.getSound('danger').play(); ant.takeDamage(beetle.attackDamage); // Push ant away var dx = ant.x - beetle.x; var dy = ant.y - beetle.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { ant.x += dx / distance * 60; ant.y += dy / distance * 60; } } } // Check if ant is at anthill (health restoration) var distanceToAnthill = Math.sqrt(Math.pow(ant.x - anthill.x, 2) + Math.pow(ant.y - anthill.y, 2)); if (distanceToAnthill < 100 && anthill.visible) { // Restore some health when at anthill ant.health = Math.min(ant.maxHealth, ant.health + 0.5); } } else { // Inside anthill logic // Exit anthill if ant moves to bottom if (ant.y > 2000) { isInsideAnthill = false; ant.x = anthill.x; ant.y = anthill.y - 100; anthillInterior.visible = false; craftingTable.visible = false; // Show exterior elements anthill.visible = true; for (var i = 0; i < resources.length; i++) { resources[i].visible = true; } for (var i = 0; i < predators.length; i++) { predators[i].visible = true; } for (var i = 0; i < spiders.length; i++) { spiders[i].visible = true; } for (var i = 0; i < beetles.length; i++) { beetles[i].visible = true; } } } // Game over conditions if (ant.health <= 0) { LK.effects.flashScreen(0xFF0000, 1000); LK.showGameOver(); } // Defense phase trigger at halfway point if (colonyStrength >= maxColonyStrength / 2 && !defensePhaseTriggered && gamePhase === 'exploration') { defensePhaseTriggered = true; gamePhase = 'defense'; // Spawn ally ants with advanced weapons var weapons = ['sword', 'axe', 'shield']; for (var i = 0; i < 3; i++) { var allyWeapon = weapons[i % weapons.length]; var ally = game.addChild(new AllyAnt(allyWeapon)); ally.x = anthill.x + (Math.random() - 0.5) * 200; ally.y = anthill.y + (Math.random() - 0.5) * 200; allyAnts.push(ally); } // Show defense message LK.effects.flashScreen(0x00FF00, 1000); // Start spawning strong enemies defenseWaveTimer = 0; defenseWavesSpawned = 0; } // Defense phase logic if (gamePhase === 'defense') { defenseWaveTimer++; // Spawn waves of strong enemies if (defenseWaveTimer > 600 && defenseWavesSpawned < maxDefenseWaves) { // Every 10 seconds // Spawn strong spiders for (var i = 0; i < 2; i++) { var strongSpider = game.addChild(new StrongSpider()); strongSpider.x = Math.random() * 1800 + 124; strongSpider.y = Math.random() * 1800 + 200; strongSpiders.push(strongSpider); } // Spawn strong beetles for (var i = 0; i < 2; i++) { var strongBeetle = game.addChild(new StrongBeetle()); strongBeetle.x = Math.random() * 1800 + 124; strongBeetle.y = Math.random() * 1800 + 200; strongBeetles.push(strongBeetle); } defenseWavesSpawned++; defenseWaveTimer = 0; LK.getSound('danger').play(); } // Check if defense is complete (all strong enemies defeated) if (defenseWavesSpawned >= maxDefenseWaves && strongSpiders.length === 0 && strongBeetles.length === 0) { gamePhase = 'exploration'; // Bonus rewards for completing defense colonyStrength += 20; LK.effects.flashScreen(0x00FF00, 1500); } } // Strong spider combat and cleanup for (var i = strongSpiders.length - 1; i >= 0; i--) { var strongSpider = strongSpiders[i]; if (strongSpider.health <= 0) { LK.effects.flashObject(ant, 0x00FF00, 300); LK.setScore(LK.getScore() + 200); strongSpider.destroy(); strongSpiders.splice(i, 1); continue; } // Combat with player var distanceToStrongSpider = Math.sqrt(Math.pow(ant.x - strongSpider.x, 2) + Math.pow(ant.y - strongSpider.y, 2)); // Attack with weapon at distance if (ant.weapon && distanceToStrongSpider < 140 && strongSpider.visible && LK.ticks % 30 === 0) { strongSpider.health -= ant.attackDamage; LK.effects.flashObject(strongSpider, 0xFF0000, 200); } // Only take damage if actually touching if (ant.intersects(strongSpider) && strongSpider.visible && LK.ticks % 45 === 0) { LK.getSound('danger').play(); ant.takeDamage(strongSpider.attackDamage); } // Combat with allies for (var j = 0; j < allyAnts.length; j++) { var ally = allyAnts[j]; if (ally.intersects(strongSpider) && LK.ticks % 40 === 0) { ally.takeDamage(strongSpider.attackDamage); if (ally.health <= 0) { ally.destroy(); allyAnts.splice(j, 1); break; } } } } // Strong beetle combat and cleanup for (var i = strongBeetles.length - 1; i >= 0; i--) { var strongBeetle = strongBeetles[i]; if (strongBeetle.health <= 0) { LK.effects.flashObject(ant, 0x00FF00, 300); LK.setScore(LK.getScore() + 250); strongBeetle.destroy(); strongBeetles.splice(i, 1); continue; } // Combat with player var distanceToStrongBeetle = Math.sqrt(Math.pow(ant.x - strongBeetle.x, 2) + Math.pow(ant.y - strongBeetle.y, 2)); // Attack with weapon at distance if (ant.weapon && distanceToStrongBeetle < 140 && strongBeetle.visible && LK.ticks % 35 === 0) { strongBeetle.health -= ant.attackDamage; LK.effects.flashObject(strongBeetle, 0xFF0000, 200); } // Only take damage if actually touching if (ant.intersects(strongBeetle) && strongBeetle.visible && LK.ticks % 50 === 0) { LK.getSound('danger').play(); ant.takeDamage(strongBeetle.attackDamage); } // Combat with allies for (var j = 0; j < allyAnts.length; j++) { var ally = allyAnts[j]; if (ally.intersects(strongBeetle) && LK.ticks % 45 === 0) { ally.takeDamage(strongBeetle.attackDamage); if (ally.health <= 0) { ally.destroy(); allyAnts.splice(j, 1); break; } } } } // Win condition if (colonyStrength >= maxColonyStrength) { LK.showYouWin(); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var AllyAnt = Container.expand(function (weaponType) {
var self = Container.call(this);
var antGraphics = self.attachAsset('ant', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint ally ants slightly different color
antGraphics.tint = 0x00CCFF;
self.health = 80;
self.maxHealth = 80;
self.speed = 2;
self.weapon = weaponType;
self.attackDamage = weaponType === 'sword' ? 40 : weaponType === 'axe' ? 35 : 25;
self.lastAttackTime = 0;
self.targetEnemy = null;
self.isMoving = false;
self.targetX = self.x;
self.targetY = self.y;
// Create weapon visual
var weaponGraphics = self.attachAsset(weaponType, {
anchorX: 0.5,
anchorY: 0.5,
x: 20,
y: -10
});
self.takeDamage = function (damage) {
self.health = Math.max(0, self.health - damage);
LK.effects.flashObject(self, 0xFF0000, 300);
};
self.findNearestEnemy = function () {
var nearestEnemy = null;
var nearestDistance = Infinity;
// Check spiders
for (var i = 0; i < strongSpiders.length; i++) {
var spider = strongSpiders[i];
var distance = Math.sqrt(Math.pow(self.x - spider.x, 2) + Math.pow(self.y - spider.y, 2));
if (distance < nearestDistance) {
nearestDistance = distance;
nearestEnemy = spider;
}
}
// Check beetles
for (var i = 0; i < strongBeetles.length; i++) {
var beetle = strongBeetles[i];
var distance = Math.sqrt(Math.pow(self.x - beetle.x, 2) + Math.pow(self.y - beetle.y, 2));
if (distance < nearestDistance) {
nearestDistance = distance;
nearestEnemy = beetle;
}
}
return nearestEnemy;
};
self.update = function () {
// Find and attack nearest enemy
self.targetEnemy = self.findNearestEnemy();
if (self.targetEnemy) {
var dx = self.targetEnemy.x - self.x;
var dy = self.targetEnemy.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 60) {
// Move towards enemy
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
// Attack enemy
if (LK.ticks - self.lastAttackTime > 60) {
self.targetEnemy.health -= self.attackDamage;
LK.effects.flashObject(self.targetEnemy, 0xFF0000, 200);
self.lastAttackTime = LK.ticks;
}
}
}
// Keep within bounds
if (self.x < 50) self.x = 50;
if (self.x > 1998) self.x = 1998;
if (self.y < 50) self.y = 50;
if (self.y > 2682) self.y = 2682;
};
return self;
});
var Ant = Container.expand(function () {
var self = Container.call(this);
var antGraphics = self.attachAsset('ant', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.speed = 3;
self.isMoving = false;
self.targetX = 0;
self.targetY = 0;
self.weapon = null;
self.attackDamage = 10;
self.moveTo = function (x, y) {
self.targetX = x;
self.targetY = y;
self.isMoving = true;
};
self.takeDamage = function (damage) {
self.health = Math.max(0, self.health - damage);
LK.effects.flashObject(self, 0xFF0000, 300);
};
self.equipWeapon = function (weaponType) {
self.weapon = weaponType;
if (weaponType === 'sword') self.attackDamage = 25;else if (weaponType === 'axe') self.attackDamage = 20;else self.attackDamage = 10;
};
self.update = function () {
if (self.isMoving) {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > self.speed) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
self.x = self.targetX;
self.y = self.targetY;
self.isMoving = false;
}
}
};
return self;
});
var Beetle = Container.expand(function () {
var self = Container.call(this);
var beetleGraphics = self.attachAsset('beetle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0.8;
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.attackDamage = 20;
self.health = 50;
self.lastAttackTime = 0;
self.update = function () {
self.changeDirectionTimer++;
if (self.changeDirectionTimer > 150) {
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
}
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Keep within bounds
if (self.x < 50) self.x = 50;
if (self.x > 1998) self.x = 1998;
if (self.y < 50) self.y = 50;
if (self.y > 2682) self.y = 2682;
};
return self;
});
var Predator = Container.expand(function () {
var self = Container.call(this);
var predatorGraphics = self.attachAsset('predator', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1;
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.update = function () {
self.changeDirectionTimer++;
if (self.changeDirectionTimer > 120) {
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
}
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Keep predator within game bounds
if (self.x < 50) self.x = 50;
if (self.x > 1998) self.x = 1998;
if (self.y < 50) self.y = 50;
if (self.y > 2682) self.y = 2682;
};
return self;
});
var Resource = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.value = 1;
var assetName = 'foodCrumb';
if (type === 'twig') assetName = 'twig';else if (type === 'leaf') assetName = 'leaf';else if (type === 'water') assetName = 'waterDrop';
var resourceGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
if (type === 'twig') self.value = 2;else if (type === 'leaf') self.value = 3;else if (type === 'water') self.value = 5;
return self;
});
var Spider = Container.expand(function () {
var self = Container.call(this);
var spiderGraphics = self.attachAsset('spider', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1.5;
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.attackDamage = 15;
self.health = 30;
self.lastAttackTime = 0;
self.update = function () {
self.changeDirectionTimer++;
if (self.changeDirectionTimer > 90) {
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
}
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Keep within bounds
if (self.x < 50) self.x = 50;
if (self.x > 1998) self.x = 1998;
if (self.y < 50) self.y = 50;
if (self.y > 2682) self.y = 2682;
};
return self;
});
var StrongBeetle = Container.expand(function () {
var self = Container.call(this);
var beetleGraphics = self.attachAsset('beetle', {
anchorX: 0.5,
anchorY: 0.5
});
// Make stronger beetles larger and darker
beetleGraphics.scaleX = 1.5;
beetleGraphics.scaleY = 1.5;
beetleGraphics.tint = 0x330000;
self.speed = 1.5;
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.attackDamage = 40;
self.health = 150;
self.maxHealth = 150;
self.lastAttackTime = 0;
self.update = function () {
// Aggressive targeting towards player and allies
var nearestTarget = null;
var nearestDistance = Infinity;
// Check distance to player ant
var distanceToPlayer = Math.sqrt(Math.pow(self.x - ant.x, 2) + Math.pow(self.y - ant.y, 2));
if (distanceToPlayer < 400) {
nearestTarget = ant;
nearestDistance = distanceToPlayer;
}
// Check distance to ally ants
for (var i = 0; i < allyAnts.length; i++) {
var ally = allyAnts[i];
var distance = Math.sqrt(Math.pow(self.x - ally.x, 2) + Math.pow(self.y - ally.y, 2));
if (distance < nearestDistance) {
nearestDistance = distance;
nearestTarget = ally;
}
}
if (nearestTarget && nearestDistance < 350) {
// Move towards target
var dx = nearestTarget.x - self.x;
var dy = nearestTarget.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
// Random movement
self.changeDirectionTimer++;
if (self.changeDirectionTimer > 80) {
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
}
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
}
// Keep within bounds
if (self.x < 50) self.x = 50;
if (self.x > 1998) self.x = 1998;
if (self.y < 50) self.y = 50;
if (self.y > 2682) self.y = 2682;
};
return self;
});
var StrongSpider = Container.expand(function () {
var self = Container.call(this);
var spiderGraphics = self.attachAsset('spider', {
anchorX: 0.5,
anchorY: 0.5
});
// Make stronger spiders larger and darker
spiderGraphics.scaleX = 1.5;
spiderGraphics.scaleY = 1.5;
spiderGraphics.tint = 0x660000;
self.speed = 2;
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
self.attackDamage = 35;
self.health = 120;
self.maxHealth = 120;
self.lastAttackTime = 0;
self.targetPlayer = false;
self.update = function () {
// Aggressive targeting towards player and allies
var nearestTarget = null;
var nearestDistance = Infinity;
// Check distance to player ant
var distanceToPlayer = Math.sqrt(Math.pow(self.x - ant.x, 2) + Math.pow(self.y - ant.y, 2));
if (distanceToPlayer < 400) {
nearestTarget = ant;
nearestDistance = distanceToPlayer;
}
// Check distance to ally ants
for (var i = 0; i < allyAnts.length; i++) {
var ally = allyAnts[i];
var distance = Math.sqrt(Math.pow(self.x - ally.x, 2) + Math.pow(self.y - ally.y, 2));
if (distance < nearestDistance) {
nearestDistance = distance;
nearestTarget = ally;
}
}
if (nearestTarget && nearestDistance < 300) {
// Move towards target
var dx = nearestTarget.x - self.x;
var dy = nearestTarget.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
// Random movement
self.changeDirectionTimer++;
if (self.changeDirectionTimer > 60) {
self.direction = Math.random() * Math.PI * 2;
self.changeDirectionTimer = 0;
}
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
}
// Keep within bounds
if (self.x < 50) self.x = 50;
if (self.x > 1998) self.x = 1998;
if (self.y < 50) self.y = 50;
if (self.y > 2682) self.y = 2682;
};
return self;
});
var Weapon = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
var weaponGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var WeatherEvent = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.damage = 0;
if (type === 'acidRain') {
var rainGraphics = self.attachAsset('acidRain', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.damage = 10;
} else if (type === 'stone') {
var stoneGraphics = self.attachAsset('fallingStone', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.damage = 25;
} else if (type === 'lightning') {
var lightningGraphics = self.attachAsset('lightning', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0;
self.damage = 30;
self.lifeTime = 30;
}
self.update = function () {
if (self.type !== 'lightning') {
self.y += self.speed;
} else {
self.lifeTime--;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x90EE90
});
/****
* Game Code
****/
// Weather assets
// Weapon assets
// Health bar assets
// New insect enemies
// Anthill interior
var ant;
var anthill;
var resources = [];
var predators = [];
var spiders = [];
var beetles = [];
var weatherEvents = [];
var weapons = [];
var colonyStrength = 0;
var maxColonyStrength = 100;
var gamePhase = 'selection'; // 'selection', 'exploration', 'defense', 'anthill'
var isInsideAnthill = false;
var defensePhaseTriggered = false;
var allyAnts = [];
var strongSpiders = [];
var strongBeetles = [];
var defenseWaveTimer = 0;
var defenseWavesSpawned = 0;
var maxDefenseWaves = 3;
var craftingTable;
var anthillInterior;
var difficulty = 'normal'; // 'normal' or 'hard'
var difficultySelected = false;
var normalButton;
var hardButton;
var difficultyTitle;
// UI Elements
var healthBarBg;
var healthBar;
var strengthText;
var resourceCountText;
var weaponText;
var collectedResources = 0;
var weatherTimer = 0;
var currentWeather = 'clear';
// Initialize anthill (hidden initially)
anthill = game.addChild(LK.getAsset('anthill', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2400
}));
anthill.visible = false;
// Initialize ant (hidden initially)
ant = game.addChild(new Ant());
ant.x = anthill.x;
ant.y = anthill.y - 100;
ant.visible = false;
// Initialize difficulty selection UI
difficultyTitle = new Text2('Selecciona Dificultad', {
size: 80,
fill: 0xFFFFFF
});
difficultyTitle.anchor.set(0.5, 0.5);
difficultyTitle.x = 1024;
difficultyTitle.y = 800;
game.addChild(difficultyTitle);
normalButton = LK.getAsset('healthBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 724,
y: 1200,
scaleX: 2,
scaleY: 3
});
game.addChild(normalButton);
var normalText = new Text2('NORMAL', {
size: 60,
fill: 0x00FF00
});
normalText.anchor.set(0.5, 0.5);
normalText.x = 724;
normalText.y = 1200;
game.addChild(normalText);
hardButton = LK.getAsset('healthBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 1324,
y: 1200,
scaleX: 2,
scaleY: 3
});
game.addChild(hardButton);
var hardText = new Text2('DIFICIL', {
size: 60,
fill: 0xFF0000
});
hardText.anchor.set(0.5, 0.5);
hardText.x = 1324;
hardText.y = 1200;
game.addChild(hardText);
// Initialize UI (hidden initially)
healthBarBg = LK.gui.top.addChild(LK.getAsset('healthBackground', {
x: 200,
y: 100
}));
healthBarBg.visible = false;
healthBar = LK.gui.top.addChild(LK.getAsset('healthBar', {
x: 200,
y: 100
}));
healthBar.visible = false;
strengthText = new Text2('Colony Strength: 0/100', {
size: 40,
fill: 0xFFFFFF
});
strengthText.anchor.set(0, 0);
strengthText.x = 50;
strengthText.y = 150;
strengthText.visible = false;
LK.gui.top.addChild(strengthText);
resourceCountText = new Text2('Resources: 0', {
size: 40,
fill: 0xFFFFFF
});
resourceCountText.anchor.set(0, 0);
resourceCountText.x = 50;
resourceCountText.y = 200;
resourceCountText.visible = false;
LK.gui.top.addChild(resourceCountText);
weaponText = new Text2('Weapon: None', {
size: 40,
fill: 0xFFFFFF
});
weaponText.anchor.set(0, 0);
weaponText.x = 50;
weaponText.y = 250;
weaponText.visible = false;
LK.gui.top.addChild(weaponText);
// Spawn initial resources
function spawnResource() {
var types = ['food', 'twig', 'leaf', 'water'];
var randomType = types[Math.floor(Math.random() * types.length)];
var resource = game.addChild(new Resource(randomType));
resource.x = Math.random() * 1800 + 124;
resource.y = Math.random() * 2000 + 200;
// Avoid spawning too close to anthill
var distanceToAnthill = Math.sqrt(Math.pow(resource.x - anthill.x, 2) + Math.pow(resource.y - anthill.y, 2));
if (distanceToAnthill < 300) {
resource.x = Math.random() * 1000 + 100;
resource.y = Math.random() * 1500 + 200;
}
resources.push(resource);
}
// Spawn initial predators
function spawnPredator() {
var predator = game.addChild(new Predator());
predator.x = Math.random() * 1800 + 124;
predator.y = Math.random() * 1800 + 200;
predators.push(predator);
}
function spawnSpider() {
var spider = game.addChild(new Spider());
spider.x = Math.random() * 1800 + 124;
spider.y = Math.random() * 1800 + 200;
spiders.push(spider);
}
function spawnBeetle() {
var beetle = game.addChild(new Beetle());
beetle.x = Math.random() * 1800 + 124;
beetle.y = Math.random() * 1800 + 200;
beetles.push(beetle);
}
function spawnWeatherEvent() {
var types = ['acidRain', 'stone', 'lightning'];
var randomType = types[Math.floor(Math.random() * types.length)];
var weather = game.addChild(new WeatherEvent(randomType));
if (randomType === 'lightning') {
weather.x = Math.random() * 1800 + 124;
weather.y = 100;
LK.getSound('lightning').play();
} else {
weather.x = Math.random() * 1800 + 124;
weather.y = 0;
}
weatherEvents.push(weather);
}
function setupAnthillInterior() {
anthillInterior = game.addChild(LK.getAsset('anthillInterior', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
anthillInterior.visible = false;
craftingTable = game.addChild(LK.getAsset('craftingTable', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
}));
craftingTable.visible = false;
}
// Initialize world
for (var i = 0; i < 15; i++) {
spawnResource();
}
for (var i = 0; i < 3; i++) {
spawnPredator();
}
for (var i = 0; i < 2; i++) {
spawnSpider();
}
for (var i = 0; i < 2; i++) {
spawnBeetle();
}
setupAnthillInterior();
function startGame() {
gamePhase = 'exploration';
difficultySelected = true;
// Hide difficulty selection UI
difficultyTitle.destroy();
normalButton.destroy();
hardButton.destroy();
// Show game UI
healthBarBg.visible = true;
healthBar.visible = true;
strengthText.visible = true;
resourceCountText.visible = true;
weaponText.visible = true;
anthill.visible = true;
ant.visible = true;
// Apply difficulty adjustments
if (difficulty === 'hard') {
// Hard mode adjustments
for (var i = 0; i < 3; i++) {
spawnSpider();
}
for (var i = 0; i < 3; i++) {
spawnBeetle();
}
// Reduce ant health in hard mode
ant.health = 70;
ant.maxHealth = 70;
}
}
// Resource spawn timer
var resourceSpawnTimer = 0;
game.down = function (x, y, obj) {
if (gamePhase === 'selection') {
// Check if clicking on normal button
var distanceToNormal = Math.sqrt(Math.pow(x - normalButton.x, 2) + Math.pow(y - normalButton.y, 2));
if (distanceToNormal < 150) {
difficulty = 'normal';
startGame();
}
// Check if clicking on hard button
var distanceToHard = Math.sqrt(Math.pow(x - hardButton.x, 2) + Math.pow(y - hardButton.y, 2));
if (distanceToHard < 150) {
difficulty = 'hard';
startGame();
}
} else if (ant.health > 0) {
if (isInsideAnthill) {
// Check if clicking on crafting table
var distanceToCrafting = Math.sqrt(Math.pow(x - craftingTable.x, 2) + Math.pow(y - craftingTable.y, 2));
if (distanceToCrafting < 100 && collectedResources >= 5) {
// Craft weapon
var weaponTypes = ['axe', 'sword', 'shield'];
var randomWeapon = weaponTypes[Math.floor(Math.random() * weaponTypes.length)];
ant.equipWeapon(randomWeapon);
collectedResources -= 5;
LK.getSound('craft').play();
} else {
ant.moveTo(x, y);
}
} else {
// Check if clicking on anthill to enter
var distanceToAnthill = Math.sqrt(Math.pow(x - anthill.x, 2) + Math.pow(y - anthill.y, 2));
if (distanceToAnthill < 100) {
isInsideAnthill = true;
ant.x = 1024;
ant.y = 1500;
anthillInterior.visible = true;
craftingTable.visible = true;
// Hide exterior elements
anthill.visible = false;
for (var i = 0; i < resources.length; i++) {
resources[i].visible = false;
}
for (var i = 0; i < predators.length; i++) {
predators[i].visible = false;
}
for (var i = 0; i < spiders.length; i++) {
spiders[i].visible = false;
}
for (var i = 0; i < beetles.length; i++) {
beetles[i].visible = false;
}
} else {
ant.moveTo(x, y);
}
}
}
};
game.update = function () {
if (gamePhase === 'selection') {
// Don't update game logic during difficulty selection
return;
}
// Update health bar
var healthPercent = ant.health / ant.maxHealth;
healthBar.scaleX = healthPercent;
// Update UI text
strengthText.setText('Colony Strength: ' + colonyStrength + '/' + maxColonyStrength);
resourceCountText.setText('Resources: ' + collectedResources);
weaponText.setText('Weapon: ' + (ant.weapon || 'None'));
if (!isInsideAnthill) {
// Weather system
weatherTimer++;
var weatherSpawnRate = difficulty === 'hard' ? 250 : 400;
var weatherChance = difficulty === 'hard' ? 0.5 : 0.3;
if (weatherTimer > weatherSpawnRate) {
if (Math.random() < weatherChance) {
spawnWeatherEvent();
}
weatherTimer = 0;
}
// Update weather events
for (var i = weatherEvents.length - 1; i >= 0; i--) {
var weather = weatherEvents[i];
if (weather.type === 'lightning' && weather.lifeTime <= 0) {
weather.destroy();
weatherEvents.splice(i, 1);
} else if (weather.y > 2800) {
weather.destroy();
weatherEvents.splice(i, 1);
} else if (ant.intersects(weather)) {
ant.takeDamage(weather.damage);
LK.getSound('impact').play();
weather.destroy();
weatherEvents.splice(i, 1);
}
}
// Spawn new resources periodically
resourceSpawnTimer++;
if (resourceSpawnTimer > 300 && resources.length < 20) {
spawnResource();
resourceSpawnTimer = 0;
}
// Check for resource collection
for (var i = resources.length - 1; i >= 0; i--) {
var resource = resources[i];
if (ant.intersects(resource) && resource.visible) {
LK.getSound('collect').play();
colonyStrength = Math.min(maxColonyStrength, colonyStrength + resource.value);
collectedResources++;
LK.setScore(LK.getScore() + resource.value * 10);
// Flash effect
LK.effects.flashObject(ant, 0x00FF00, 300);
resource.destroy();
resources.splice(i, 1);
}
}
// Check for predator collisions
for (var i = 0; i < predators.length; i++) {
var predator = predators[i];
if (ant.intersects(predator) && predator.visible) {
LK.getSound('danger').play();
ant.takeDamage(15);
// Push ant away from predator
var dx = ant.x - predator.x;
var dy = ant.y - predator.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
ant.x += dx / distance * 100;
ant.y += dy / distance * 100;
}
}
}
// Check for spider collisions and combat
for (var i = spiders.length - 1; i >= 0; i--) {
var spider = spiders[i];
var distanceToSpider = Math.sqrt(Math.pow(ant.x - spider.x, 2) + Math.pow(ant.y - spider.y, 2));
// Attack with weapon at distance
if (ant.weapon && distanceToSpider < 120 && spider.visible) {
// Attack spider with weapon at range
spider.health -= ant.attackDamage;
LK.effects.flashObject(spider, 0xFF0000, 200);
if (spider.health <= 0) {
// Spider defeated
LK.effects.flashObject(ant, 0x00FF00, 300);
LK.setScore(LK.getScore() + 50);
spider.destroy();
spiders.splice(i, 1);
continue;
}
}
// Only take damage if actually touching
else if (ant.intersects(spider) && spider.visible) {
LK.getSound('danger').play();
ant.takeDamage(spider.attackDamage);
// Push ant away
var dx = ant.x - spider.x;
var dy = ant.y - spider.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
ant.x += dx / distance * 80;
ant.y += dy / distance * 80;
}
}
}
// Check for beetle collisions and combat
for (var i = beetles.length - 1; i >= 0; i--) {
var beetle = beetles[i];
var distanceToBeetle = Math.sqrt(Math.pow(ant.x - beetle.x, 2) + Math.pow(ant.y - beetle.y, 2));
// Attack with weapon at distance
if (ant.weapon && distanceToBeetle < 120 && beetle.visible) {
// Attack beetle with weapon at range
beetle.health -= ant.attackDamage;
LK.effects.flashObject(beetle, 0xFF0000, 200);
if (beetle.health <= 0) {
// Beetle defeated
LK.effects.flashObject(ant, 0x00FF00, 300);
LK.setScore(LK.getScore() + 75);
beetle.destroy();
beetles.splice(i, 1);
continue;
}
}
// Only take damage if actually touching
else if (ant.intersects(beetle) && beetle.visible) {
LK.getSound('danger').play();
ant.takeDamage(beetle.attackDamage);
// Push ant away
var dx = ant.x - beetle.x;
var dy = ant.y - beetle.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
ant.x += dx / distance * 60;
ant.y += dy / distance * 60;
}
}
}
// Check if ant is at anthill (health restoration)
var distanceToAnthill = Math.sqrt(Math.pow(ant.x - anthill.x, 2) + Math.pow(ant.y - anthill.y, 2));
if (distanceToAnthill < 100 && anthill.visible) {
// Restore some health when at anthill
ant.health = Math.min(ant.maxHealth, ant.health + 0.5);
}
} else {
// Inside anthill logic
// Exit anthill if ant moves to bottom
if (ant.y > 2000) {
isInsideAnthill = false;
ant.x = anthill.x;
ant.y = anthill.y - 100;
anthillInterior.visible = false;
craftingTable.visible = false;
// Show exterior elements
anthill.visible = true;
for (var i = 0; i < resources.length; i++) {
resources[i].visible = true;
}
for (var i = 0; i < predators.length; i++) {
predators[i].visible = true;
}
for (var i = 0; i < spiders.length; i++) {
spiders[i].visible = true;
}
for (var i = 0; i < beetles.length; i++) {
beetles[i].visible = true;
}
}
}
// Game over conditions
if (ant.health <= 0) {
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
// Defense phase trigger at halfway point
if (colonyStrength >= maxColonyStrength / 2 && !defensePhaseTriggered && gamePhase === 'exploration') {
defensePhaseTriggered = true;
gamePhase = 'defense';
// Spawn ally ants with advanced weapons
var weapons = ['sword', 'axe', 'shield'];
for (var i = 0; i < 3; i++) {
var allyWeapon = weapons[i % weapons.length];
var ally = game.addChild(new AllyAnt(allyWeapon));
ally.x = anthill.x + (Math.random() - 0.5) * 200;
ally.y = anthill.y + (Math.random() - 0.5) * 200;
allyAnts.push(ally);
}
// Show defense message
LK.effects.flashScreen(0x00FF00, 1000);
// Start spawning strong enemies
defenseWaveTimer = 0;
defenseWavesSpawned = 0;
}
// Defense phase logic
if (gamePhase === 'defense') {
defenseWaveTimer++;
// Spawn waves of strong enemies
if (defenseWaveTimer > 600 && defenseWavesSpawned < maxDefenseWaves) {
// Every 10 seconds
// Spawn strong spiders
for (var i = 0; i < 2; i++) {
var strongSpider = game.addChild(new StrongSpider());
strongSpider.x = Math.random() * 1800 + 124;
strongSpider.y = Math.random() * 1800 + 200;
strongSpiders.push(strongSpider);
}
// Spawn strong beetles
for (var i = 0; i < 2; i++) {
var strongBeetle = game.addChild(new StrongBeetle());
strongBeetle.x = Math.random() * 1800 + 124;
strongBeetle.y = Math.random() * 1800 + 200;
strongBeetles.push(strongBeetle);
}
defenseWavesSpawned++;
defenseWaveTimer = 0;
LK.getSound('danger').play();
}
// Check if defense is complete (all strong enemies defeated)
if (defenseWavesSpawned >= maxDefenseWaves && strongSpiders.length === 0 && strongBeetles.length === 0) {
gamePhase = 'exploration';
// Bonus rewards for completing defense
colonyStrength += 20;
LK.effects.flashScreen(0x00FF00, 1500);
}
}
// Strong spider combat and cleanup
for (var i = strongSpiders.length - 1; i >= 0; i--) {
var strongSpider = strongSpiders[i];
if (strongSpider.health <= 0) {
LK.effects.flashObject(ant, 0x00FF00, 300);
LK.setScore(LK.getScore() + 200);
strongSpider.destroy();
strongSpiders.splice(i, 1);
continue;
}
// Combat with player
var distanceToStrongSpider = Math.sqrt(Math.pow(ant.x - strongSpider.x, 2) + Math.pow(ant.y - strongSpider.y, 2));
// Attack with weapon at distance
if (ant.weapon && distanceToStrongSpider < 140 && strongSpider.visible && LK.ticks % 30 === 0) {
strongSpider.health -= ant.attackDamage;
LK.effects.flashObject(strongSpider, 0xFF0000, 200);
}
// Only take damage if actually touching
if (ant.intersects(strongSpider) && strongSpider.visible && LK.ticks % 45 === 0) {
LK.getSound('danger').play();
ant.takeDamage(strongSpider.attackDamage);
}
// Combat with allies
for (var j = 0; j < allyAnts.length; j++) {
var ally = allyAnts[j];
if (ally.intersects(strongSpider) && LK.ticks % 40 === 0) {
ally.takeDamage(strongSpider.attackDamage);
if (ally.health <= 0) {
ally.destroy();
allyAnts.splice(j, 1);
break;
}
}
}
}
// Strong beetle combat and cleanup
for (var i = strongBeetles.length - 1; i >= 0; i--) {
var strongBeetle = strongBeetles[i];
if (strongBeetle.health <= 0) {
LK.effects.flashObject(ant, 0x00FF00, 300);
LK.setScore(LK.getScore() + 250);
strongBeetle.destroy();
strongBeetles.splice(i, 1);
continue;
}
// Combat with player
var distanceToStrongBeetle = Math.sqrt(Math.pow(ant.x - strongBeetle.x, 2) + Math.pow(ant.y - strongBeetle.y, 2));
// Attack with weapon at distance
if (ant.weapon && distanceToStrongBeetle < 140 && strongBeetle.visible && LK.ticks % 35 === 0) {
strongBeetle.health -= ant.attackDamage;
LK.effects.flashObject(strongBeetle, 0xFF0000, 200);
}
// Only take damage if actually touching
if (ant.intersects(strongBeetle) && strongBeetle.visible && LK.ticks % 50 === 0) {
LK.getSound('danger').play();
ant.takeDamage(strongBeetle.attackDamage);
}
// Combat with allies
for (var j = 0; j < allyAnts.length; j++) {
var ally = allyAnts[j];
if (ally.intersects(strongBeetle) && LK.ticks % 45 === 0) {
ally.takeDamage(strongBeetle.attackDamage);
if (ally.health <= 0) {
ally.destroy();
allyAnts.splice(j, 1);
break;
}
}
}
}
// Win condition
if (colonyStrength >= maxColonyStrength) {
LK.showYouWin();
}
};
escarabajo de terror. In-Game asset. High contrast. No shadows
hormiga. In-Game asset. 2d. High contrast. No shadows
tierra amontonada. In-Game asset. 2d. High contrast
hoja. In-Game asset. 2d. High contrast
escarabajo. In-Game asset. 2d. High contrast. No shadows
hacha. In-Game asset. 2d. High contrast. No shadows
araña miedo. In-Game asset. 2d. High contrast. No shadows
gota de acido. In-Game asset. 2d. High contrast. No shadows
interior de un hormiguero. In-Game asset. 2d
mesa de elaboracion de tierra. In-Game asset. 2d
piedra. In-Game asset. 2d. High contrast. No shadows
miga de pan. In-Game asset. 2d. High contrast. No shadows
escudo. In-Game asset. 2d. High contrast. No shadows
rayo fuerte. In-Game asset. 2d. High contrast. No shadows
espada de guerra. In-Game asset. 2d. High contrast. No shadows
rama de madera. In-Game asset. 2d. High contrast. No shadows
gota de agua. In-Game asset. 2d. High contrast. No shadows
barra de vida. In-Game asset. 2d. High contrast. No shadows