Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: enemies is not defined' in this line: 'for (var i = 0; i < enemies.length; i++) {' Line Number: 85
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'length')' in this line: 'for (var i = 0; i < enemies.length; i++) {' Line Number: 9
Code edit (1 edits merged)
Please save this source code
User prompt
bullets should fly towards their target enemy
User prompt
put bullets in the bullets array so they update
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'length')' in this line: 'for (var i = 0; i < enemies.length; i++) {' Line Number: 9
User prompt
Fix Bug: 'Timeout.tick error: enemies is not defined' in this line: 'for (var i = 0; i < enemies.length; i++) {' Line Number: 8
User prompt
each tower shoots every second if enemy in range
User prompt
towers shoot at enemies within 300 pixels
Code edit (2 edits merged)
Please save this source code
User prompt
scale enemies to fit graphics
User prompt
when player clicks, also spawn an enemy
User prompt
make towers scale 2
User prompt
place a tower where player taps
User prompt
create a tower sprite
User prompt
remove the buttons
Code edit (1 edits merged)
Please save this source code
User prompt
if an enemy reaches the bottom of the screen, game is over
User prompt
why do enemies not show up
User prompt
inesrt an enemy at start
User prompt
enemy should have a graphics asset
User prompt
move all enemies every frame
Code edit (3 edits merged)
Please save this source code
User prompt
there should be graphics assets for the three buttons
var Tower = Container.expand(function () { var self = Container.call(this); var towerGraphics = self.createAsset('tower', 'Tower Graphics', .5, .5); self.shoot = function () {}; self.upgrade = function () {}; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('enemySprite', 'Enemy Sprite', .5, .5); enemyGraphics.height = 100; 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 () {}; self.hit = function () {}; }); 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 = []; var enemies = []; var bullets = []; var selectedTowerType = null; self.init = function () { var initialEnemy = new Enemy(); initialEnemy.x = Math.random() * 2048; initialEnemy.y = 0; enemies.push(initialEnemy); self.addChild(initialEnemy); LK.setInterval(function () { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = -newEnemy.height / 2; enemies.push(newEnemy); self.addChild(newEnemy); }, 2000); }; LK.on('tick', function () { for (var i = 0; i < enemies.length; i++) { enemies[i].move(); if (enemies[i].y >= 2732 - enemies[i].height / 2) { LK.showGameOver(); } } }); stage.on('down', function (obj) { if (self.selectedTowerType) { var position = obj.event.getLocalPosition(self); var newTower = self.addChild(new Tower(self.selectedTowerType)); newTower.x = position.x; newTower.y = position.y; towers.push(newTower); self.selectedTowerType = null; } }); stage.on('move', function (obj) {}); stage.on('up', function (obj) {}); });
===================================================================
--- original.js
+++ change.js
@@ -1,16 +1,4 @@
-var Button = Container.expand(function (label) {
- var self = Container.call(this);
- var buttonGraphics = self.createAsset(label.toLowerCase().replace(/\s/g, ''), label, 0.5, 0.5);
- buttonGraphics.width = 200;
- buttonGraphics.height = 160;
- buttonGraphics.alpha = 1;
- self.interactive = true;
- self.buttonMode = true;
- self.on('down', function () {
- self.parent.selectedTowerType = label;
- });
-});
var Tower = Container.expand(function () {
var self = Container.call(this);
var towerGraphics = self.createAsset('tower', 'Tower Graphics', .5, .5);
self.shoot = function () {};
@@ -42,19 +30,8 @@
var enemies = [];
var bullets = [];
var selectedTowerType = null;
self.init = function () {
- var buttonY = 0;
- var buttonSpacing = 2048 / 4;
- var button1 = self.addChild(new Button('Tower Type 1'));
- button1.x = buttonSpacing - button1.width / 2;
- button1.y = buttonY;
- var button2 = self.addChild(new Button('Tower Type 2'));
- button2.x = 2 * buttonSpacing - button2.width / 2;
- button2.y = buttonY;
- var button3 = self.addChild(new Button('Tower Type 3'));
- button3.x = 3 * buttonSpacing - button3.width / 2;
- button3.y = buttonY;
var initialEnemy = new Enemy();
initialEnemy.x = Math.random() * 2048;
initialEnemy.y = 0;
enemies.push(initialEnemy);
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.