User prompt
add score to the game. The player gets 10 points for every enemy killed. Write this score top right of the screen
User prompt
move the bomb counter 100 pixels to the right
User prompt
move the bomb counter 2100 pixels to the right
User prompt
move the bomb counter 200 pixels to the left
User prompt
move the bomb counter 400 pixels to the right
User prompt
move the bomb counter 800 pixels to the left
User prompt
move the bomb counter text slightly to the left
User prompt
move the bomb counter text slightly to the left
User prompt
make sure the bomb count text is visible
User prompt
move bomb counter to left of the screen
User prompt
add text to the bomb counter - it should say 'next bomb in' then the timer
User prompt
the bomb countdown doesn't reset when I trigger a bomb
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.enemyCounter.setText')' in this line: 'self.enemyCounter.setText('0');' Line Number: 194
User prompt
I can't see the bombcountdown
User prompt
create a UI element: a countdown until the next bomb appears
User prompt
remove the visuals for the on-screen enemy counter
User prompt
fix bug in bomb so it only destroys half the on-screen enemies
User prompt
fix bug in bomb so it only destroys half the on-screen enemies
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.parent.enemyCounter.setText')' in this line: 'self.parent.enemyCounter.setText(self.parent.enemies.length.toString());' Line Number: 59
User prompt
remove the on-screen visuals for the enemy counter
User prompt
Fix Bug: 'Timeout.tick error: undefined is not an object (evaluating 'self.enemyCounter.setText')' in this line: 'self.enemyCounter.setText(self.enemies.length.toString());' Line Number: 306
User prompt
remove the graphics for the enemy counter on the top right. don't change any game logic
User prompt
Fix Bug: 'Timeout.tick error: undefined is not an object (evaluating 'self.enemyCounter.setText')' in this line: 'self.enemyCounter.setText(self.enemies.length.toString());' Line Number: 312
User prompt
Fix Bug: 'Timeout.tick error: undefined is not an object (evaluating 'self.enemyCounter.setText')' in this line: 'self.enemyCounter.setText(self.enemies.length.toString());' Line Number: 310
User prompt
Fix Bug: 'Timeout.tick error: undefined is not an object (evaluating 'self.enemyCounter.setText')' in this line: 'self.enemyCounter.setText(self.enemies.length.toString());' Line Number: 308
var BombPickup = Container.expand(function () {
var self = Container.call(this);
self.bombGraphics = self.createAsset('bombPickup', 'Bomb Pickup', 0.5, 0.5);
self.bombGraphics.scale.set(1.3);
});
var Star = Container.expand(function (speed) {
var self = Container.call(this);
self.starGraphics = self.createAsset('star', 'White Round Star', 0.5, 0.5);
self.speed = speed;
self.move = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -self.starGraphics.height;
self.x = Math.random() * 2048;
}
};
});
var HealthPickup = Container.expand(function () {
var self = Container.call(this);
self.pickupGraphics = self.createAsset('healthPickup', 'Health Pickup', 0.5, 0.5);
self.pickupGraphics.scale.set(1.3);
});
var HealthBar = Container.expand(function (maxHealth, currentHealth) {
var self = Container.call(this);
self.maxHealth = maxHealth;
self.currentHealth = currentHealth;
self.background = self.createAsset('healthBarBackground', 'Health Bar Background', 0, 0.5);
self.background.scale.set(2, 0.125);
self.foreground = self.createAsset('healthBarForeground', 'Health Bar Foreground', 0, 0.5);
self.foreground.scale.set(2, 0.125);
self.updateHealth = function (newHealth) {
self.currentHealth = newHealth;
self.foreground.scale.x = self.currentHealth / self.maxHealth;
};
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
self.bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
self.bulletGraphics.scale.set(0.2);
var speed = 20;
self.direction = 0;
self.move = function () {
self.x += Math.cos(self.direction) * speed;
self.y += Math.sin(self.direction) * speed;
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
if (self.parent && self.parent.bullets && self.parent.bullets.includes(self)) {
self.parent.bullets.splice(self.parent.bullets.indexOf(self), 1);
self.destroy();
}
}
};
self.hit = function (enemy) {
if (self.parent && self.parent.enemies && self.parent.enemies.includes(enemy)) {
enemy.enemyGraphics.scale.x /= 1.2;
enemy.enemyGraphics.scale.y /= 1.2;
if (enemy.enemyGraphics.scale.x < 0.8 || enemy.enemyGraphics.scale.y < 0.8) {
self.parent.enemies.splice(self.parent.enemies.indexOf(enemy), 1);
enemy.destroy();
self.parent.enemyCounter.setText(self.parent.enemies.length.toString());
if (self.parent && self.parent.bullets && self.parent.bullets.includes(self)) {
self.parent.bullets.splice(self.parent.bullets.indexOf(self), 1);
self.destroy();
}
}
}
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
self.health = 100;
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
heroGraphics.scale.set(1);
heroGraphics.rotation = Math.PI / 2;
self.bullets = [];
self.move = function () {
for (var i = 0; i < self.bullets.length; i++) {
self.bullets[i].move();
}
};
self.lastDamageTime = 0;
self.reduceHealth = function (amount) {
var currentTime = LK.ticks;
if (currentTime - self.lastDamageTime >= 15) {
self.health -= amount * 2;
if (self.health < 0) self.health = 0;
self.healthBar.updateHealth(self.health);
self.lastDamageTime = currentTime;
}
};
self.lastShootTime = 0;
self.shoot = function () {
var currentTime = LK.ticks;
if (currentTime - self.lastShootTime >= 6) {
var nearestEnemy = self.parent.findNearestEnemy(self.x, self.y);
if (nearestEnemy) {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullet.direction = Math.atan2(nearestEnemy.y - self.y, nearestEnemy.x - self.x);
self.rotation = bullet.direction;
self.bullets.push(bullet);
self.parent.addChild(bullet);
bullet.move();
self.lastShootTime = currentTime;
}
}
};
self.trackMovement = function (event) {
var pos = event.getLocalPosition(self.parent);
self.x = pos.x;
self.y = pos.y;
self.healthBar.x = self.x - self.healthBar.width / 2;
self.healthBar.y = self.y - heroGraphics.height / 2 - 10;
};
});
var YellowEnemy = Container.expand(function () {
var self = Container.call(this);
self.enemyGraphics = self.createAsset('yellowEnemy', 'Yellow Enemy character', .5, .5);
var direction = Math.random() * Math.PI * 2;
var speed = 2 * (0.8 + Math.random() * 1);
self.move = function () {
if (self.parent && self.parent.hero && self.parent.hero.x === self.parent.hero.lastX && self.parent.hero.y === self.parent.hero.lastY) {
direction = Math.atan2(self.parent.hero.y - self.y, self.parent.hero.x - self.x);
}
if (direction < 0) direction += 2 * Math.PI;
if (direction > 2 * Math.PI) direction -= 2 * Math.PI;
self.x += Math.cos(direction) * speed;
self.y += Math.sin(direction) * speed;
direction += (Math.random() - 0.5) * 0.1;
self.enemyGraphics.rotation = direction;
var margin = 100;
if (self.x < margin) {
self.x = margin;
direction = 0;
} else if (self.x > 2048 - margin) {
self.x = 2048 - margin;
direction = Math.PI;
}
if (self.y < margin) {
self.y = margin;
direction = Math.PI / 2;
} else if (self.y > 2732 - margin) {
self.y = 2732 - margin;
direction = 3 * Math.PI / 2;
}
if (self.enemyGraphics.scale.x < 0.8 || self.enemyGraphics.scale.y < 0.8) {
self.destroy();
self.parent.enemyCounter.setText(self.parent.enemies.length.toString());
}
};
self.grow = function () {
if (self.enemyGraphics.scale.x < 5 && self.enemyGraphics.scale.y < 5) {
self.enemyGraphics.scale.x *= 1.2;
self.enemyGraphics.scale.y *= 1.2;
}
};
LK.setInterval(self.grow, 1500);
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.spawnBombPickup = function () {
var bombPickup = new BombPickup();
bombPickup.x = Math.random() * (2048 - bombPickup.bombGraphics.width) + bombPickup.bombGraphics.width / 2;
bombPickup.y = Math.random() * (2732 - bombPickup.bombGraphics.height) + bombPickup.bombGraphics.height / 2;
self.bombPickups.push(bombPickup);
self.addChild(bombPickup);
};
LK.setInterval(self.spawnBombPickup, 30000);
self.checkForBombPickup = function (hero, bombPickups) {
for (var i = bombPickups.length - 1; i >= 0; i--) {
var pickup = bombPickups[i];
if (hero.intersects(pickup)) {
var halfEnemyCount = Math.ceil(self.enemies.length / 2);
for (var i = 0; i < halfEnemyCount; i++) {
var enemyIndex = Math.floor(Math.random() * self.enemies.length);
var enemy = self.enemies.splice(enemyIndex, 1)[0];
enemy.destroy();
}
if (self.enemyCounter) {
if (self.enemyCounter) {
self.enemyCounter.setText(self.enemies.length.toString());
}
}
pickup.destroy();
bombPickups.splice(i, 1);
}
}
};
self.checkForHealthPickup = function (hero, healthPickups) {
for (var i = healthPickups.length - 1; i >= 0; i--) {
var pickup = healthPickups[i];
if (hero.intersects(pickup)) {
hero.health = hero.healthBar.maxHealth * 2;
hero.healthBar.updateHealth(hero.health);
pickup.destroy();
healthPickups.splice(i, 1);
}
}
};
self.spawnHealthPickup = function () {
var healthPickup = new HealthPickup();
healthPickup.x = Math.random() * (2048 - healthPickup.pickupGraphics.width) + healthPickup.pickupGraphics.width / 2;
healthPickup.y = Math.random() * (2732 - healthPickup.pickupGraphics.height) + healthPickup.pickupGraphics.height / 2;
self.healthPickups.push(healthPickup);
self.addChild(healthPickup);
};
self.findNearestEnemy = function (x, y) {
var nearestEnemy = null;
var nearestDistance = Infinity;
for (var i = 0; i < self.enemies.length; i++) {
var dx = x - self.enemies[i].x;
var dy = y - self.enemies[i].y;
var distanceSquared = dx * dx + dy * dy;
if (distanceSquared < nearestDistance * nearestDistance) {
nearestDistance = Math.sqrt(distanceSquared);
nearestEnemy = self.enemies[i];
}
}
return nearestEnemy;
};
LK.on('tick', function () {
hero.move();
for (var i = 0; i < self.enemies.length; i++) {
self.enemies[i].move();
}
for (var i = 0; i < self.enemies.length; i++) {
if (hero.intersects(self.enemies[i]) && LK.ticks - hero.lastDamageTime >= 15) {
hero.reduceHealth(10);
if (hero.health <= 0) {
LK.showGameOver();
return;
}
}
}
self.checkForHealthPickup(hero, self.healthPickups);
self.checkForBombPickup(hero, self.bombPickups);
if (hero.health <= hero.healthBar.maxHealth * 0.40 && self.healthPickups.length === 0) {
self.spawnHealthPickup();
}
hero.shoot();
for (var i = 0; i < hero.bullets.length; i++) {
for (var j = 0; j < self.enemies.length; j++) {
if (hero.bullets[i] && hero.bullets[i].intersects(self.enemies[j])) {
hero.bullets[i].hit(self.enemies[j]);
hero.bullets[i].destroy();
hero.bullets.splice(i, 1);
i--;
}
}
if (hero.bullets[i] && (hero.bullets[i].x < 0 || hero.bullets[i].x > 2048 || hero.bullets[i].y < 0 || hero.bullets[i].y > 2732)) {
hero.bullets[i].destroy();
hero.bullets.splice(i, 1);
i--;
}
}
});
self.stars = [];
for (var i = 0; i < 100; i++) {
var starSpeed = 0.5 + Math.random() * 2;
var star = new Star(starSpeed);
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
self.stars.push(star);
self.addChild(star);
}
var hero = self.addChild(new Hero());
hero.healthBar = self.addChild(new HealthBar(hero.health, hero.health));
self.enemies = [];
self.healthPickups = [];
self.bombPickups = [];
hero.x = 2048 / 2;
hero.y = 2732 / 2;
LK.on('tick', function () {
for (var i = 0; i < self.stars.length; i++) {
self.stars[i].move();
}
hero.move();
for (var i = 0; i < self.enemies.length; i++) {
self.enemies[i].move();
}
});
LK.stage.on('move', function (obj) {
hero.trackMovement(obj.event);
});
var enemySpawnCounter = 0;
var spawnEnemy = LK.setInterval(function () {
if (self.enemies.length < 50) {
var enemy = new YellowEnemy();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
enemy.x = Math.random() * 2048;
enemy.y = -enemy.enemyGraphics.height;
break;
case 1:
enemy.x = 2048 + enemy.enemyGraphics.width;
enemy.y = Math.random() * 2732;
break;
case 2:
enemy.x = Math.random() * 2048;
enemy.y = 2732 + enemy.enemyGraphics.height;
break;
case 3:
enemy.x = -enemy.enemyGraphics.width;
enemy.y = Math.random() * 2732;
break;
}
self.enemies.push(enemy);
self.addChild(enemy);
self.enemyCounter.setText(self.enemies.length.toString());
enemySpawnCounter++;
}
}, 325);
});
amoeba Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Green equilateral triangle, fills the entire picture space in width and height Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
square box viewed from above. White with a large Red Cross Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Purple bomb Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
space image stylised gas clouds, black and white image, low contrast