Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'enemies')' in this line: 'self.self.enemies.push(newEnemy);' Line Number: 82
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 111
User prompt
use a counter instead of interval to spawn enemies
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'enemies')' in this line: 'self.self.enemies.push(newEnemy);' Line Number: 80
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 109
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'enemies')' in this line: 'self.self.enemies.push(newEnemy);' Line Number: 80
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 109
User prompt
rewrite setinterval to use a global counter instead
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'enemies')' in this line: 'self.self.enemies.push(newEnemy);' Line Number: 79
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 108
User prompt
how come towers don't shoot at enemies
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'enemies')' in this line: 'self.self.enemies.push(newEnemy);' Line Number: 79
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 108
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'enemies')' in this line: 'self.self.enemies.push(newEnemy);' Line Number: 79
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 108
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'self')' in this line: 'self.self.self.enemies.push(newEnemy);' Line Number: 79
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 110
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 110
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 110
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 110
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'enemies.push(newEnemy);' Line Number: 110
var Tower = Container.expand(function () { var self = Container.call(this); var towerGraphics = self.createAsset('towerSprite', 'Tower Sprite', .5, .5); towerGraphics.scale.set(2); self.shoot = function (enemies) {}; self.upgrade = function () {}; self.shootTimer = LK.setInterval(function () { var enemies = self.parent.enemies; for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; var dx = enemy.x - self.x; var dy = enemy.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance <= 300) { console.log('shot'); var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; bullet.target = enemy; self.parent.bullets.push(bullet); self.parent.addChild(bullet); break; } } }, 1000); }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('enemySprite', 'Enemy Sprite', .5, .5); enemyGraphics.scale.set(0.8); self.move = function () { self.y += 2; }; self.die = function () {}; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5); self.move = function () { if (this.target) { var tx = this.target.x - this.x; var ty = this.target.y - this.y; var dist = Math.sqrt(tx * tx + ty * ty); if (dist > 0) { var rad = Math.atan2(ty, tx); this.x += Math.cos(rad) * 5; this.y += Math.sin(rad) * 5; } if (dist < 5) { this.hit(); } } }; self.hit = function () { this.target.die(); this.destroy(); }; }); var Game = Container.expand(function () { var self = Container.call(this); var background = self.createAsset('background', 'Background Image', 0, 0); background.width = 2048; background.height = 2732; background.y = 0; self.addChildAt(background, 0); var towers = []; self.enemies = []; var bullets = []; var selectedTowerType = null; var initialEnemy = new Enemy(); initialEnemy.x = Math.random() * 2048; initialEnemy.y = 0; self.enemies.push(initialEnemy); self.addChild(initialEnemy); LK.setInterval(function () { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = -newEnemy.height / 2; self.enemies.push(newEnemy); self.addChild(newEnemy); }, 2000); LK.on('tick', function () { for (var i = 0; i < self.enemies.length; i++) { self.enemies[i].move(); if (self.enemies[i].y >= 2732 - self.enemies[i].height / 2) { LK.showGameOver(); } } for (var j = 0; j < towers.length; j++) { towers[j].shoot(self.enemies); } for (var k = bullets.length - 1; k >= 0; k--) { bullets[k].move(); if (!bullets[k].parent) { bullets.splice(k, 1); } } }); stage.on('down', function (obj) { var position = obj.event.getLocalPosition(self); var newTower = self.addChild(new Tower()); newTower.x = position.x; newTower.y = position.y; towers.push(newTower); var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = -newEnemy.height / 2; enemies.push(newEnemy); self.addChild(newEnemy); }); stage.on('move', function (obj) {}); stage.on('up', function (obj) {}); });
===================================================================
--- original.js
+++ change.js
@@ -86,9 +86,9 @@
LK.showGameOver();
}
}
for (var j = 0; j < towers.length; j++) {
- towers[j].shoot(enemies);
+ towers[j].shoot(self.enemies);
}
for (var k = bullets.length - 1; k >= 0; k--) {
bullets[k].move();
if (!bullets[k].parent) {
a medieval style stone tower. top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
an evil goblin. pixelart. top down view. In-Game asset. 2d. Blank background. High contrast. No shadows.
a silver sling bullet. pixelart. top down view. In-Game asset. 2d. Blank background. High contrast. No shadows.
brown wooden board. game gui style. 2048x400 pixels. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A medieval stone wall seen from the front. pixelart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A large scary troll. front top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A treasure chest. Medieval style. cartoony. Open and full of gold coins. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A metalic square button with the symbol of a tower from chess. Pixelart. Gamegui style. Medieval. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a medieval style stone tower. top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a medieval style stone tower. top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a medieval style stone tower. top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a medieval style stone tower. top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a medieval style stone tower. top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a medieval style stone tower. top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a colossal menacing black knight in heavy armor. pixelart game sprite. front view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a crossbow bolt made of bronze. straight. pixelart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a straight crossbow bolt made of gold. top down view. pixelart. bolt only, crossbow not included. vertical display, from bottom to top. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a straight crossbow bolt made of jade. top down view. pixelart. bolt only, crossbow not included. vertical display, from bottom to top. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a straight crossbow bolt made of cobalt. top down view. pixelart. bolt only, crossbow not included. vertical display, from bottom to top. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a straight magic missile. top down view. pixelart. bolt only, crossbow not included. vertical display, from bottom to top. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a yellow fire arrow, pointing up. top down view. pixelart. vertical. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A red hunting arrow, pointing straight up. Pixelart. Vertical view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A purple posion dart. Feathers pointing down in the picture. Pixelart.vertical. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
an orc warrior with a large head and red eyes. pixelart. top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A fierce balrog. Pixelart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A smooth round gold coin. Pixelart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An evil snotling flying on a dragonfly. front view. enemy character in a game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A flying red dragon breathing fire. side view. enemy character in a game. pixelart.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.