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.update = function () { // Update logic for enemy // Calculate direction towards hero var dx = hero.x - self.x; var dy = hero.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); // Normalize the direction if (distance > 0) { dx /= distance; dy /= distance; } // Move towards the hero self.x += dx * self.speed; self.y += dy * self.speed; }; self.takeDamage = function (amount) { self.health -= amount; if (self.health <= 0) { self.die(); } }; self.die = function () { // Handle enemy death self.destroy(); }; }); // BossEnemy class var BossEnemy = Enemy.expand(function () { var self = Enemy.call(this); self.health = 200; // BossEnemy has more health }); //<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 and spawn position var enemies = []; var spawnY = 0; // Initialize bullets array var bullets = []; // 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); } // Spawn new enemy at the top of the screen every 30 frames if (LK.ticks % 30 == 0) { var enemy; if (LK.ticks % 600 == 0) { // Spawn BossEnemy every 600 frames enemy = new BossEnemy(); } else { enemy = new Enemy(); } enemy.x = Math.random() * 2048; // Random x position enemy.y = 0; // Spawn at the top of the screen enemies.push(enemy); game.addChild(enemy); } } // 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] && enemies[k].health > 0 && bullets[j].intersects(enemies[k])) { enemies[k].takeDamage(20); bullets[j].destroy(); bullets.splice(j, 1); break; } } } }; game.move = function (x, y, obj) { hero.x = x; };
===================================================================
--- original.js
+++ change.js
@@ -131,10 +131,10 @@
hero.takeDamage(10);
enemies[i].destroy();
enemies.splice(i, 1);
}
- // Spawn new enemy at the top of the screen every 60 frames
- if (LK.ticks % 60 == 0) {
+ // Spawn new enemy at the top of the screen every 30 frames
+ if (LK.ticks % 30 == 0) {
var enemy;
if (LK.ticks % 600 == 0) {
// Spawn BossEnemy every 600 frames
enemy = new BossEnemy();