User prompt
also make boss hp 3
User prompt
when boss destroyed the should be huge explonation using kabom asset
User prompt
make bosses hp 50
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in or related to this line: 'if (boss && lasers[i].intersects(boss)) {' Line Number: 254
User prompt
so we counter a bug, we can't hit boss right now
User prompt
lets make boss hp equal to other ships for now
User prompt
boss right and left shooter should little bit closer to middle one
User prompt
boss also can shoot lasers from right and left side of their texture
User prompt
make boss hp 50
User prompt
boss spawning score is 3 now
User prompt
make boss bigger
User prompt
half of the boss is going out of screen when its gets to right or left side of screen, because of that lets make boss horizontal movement range little bit shorter
User prompt
boss horizontal movement should be little bit slower
User prompt
everything god but boss can stops at little bit higher
User prompt
when boss gets middle of the screen it stops going down and starts horizontal movement
User prompt
when player gets 10 score and boss spawnes other enemyships stops spawning
User prompt
add boss to game using boss asset but boss only appear when player get score 10
User prompt
make enemies laser x1.5 bigger
User prompt
add explosion sound for destroy
User prompt
i change laser sound make sure you add the new one
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'sound')' in or related to this line: 'LK.init.sound('lasersound').play();' Line Number: 118
Code edit (1 edits merged)
Please save this source code
User prompt
laser sound is gone add it again
User prompt
now another bug , ship that i shoot stays but another one is dissapers
User prompt
bug still alive, you only destroy the ship i shot
/**** * 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, 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 };
===================================================================
--- original.js
+++ change.js
@@ -11,9 +11,9 @@
scaleY: 1.5
});
self.speed = 2;
self.horizontalSpeed = 2;
- self.health = 50;
+ self.health = 3;
self.update = function () {
if (self.y < 2732 / 3 - bossGraphics.height / 4) {
self.y += self.speed;
} else {
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.