User prompt
boss should shoot 2 deathlaser at same time
User prompt
make deathlaser speed little bit higher
User prompt
i change the code but still not working , can you look to code to find my mistake
Code edit (1 edits merged)
Please save this source code
User prompt
now add boss deathlaser for 5 hp or less with 1 shooter
User prompt
okay now, if boss has 5hp left boss completly stop shooting
User prompt
we counter a bug, for that first boss will stop shooting if it has 5 hp left
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'shootDeathLaser')' in or related to this line: 'self.shootDeathLaser = function () {' Line Number: 365
User prompt
if boss has 5 hp left boss start shooting deathlaser using death laser asset
User prompt
make boss hp 10
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in or related to this line: 'if (boss && boss.intersects && lasers[i].intersects(boss)) {' Line Number: 261
User prompt
okay lets make boss healt 10 and if boss has 5 hp left it should stop shooting from left laser but keep continue from right and center
User prompt
we counter a bug, boss stop shooting after 1 damage instead of keep shooting with middle and right shooter
User prompt
okay lets make it like this, after boss take 1 damage boss left shooter stop shooting
User prompt
we counter a bug, after boss take 1 shot its stop shooting, it should continue shooting with 2 laser
User prompt
after boss take 1 damage make boss starts shooting 2 laser, and after 1 more damage boss starts shooting 1 laser
User prompt
make it 0.1
User prompt
make it 0.5
User prompt
add background music to the game using space music asset
User prompt
use kabom sound effect for kabom asset
User prompt
we counter a bug only 1 of them is dissapering 2 of them left make all disaper at same time
User prompt
make kabom showtime same as destroy
User prompt
make the explosion size 1/4 size of boss but use it 3 times at same time
User prompt
bigger
User prompt
make explosion bigger
/****
* Classes
****/
// Boss class
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('boss', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
self.speed = 2;
self.horizontalSpeed = 2;
self.health = 3;
self.update = function () {
if (self.y < 2732 / 3 - bossGraphics.height / 4) {
self.y += self.speed;
} else {
self.x += self.horizontalSpeed;
if (self.x > 2048 - bossGraphics.width * 0.75 || self.x < bossGraphics.width * 0.75) {
self.horizontalSpeed = -self.horizontalSpeed;
}
}
};
self.shoot = function () {
// Center laser
var centerLaser = new EnemyLaser(self.x, self.y + bossGraphics.height * 0.75);
game.addChild(centerLaser);
enemyLasers.push(centerLaser);
// Right side laser
var rightLaser = new EnemyLaser(self.x + bossGraphics.width * 0.3, self.y + bossGraphics.height * 0.75);
game.addChild(rightLaser);
enemyLasers.push(rightLaser);
// Left side laser
var leftLaser = new EnemyLaser(self.x - bossGraphics.width * 0.3, self.y + bossGraphics.height * 0.75);
game.addChild(leftLaser);
enemyLasers.push(leftLaser);
};
});
// EnemyLaser class
var EnemyLaser = Container.expand(function (x, y) {
var self = Container.call(this);
var enemyLaserGraphics = self.attachAsset('enemylaser', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
self.x = x;
self.y = y;
self.speed = 10;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// EnemyShip class
var EnemyShip = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyship', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
self.shoot = function () {
var enemyLaser = new EnemyLaser(self.x, self.y + enemyGraphics.height / 2);
game.addChild(enemyLaser);
enemyLasers.push(enemyLaser);
};
});
// Laser class
var Laser = Container.expand(function (x, y) {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.speed = -15;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// SpaceShip class
var SpaceShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('spaceship', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
self.y = 2732 - 200;
};
self.shoot = function () {
var laser = new Laser(self.x, self.y - shipGraphics.height / 2);
game.addChild(laser);
lasers.push(laser);
LK.getSound('new_laser_sound_id').play();
};
});
// Star class
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -starGraphics.height;
self.x = Math.random() * 2048;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Removed incorrect sound play call
// Initialize arrays and variables
var spaceship;
var enemies = [];
var lasers = [];
var enemyLasers = [];
var stars = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var boss = null;
// Create spaceship
spaceship = new SpaceShip();
spaceship.x = 2048 / 2;
spaceship.y = 2732 - 200;
game.addChild(spaceship);
// Create and add stars
for (var i = 0; i < 50; i++) {
var star = new Star();
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
stars.push(star);
game.addChild(star);
}
// Spawn enemies
function spawnEnemy() {
var enemy = new EnemyShip();
enemy.x = Math.random() * 2048;
enemy.y = -100;
enemies.push(enemy);
game.addChild(enemy);
}
// Handle game updates
game.update = function () {
// Update spaceship
spaceship.update();
// Update stars
for (var i = stars.length - 1; i >= 0; i--) {
stars[i].update();
}
// Update lasers
for (var i = lasers.length - 1; i >= 0; i--) {
lasers[i].update();
if (lasers[i].y < 0) {
lasers[i].destroy();
lasers.splice(i, 1);
}
}
// Update enemy lasers
for (var i = enemyLasers.length - 1; i >= 0; i--) {
enemyLasers[i].update();
if (enemyLasers[i].y > 2732) {
enemyLasers[i].destroy();
enemyLasers.splice(i, 1);
}
}
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].y > 2732) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Check for collisions
for (var i = lasers.length - 1; i >= 0; i--) {
for (var j = enemies.length - 1; j >= 0; j--) {
if (lasers[i].intersects(enemies[j])) {
lasers[i].destroy();
var destroyEffect = LK.getAsset('destroy', {
anchorX: 0.5,
anchorY: 0.5,
x: enemies[j].x,
y: enemies[j].y
});
game.addChild(destroyEffect);
LK.setTimeout(function () {
destroyEffect.destroy();
}, 200);
LK.getSound('explosion').play();
enemies[j].destroy();
lasers.splice(i, 1);
enemies.splice(j, 1);
score++;
scoreTxt.setText(score);
if (score === 3 && !boss) {
boss = new Boss();
boss.x = 2048 / 2;
boss.y = -boss.height;
game.addChild(boss);
}
break;
}
}
if (boss && boss.intersects && lasers[i].intersects(boss)) {
lasers[i].destroy();
var destroyEffect = LK.getAsset('destroy', {
anchorX: 0.5,
anchorY: 0.5,
x: boss.x,
y: boss.y
});
game.addChild(destroyEffect);
LK.setTimeout(function () {
destroyEffect.destroy();
}, 200);
LK.getSound('explosion').play();
boss.health--;
if (boss.health <= 0) {
var kabomEffect = LK.getAsset('kabom', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3,
x: boss.x,
y: boss.y
});
game.addChild(kabomEffect);
LK.setTimeout(function () {
kabomEffect.destroy();
}, 1000);
LK.getSound('explosion').play();
boss.destroy();
boss = null;
}
lasers.splice(i, 1);
score++;
scoreTxt.setText(score);
break;
}
}
for (var i = enemyLasers.length - 1; i >= 0; i--) {
if (enemyLasers[i].intersects(spaceship)) {
enemyLasers[i].destroy();
enemyLasers.splice(i, 1);
// Flash screen red for 1 second (1000ms) to show we are dead.
LK.effects.flashScreen(0xff0000, 1000);
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state.
break;
}
}
// Spawn enemies periodically if boss is not present
if (!boss && LK.ticks % 60 == 0) {
spawnEnemy();
}
// Enemies shoot periodically if boss is not present
if (!boss && LK.ticks % 120 == 0) {
for (var i = 0; i < enemies.length; i++) {
enemies[i].shoot();
}
}
if (boss) {
boss.update();
if (LK.ticks % 60 == 0) {
boss.shoot();
}
}
};
// Handle touch events
game.down = function (x, y, obj) {
spaceship.shoot();
};
game.move = function (x, y, obj) {
spaceship.x = x;
};
game.up = function (x, y, obj) {
// No action needed on touch up
};
star white. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
enemy space ship boss it should be big and looking from top. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
linear laser red horizontal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red pixel circle with black background and hearth on middle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red circle with black background and bullet on middle next to x2 symbol. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.