Code edit (1 edits merged)
Please save this source code
User prompt
make the super boss do 50 damage
Code edit (1 edits merged)
Please save this source code
User prompt
make the super boss a seperate asset
User prompt
make a super boss that spawns in once score is at 100
User prompt
make boss enemies do twice as much damage
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in or related to this line: 'if (enemies[k].health > 0 && bullets[j].intersects(enemies[k])) {' Line Number: 275
User prompt
make a cap for the spawn interval
User prompt
set the text for score back to white
User prompt
make the text for score red
User prompt
make the text for score black
User prompt
make a score counter at the top that goes up 1 every time an enemy is killed and 10 every every time a boss is killed
User prompt
make enemies spawn in faster over time
User prompt
make enemies and bosses spawn less frequently
User prompt
have the background music always playing on a loop
User prompt
have a seperate sound for when the base gets hit
User prompt
make a sound when the boss gets hit
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'update')' in or related to this line: 'bullets[j].update();' Line Number: 250
User prompt
make the background the same size as the screen
User prompt
make a background
User prompt
make a background
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
var Base = Container.expand(function () {
var self = Container.call(this);
var baseGraphics = self.attachAsset('base', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 500;
self.update = function () {
if (self.health <= 0) {
LK.showGameOver();
}
};
self.takeDamage = function (amount) {
self.health -= amount;
// Play player damage sound
LK.getSound('playerDamage').play();
};
});
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('boss', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 200;
self.speed = 0.5;
self.update = function () {
// Update logic for boss
// Move straight down
self.y += self.speed;
};
self.takeDamage = function (amount) {
self.health -= amount;
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// Handle boss death
for (var i = bullets.length - 1; i >= 0; i--) {
if (bullets[i].intersects(self)) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
// Play boss death sound
LK.getSound('bossDeath').play();
self.destroy();
};
});
// 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.update = function () {
self.y -= self.speed;
if (self.y < 0 || self.y > 2732) {
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.health = 50;
self.speed = 1;
self.update = function () {
// Update logic for enemy
// Move straight down
self.y += self.speed;
};
self.takeDamage = function (amount) {
self.health -= amount;
// Play enemy hit sound
LK.getSound('enemyHit').play();
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// Handle enemy death
for (var i = bullets.length - 1; i >= 0; i--) {
if (bullets[i].intersects(self)) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
// Play enemy death sound
LK.getSound('enemyDeath').play();
self.destroy();
};
});
// HealthBar class
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var healthBarGraphics = self.attachAsset('healthBar', {
anchorX: 0.5,
anchorY: 0.5,
height: 10
});
self.update = function () {
// Update logic for health bar
// Adjust width of health bar based on health of parent
healthBarGraphics.width = self.parent.health * 2;
};
self.interactive = false; // Disable hitbox for health bar
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.speed = 5;
self.update = function () {
// Update logic for hero
// Move hero left if it's not at the edge of the screen
if (self.x > 0) {
self.x -= self.speed;
}
// Move hero right if it's not at the edge of the screen
if (self.x < 2048) {
self.x += self.speed;
}
};
self.takeDamage = function (amount) {
self.health -= amount;
// Play player damage sound
LK.getSound('playerDamage').play();
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// Handle hero death
LK.showGameOver();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
LK.playMusic('backgroundMusic');
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 200;
// Attach health bar to hero
var heroHealthBar = hero.addChild(new HealthBar());
heroHealthBar.y = 75; // Position health bar below hero
var base = game.addChild(new Base());
base.x = 2048 / 2;
base.y = 2732 - 50;
// Attach health bar to base
var baseHealthBar = base.addChild(new HealthBar());
baseHealthBar.y = 0; // Position health bar above base
// Initialize enemies array
var enemies = [];
// Initialize bullets array
var bullets = [];
// Function to spawn enemies
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = 0;
// Attach health bar to enemy
var enemyHealthBar = enemy.addChild(new HealthBar());
enemyHealthBar.y = -75; // Position health bar slightly above enemy
enemies.push(enemy);
game.addChild(enemy);
}
// Function to shoot bullets
function shootBullet() {
var bullet = new Bullet();
bullet.x = hero.x;
bullet.y = hero.y;
bullets.push(bullet);
game.addChild(bullet);
}
// Handle touch events for shooting
game.down = function (x, y, obj) {
hero.x = x;
shootBullet();
};
// Update game logic
game.update = function () {
// Update hero
hero.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].intersects(hero)) {
hero.takeDamage(10);
enemies[i].destroy();
enemies.splice(i, 1);
} else if (enemies[i].intersects(base)) {
base.takeDamage(10);
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
for (var k = enemies.length - 1; k >= 0; k--) {
if (enemies[k].health > 0 && bullets[j].intersects(enemies[k])) {
enemies[k].takeDamage(20);
if (bullets[j]) {
bullets[j].destroy();
}
bullets.splice(j, 1);
break;
}
}
}
if (LK.ticks % 60 == 0) {
spawnEnemy();
}
// Spawn boss enemy periodically
if (LK.ticks % 600 == 0) {
var boss = new Boss();
boss.x = Math.random() * 2048;
boss.y = 0;
// Attach health bar to boss
var bossHealthBar = boss.addChild(new HealthBar());
bossHealthBar.y = -125; // Position health bar slightly above boss
enemies.push(boss);
game.addChild(boss);
}
// Spawn powerups periodically
};
game.move = function (x, y, obj) {
hero.x = x;
};