User prompt
make it so bullets dont hit dead enemies
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'destroy')' in or related to this line: 'bullets[j].destroy();' Line Number: 176
User prompt
make it so bullets dont get stuck on an enemy after it dies
User prompt
make enemies spawn in more often
User prompt
make a boss enemy that spawns in every once in a while with more health
User prompt
have enemies spawn
User prompt
make all enemies move towards player
User prompt
go back to before the sationary enemies
User prompt
the enemies are not spawning
User prompt
get rid of hero movement with keyboard
User prompt
make the enemies spawn from the top of the screen
User prompt
make enemies that come towards the player
User prompt
get rid of the spawn points
User prompt
make all enemies go towards the player
User prompt
bulletss are hitting dead enemies
User prompt
bullets keep getting locked at the closest enemy position
User prompt
make it so that only one enemy spawns at each position
User prompt
make stationary enemies spawn in a grid towards the top of the screen
User prompt
have enemies spawn in at certain positions and stay there
User prompt
fix bullets so they dont get stuck at a certain y
User prompt
make hero move with mouse but bound to same y level
Code edit (1 edits merged)
Please save this source code
User prompt
delete pause button
User prompt
pauseGame() is broken
User prompt
make it so p pauses
/**** * 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.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 = 3; self.update = function () { // Update logic for enemy // Move towards hero var dx = hero.x - self.x; var dy = hero.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { self.x += self.speed * dx / distance; self.y += self.speed * dy / distance; } }; self.takeDamage = function (amount) { self.health -= amount; if (self.health <= 0) { self.die(); } }; self.die = function () { // Handle enemy death self.destroy(); }; }); //<Assets used in the game will automatically appear here> // 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; 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 ****/ // Initialize hero var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 200; // 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; 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(); // Handle keyboard events for hero movement and game pause LK.on('keydown', function (event) { switch (event.key) { case 'w': // Move hero up hero.y -= hero.speed; break; case 'a': // Move hero left hero.x -= hero.speed; break; case 's': // Move hero down hero.y += hero.speed; break; case 'd': // Move hero right hero.x += hero.speed; break; } }); // 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); } } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { bullets[j].update(); for (var k = enemies.length - 1; k >= 0; k--) { if (bullets[j].intersects(enemies[k])) { enemies[k].takeDamage(20); bullets[j].destroy(); bullets.splice(j, 1); break; } } } // Spawn enemies periodically if (LK.ticks % 60 == 0) { spawnEnemy(); } }; game.move = function (x, y, obj) { hero.x = x; };
===================================================================
--- original.js
+++ change.js
@@ -10,9 +10,9 @@
});
self.speed = 10;
self.update = function () {
self.y -= self.speed;
- if (self.y < 0) {
+ if (self.y < 0 || self.y > 2732) {
self.destroy();
}
};
});