User prompt
Please fix the bug: 'ReferenceError: bullets is not defined' in or related to this line: 'npcs.splice(j, 1); // Remove NPC from array' Line Number: 287
User prompt
Please fix the bug: 'Uncaught ReferenceError: player is not defined' in or related to this line: 'player.x = x;' Line Number: 262
User prompt
Please fix the bug: 'Uncaught ReferenceError: player is not defined' in or related to this line: 'player.x = x;' Line Number: 262
User prompt
Please fix the bug: 'ReferenceError: enemies is not defined' in or related to this line: 'for (var i = 0; i < enemies.length; i++) {' Line Number: 276
User prompt
Please fix the bug: 'ReferenceError: enemies is not defined' in or related to this line: 'for (var i = 0; i < enemies.length; i++) {' Line Number: 276
User prompt
Please fix the bug: 'ReferenceError: enemies is not defined' in or related to this line: 'for (var i = 0; i < enemies.length; i++) {' Line Number: 276
User prompt
make a menu screen
User prompt
remove bullet
User prompt
add menu screen
User prompt
increase enemy speed and NPC to 20
User prompt
make enemy chase all of the NPCs then chase player after killing all of the NPCs
User prompt
increase NPC count to 19
User prompt
MAKE THE enemy chasing NPC and after enemy killing NPC, then chase player
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'x')' in or related to this line: 'var dxNpc = npc.x - self.x;' Line Number: 58
User prompt
please fix any bugs
User prompt
make the enemy can chase player and NPC
User prompt
make the enemy can chasing NPC
User prompt
make the enemy can killing NPC
User prompt
make the NPC walk everywhere across the screen
User prompt
make the NPC run away from enemy
User prompt
make the NPC spawned same as player
User prompt
make the NPC not bounced because of the trees
User prompt
make the NPC not detect the tree
User prompt
make the NPC speed looks like enemy
User prompt
make the NPC cant collide with the trees
===================================================================
--- original.js
+++ change.js
@@ -1,19 +1,7 @@
/****
* Classes
****/
-// Define a 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;
- };
-});
// Define an Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyBody = self.attachAsset('enemyBody', {
@@ -221,24 +209,13 @@
npc.x = Math.random() * 2048;
npc.y = Math.random() * 2732;
npcs.push(npc);
}
-// Initialize bullets
-var bullets = [];
-// Handle player movement
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
};
// Handle shooting
-game.down = function (x, y, obj) {
- var bullet = new Bullet();
- bullet.x = player.x;
- bullet.y = player.y;
- bullets.push(bullet);
- game.addChild(bullet);
-};
-// Game update loop
game.update = function () {
// Update enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
@@ -254,24 +231,8 @@
}
}
}
// 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] && bullets[j].intersects(enemies[k])) {
- bullets[j].destroy();
- bullets.splice(j, 1);
- enemies[k].destroy();
- enemies.splice(k, 1);
- break;
- }
- }
- if (bullets[j] && bullets[j].y < -50) {
- bullets[j].destroy();
- bullets.splice(j, 1);
- }
- }
};
game.start = function () {
// Initialize player
var player = game.addChild(new Player());
@@ -299,24 +260,13 @@
npc.x = Math.random() * 2048;
npc.y = Math.random() * 2732;
npcs.push(npc);
}
- // Initialize bullets
- var bullets = [];
- // Handle player movement
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
};
// Handle shooting
- game.down = function (x, y, obj) {
- var bullet = new Bullet();
- bullet.x = player.x;
- bullet.y = player.y;
- bullets.push(bullet);
- game.addChild(bullet);
- };
- // Game update loop
game.update = function () {
// Update enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
@@ -332,24 +282,8 @@
}
}
}
// 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] && bullets[j].intersects(enemies[k])) {
- bullets[j].destroy();
- bullets.splice(j, 1);
- enemies[k].destroy();
- enemies.splice(k, 1);
- break;
- }
- }
- if (bullets[j] && bullets[j].y < -50) {
- bullets[j].destroy();
- bullets.splice(j, 1);
- }
- }
};
};
game.showInstructions = function () {
var instructions = "Welcome to Night of the Massacre 2! \n\n" + "You are the yellow player. Use your mouse or touch to move around. \n\n" + "Click or tap to shoot bullets. \n\n" + "Your goal is to protect the NPCs (non-player characters) from the red enemies. \n\n" + "If an enemy touches you, it's game over! \n\n" + "Good luck!";