User prompt
Increase the range bullet to 5x
User prompt
Do not fire more than 3 bullets per enemy and shoot only when new enemy is spawned om top of the screen
User prompt
Shoot the bullet from the tower only when the enemy is at 5 units distance form the tower and so not trigger the bullets continuously
User prompt
Shoot the arrows only when the alien is 3x units distance to the tower
User prompt
Increase the range of the bullets by 3x
User prompt
increase the range of the bullets from the tower to 2 x
User prompt
the game is over only when we miss more than 10 enemys
Initial prompt
show the missed enemy list in the bottom of the game screen
/**** * Classes ****/ // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.target = null; self.update = function () { if (self.target) { var dx = self.target.x - self.x; var dy = self.target.y - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < self.speed) { self.target.health -= 10; if (self.target.health <= 0) { self.target.destroy(); } self.destroy(); } else { self.x += dx / dist * self.speed; self.y += dy / dist * self.speed; } } else { self.destroy(); } }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.health = 100; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); missedEnemies.push(self); updateMissedEnemiesList(); if (missedEnemies.length > 10) { gameOver(); } } }; }); //<Assets used in the game will automatically appear here> // Tower class var Tower = Container.expand(function () { var self = Container.call(this); var towerGraphics = self.attachAsset('tower', { anchorX: 0.5, anchorY: 0.5 }); self.range = 600; self.fireRate = 60; self.fireCooldown = 0; self.update = function () { if (self.fireCooldown > 0) { self.fireCooldown--; } else { var target = findClosestEnemy(self); if (target) { fireBullet(self, target); self.fireCooldown = self.fireRate; } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var towers = []; var enemies = []; var bullets = []; var score = 0; var baseHealth = 100; var missedEnemies = []; var missedEnemiesTxt = new Text2('Missed Enemies: 0', { size: 50, fill: 0xFFFFFF }); missedEnemiesTxt.anchor.set(0.5, 0); LK.gui.bottom.addChild(missedEnemiesTxt); // Create score text var scoreTxt = new Text2('Score: 0', { size: 50, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create base health text var healthTxt = new Text2('Base Health: 100', { size: 50, fill: 0xFFFFFF }); healthTxt.anchor.set(0.5, 0); LK.gui.topRight.addChild(healthTxt); // Function to find the closest enemy to a tower function findClosestEnemy(tower) { var closest = null; var closestDist = tower.range; for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; var dx = enemy.x - tower.x; var dy = enemy.y - tower.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < closestDist) { closest = enemy; closestDist = dist; } } return closest; } // Function to fire a bullet from a tower to a target function fireBullet(tower, target) { var bullet = new Bullet(); bullet.x = tower.x; bullet.y = tower.y; bullet.target = target; bullets.push(bullet); game.addChild(bullet); } // Function to handle game over function gameOver() { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } function updateMissedEnemiesList() { missedEnemiesTxt.setText('Missed Enemies: ' + missedEnemies.length); } // Function to spawn enemies function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -50; enemies.push(enemy); game.addChild(enemy); } // Game update function game.update = function () { for (var i = 0; i < towers.length; i++) { towers[i].update(); } for (var i = 0; i < enemies.length; i++) { enemies[i].update(); } for (var i = 0; i < bullets.length; i++) { bullets[i].update(); } if (LK.ticks % 120 == 0) { spawnEnemy(); } }; // Event listener for placing towers game.down = function (x, y, obj) { var tower = new Tower(); tower.x = x; tower.y = y; towers.push(tower); game.addChild(tower); };
===================================================================
--- original.js
+++ change.js
@@ -58,9 +58,9 @@
var towerGraphics = self.attachAsset('tower', {
anchorX: 0.5,
anchorY: 0.5
});
- self.range = 300;
+ self.range = 600;
self.fireRate = 60;
self.fireCooldown = 0;
self.update = function () {
if (self.fireCooldown > 0) {
@@ -93,23 +93,23 @@
var baseHealth = 100;
var missedEnemies = [];
var missedEnemiesTxt = new Text2('Missed Enemies: 0', {
size: 50,
- fill: "#ffffff"
+ fill: 0xFFFFFF
});
missedEnemiesTxt.anchor.set(0.5, 0);
LK.gui.bottom.addChild(missedEnemiesTxt);
// Create score text
var scoreTxt = new Text2('Score: 0', {
size: 50,
- fill: "#ffffff"
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create base health text
var healthTxt = new Text2('Base Health: 100', {
size: 50,
- fill: "#ffffff"
+ fill: 0xFFFFFF
});
healthTxt.anchor.set(0.5, 0);
LK.gui.topRight.addChild(healthTxt);
// Function to find the closest enemy to a tower
create a tower in a tower defense game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
SINGLE alien in BLUE color with GIF animation of arrows animation with a spark at the end of the sprite animation. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
GIF animation of arrows animation with a spark at the end of the sprite animation. Sprite Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.