Code edit (1 edits merged)
Please save this source code
User prompt
bullets should be rotated on spawn to face the direction they're moving
User prompt
set bullet scale 0.2
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.parent.bullets.push(bullet);' Line Number: 18
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'gameInstance.bullets.push(bullet);' Line Number: 25
User prompt
use the global arrays for towers bullets and enemies
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'gameInstance.bullets.push(bullet);' Line Number: 25
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'return self.parent;' Line Number: 7
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.enemies.push(initialEnemy);' Line Number: 77
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.parent.bullets.push(bullet);' Line Number: 18
User prompt
Fix Bug: 'TypeError: self.getGameInstance is not a function' in this line: 'self.getGameInstance().bullets.push(bullet);' Line Number: 18
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.parent.bullets.push(bullet);' Line Number: 18
User prompt
Fix Bug: 'TypeError: self.getGameInstance is not a function' in this line: 'self.getGameInstance().bullets.push(bullet);' Line Number: 18
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.parent.bullets.push(bullet);' Line Number: 18
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
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
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
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
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.enemies.push(initialEnemy);' Line Number: 74
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) { if (self.shootCounter++ % 60 === 0) { 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; } } } }; self.upgrade = function () {}; self.shootCounter = 0; }); 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.on('tick', function () { self.enemySpawnCounter = self.enemySpawnCounter || 0; if (++self.enemySpawnCounter >= 120) { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = -newEnemy.height / 2; self.enemies.push(newEnemy); self.addChild(newEnemy); self.enemySpawnCounter = 0; } 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
@@ -78,9 +78,9 @@
if (++self.enemySpawnCounter >= 120) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = -newEnemy.height / 2;
- self.self.enemies.push(newEnemy);
+ self.enemies.push(newEnemy);
self.addChild(newEnemy);
self.enemySpawnCounter = 0;
}
for (var i = 0; i < self.enemies.length; i++) {
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.