User prompt
towers cannot be placed at y < 400
Code edit (3 edits merged)
Please save this source code
User prompt
instead of appearing at top of screen, enemies should appear at y position 200 at scale 0.1 and scale up as they move down.
Code edit (2 edits merged)
Please save this source code
User prompt
place a black boxat bottom of screen covering full width.
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading '0')' in this line: 'var dx = towers[i].x - this.x;' Line Number: 42
User prompt
Fix Bug: 'ReferenceError: towers is not defined' in this line: 'towers.push(newTower);' Line Number: 157
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'for (var i = 0; i < towers.length; i++) {' Line Number: 41
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'for (var i = 0; i < towers.length; i++) {' Line Number: 41
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'for (var i = 0; i < towers.length; i++) {' Line Number: 41
User prompt
enemies should walk around towards instead of through them
User prompt
when enemies die, also remove them from enemies array
User prompt
make proper collision detection between enemies and bullets
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'playerGold')' in this line: 'this.parent.playerGold += 5;' Line Number: 42
Code edit (1 edits merged)
Please save this source code
User prompt
when enemy dies, give player 5 gold and destroy enemy
User prompt
when bullets hit enemy, destroy bullet and subtract hitpoints from enemy
Code edit (2 edits merged)
Please save this source code
User prompt
when bullets leave stage, destroy them
Code edit (1 edits merged)
Please save this source code
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
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; var tx = bullet.target.x - bullet.x; var ty = bullet.target.y - bullet.y; var rad = Math.atan2(ty, tx); bullet.rotation = rad + Math.PI / 2; bullet.vx = Math.cos(rad); bullet.vy = Math.sin(rad); self.parent.addBullet(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.hitpoints = 3; self.move = function (towers) { var minDist = Infinity; var closestTower = null; for (var i = 0; i < self.game.towers.length; i++) { var dx = self.game.towers[i].x - self.x; var dy = self.game.towers[i].y - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < minDist) { minDist = dist; closestTower = self.game.towers[i]; } } if (closestTower && minDist < 300) { var avoidanceForce = 5; var ax = this.x - closestTower.x; var ay = this.y - closestTower.y; var len = Math.sqrt(ax * ax + ay * ay); ax = ax / len * avoidanceForce; ay = ay / len * avoidanceForce; this.x += ax; this.y += ay; } else { this.y += 2; } }; self.die = function () { this.game.playerGold += 5; var index = this.game.enemies.indexOf(this); if (index > -1) { this.game.enemies.splice(index, 1); } this.destroy(); }; }); var Bullet = Container.expand(function () { var self = Container.call(this); self.game = null; var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5); bulletGraphics.scale.set(0.2); self.vx = 0; self.vy = 0; 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) { this.x += this.vx * 10; this.y += this.vy * 10; } if (dist < this.width / 2 + this.target.width / 2) { this.hit(); } else if (this.x < 0 || this.x > 2048 || this.y < 0 || this.y > 2732) { this.destroy(); } } }; self.hit = function () { this.target.hitpoints -= 1; if (this.target.hitpoints <= 0) { this.target.die(); } this.destroy(); }; }); var Game = Container.expand(function () { var self = Container.call(this); self.playerGold = 0; self.addBullet = function (bullet) { bullets.push(bullet); self.addChild(bullet); }; var background = self.createAsset('background', 'Background Image', 0, 0); background.width = 2048; background.height = 2732; background.y = 0; self.addChildAt(background, 0); self.towers = []; self.enemies = []; var bullets = []; var selectedTowerType = null; var initialEnemy = new Enemy(); initialEnemy.game = self; 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.game = self; 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 < self.towers.length; j++) { self.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; self.towers.push(newTower); var newEnemy = new Enemy(); newEnemy.game = self; newEnemy.x = Math.random() * 2048; newEnemy.y = -newEnemy.height / 2; self.enemies.push(newEnemy); self.addChild(newEnemy); }); stage.on('move', function (obj) {}); stage.on('up', function (obj) {}); });
===================================================================
--- original.js
+++ change.js
@@ -37,15 +37,15 @@
self.hitpoints = 3;
self.move = function (towers) {
var minDist = Infinity;
var closestTower = null;
- for (var i = 0; i < this.game.towers.length; i++) {
- var dx = towers[i].x - this.x;
- var dy = towers[i].y - this.y;
+ for (var i = 0; i < self.game.towers.length; i++) {
+ var dx = self.game.towers[i].x - self.x;
+ var dy = self.game.towers[i].y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < minDist) {
minDist = dist;
- closestTower = towers[i];
+ closestTower = self.game.towers[i];
}
}
if (closestTower && minDist < 300) {
var avoidanceForce = 5;
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.