Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (13 edits merged)
Please save this source code
User prompt
make a button under the instructiontext
Code edit (1 edits merged)
Please save this source code
Code edit (17 edits merged)
Please save this source code
User prompt
make a white label right after scorelabel, reading: Tap to build towers (cost 10 gold)\nDo not let enemies reach the city wall.
Code edit (1 edits merged)
Please save this source code
User prompt
instead of random delay, let each goldcoin spawn with a 100ms delay from the last one
User prompt
give each goldcoin animatino a short random delay
Code edit (1 edits merged)
Please save this source code
User prompt
make all goldcoins fly to 720, 2500 instead of to treasurechest
Code edit (9 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in this line: 'var t = new GoldCoin(this.x, this.y, this.game.treasureChest.x, this.game.treasureChest.y);' Line Number: 209
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in this line: 'var t = new GoldCoin(this.x, this.y, this.game.treasureChest.x, this.game.treasureChest.y);' Line Number: 209
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in this line: 'var t = new GoldCoin(this.x, this.y, this.game.treasureChest.x, this.game.treasureChest.y);' Line Number: 209
User prompt
make all coins fly to treasurechest instead of other places
Code edit (1 edits merged)
Please save this source code
User prompt
create a treasurechest sprite right after scorelabel
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'self.game.goldCoins.push(t);' Line Number: 21
User prompt
Fix Bug: 'ReferenceError: gameInstance is not defined' in this line: 'self.game = gameInstance;' Line Number: 5
User prompt
Fix Bug: 'ReferenceError: gameInstance is not defined' in this line: 'self.game = gameInstance;' Line Number: 5
User prompt
Fix Bug: 'ReferenceError: gameInstance is not defined' in this line: 'self.game = gameInstance;' Line Number: 5
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'addChild')' in this line: 'this.game.addChild(t);' Line Number: 19
User prompt
Fix Bug: 'ReferenceError: goldCoins is not defined' in this line: 'if (!goldCoins[l].parent) {' Line Number: 323
var playerGold = 30; var playerScore = 0; var GoldCoin = Container.expand(function (startX, startY, endX, endY) { var self = Container.call(this); var coinGraphics = self.createAsset('goldCoinSprite', 'Gold Coin Sprite', 0.5, 0.5); self.addChild(coinGraphics); self.x = startX; self.y = startY; var distance = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2)); var duration = 60; var vx = (endX - startX) / duration; var vy = (endY - startY) / duration; self.move = function () { self.x += vx; self.y += vy; if (--duration <= 0) { for (var i = 0; i < 4; i++) { var t = new GoldCoin(this.x, this.y, 200, 2700); this.game.addChild(t); self.game.goldCoins.push(t); } self.destroy(); } }; }); var CityWall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.createAsset('cityWallSprite', 'City Wall Sprite', 0.5, 0.5); self.addChild(wallGraphics); }); var TrollEnemy = Container.expand(function () { var self = Container.call(this); var trollGraphics = self.createAsset('trollSprite', 'Troll Enemy Sprite', .5, .5); trollGraphics.scale.set(2.5); self.hitpoints = 30; 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 < closestTower.width / 2 + this.width / 2) { closestTower.health -= 0.5; if (closestTower.health <= 0) { var towerIndex = self.game.towers.indexOf(closestTower); if (towerIndex > -1) { self.game.towers.splice(towerIndex, 1); } closestTower.destroy(); } } else if (closestTower && minDist < 100) { var avoidanceForce = 8; 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.zigzagCounter = this.zigzagCounter || 0; this.zigzagDirection = this.zigzagDirection || 1; if (this.zigzagCounter++ % self.zigzagTension === 0) this.zigzagDirection *= -1; this.x += 4 * this.zigzagDirection; this.y += 2; if (Math.random() < 0.01) { this.zigzagTension = Math.floor(Math.random() * 40) + 10; } if (this.x > 2048) { this.zigzagDirection = -1; } if (this.x < 0) { this.zigzagDirection = 1; } var scaleIncrement = (1 - 0.1) / 200; this.scale.x += scaleIncrement; this.scale.y += scaleIncrement; this.scale.x = Math.min(this.scale.x, 1); this.scale.y = Math.min(this.scale.y, 1); } }; self.die = function () { playerGold += 50; playerScore += 1111; this.game.updateScoreLabel(); this.game.updateGoldLabel(); for (var i = 0; i < 10; i++) { var t = new GoldCoin(this.x, this.y, 200, 2700); } var index = this.game.enemies.indexOf(this); if (index > -1) { this.game.enemies.splice(index, 1); } this.destroy(); }; }); var Tower = Container.expand(function (gameInstance) { var self = Container.call(this); self.game = gameInstance; 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.game.addBullet(bullet); break; } } } }; self.upgrade = function () {}; self.shootCounter = 0; self.health = 100; }); 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.zigzagTension = Math.floor(Math.random() * 40) + 10; 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 < closestTower.width / 2 + this.width / 2) { closestTower.health -= 0.5; if (closestTower.health <= 0) { var towerIndex = self.game.towers.indexOf(closestTower); if (towerIndex > -1) { self.game.towers.splice(towerIndex, 1); } closestTower.destroy(); } } else if (closestTower && minDist < 100) { var avoidanceForce = 8; 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.zigzagCounter = this.zigzagCounter || 0; this.zigzagDirection = this.zigzagDirection || 1; if (this.zigzagCounter++ % self.zigzagTension === 0) this.zigzagDirection *= -1; this.x += 4 * this.zigzagDirection; this.y += 2; if (Math.random() < 0.01) { this.zigzagTension = Math.floor(Math.random() * 40) + 10; } if (this.x > 2048) { this.zigzagDirection = -1; } if (this.x < 0) { this.zigzagDirection = 1; } var scaleIncrement = (1 - 0.1) / 200; this.scale.x += scaleIncrement; this.scale.y += scaleIncrement; this.scale.x = Math.min(this.scale.x, 1); this.scale.y = Math.min(this.scale.y, 1); } }; self.die = function () { playerGold += 5; playerScore += 100; this.game.updateScoreLabel(); this.game.updateGoldLabel(); for (var i = 0; i < 4; i++) { var t = new GoldCoin(this.x, this.y, 200, 2700); this.game.addChild(t); this.game.goldCoins.push(t); } 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.updateGoldLabel = function () { goldLabel.setText('Gold: ' + playerGold); }; self.updateScoreLabel = function () { scoreLabel.setText('Score: ' + playerScore); }; self.playerGold = 0; self.addBullet = function (bullet) { bullets.push(bullet); self.addChild(bullet); }; self.sufficientDistanceToOtherTowers = function (position) { for (var i = 0; i < self.towers.length; i++) { var tower = self.towers[i]; var dx = tower.x - position.x; var dy = tower.y - position.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 120) { return false; } } return true; }; 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 = []; self.goldCoins = []; var selectedTowerType = null; var initialEnemy = new Enemy(); initialEnemy.game = self; initialEnemy.x = 300 + Math.random() * (1848 - 300); initialEnemy.y = 200; initialEnemy.scale.set(0.1); self.enemies.push(initialEnemy); self.addChild(initialEnemy); LK.on('tick', function () { self.enemySpawnCounter = self.enemySpawnCounter || 0; self.totalEnemiesSpawned = self.totalEnemiesSpawned || 0; if (++self.enemySpawnCounter >= 120) { var newEnemy; if (self.totalEnemiesSpawned > 3 && self.totalEnemiesSpawned % 10 == 0) { newEnemy = new TrollEnemy(); } else { newEnemy = new Enemy(); } if (newEnemy) { newEnemy.game = self; newEnemy.x = 300 + Math.random() * (1848 - 300); newEnemy.y = 200; newEnemy.scale.set(0.1); self.enemies.push(newEnemy); self.addChild(newEnemy); } self.totalEnemiesSpawned++; self.enemySpawnCounter = 0; } for (var i = 0; i < self.enemies.length; i++) { self.enemies[i].move(); if (self.enemies[i].y >= 2332 - 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); } } for (var l = self.goldCoins.length - 1; l >= 0; l--) { self.goldCoins[l].move(); if (!self.goldCoins[l].parent) { self.goldCoins.splice(l, 1); } } }); stage.on('down', function (obj) { var position = obj.event.getLocalPosition(self); if (position.y >= 400 && position.y <= 2250) { if (playerGold >= 10) { if (self.sufficientDistanceToOtherTowers(position)) { playerGold -= 10; var newTower = self.addChild(new Tower(self)); newTower.x = position.x; newTower.y = position.y; self.towers.push(newTower); self.towers.sort(function (a, b) { return a.y - b.y; }); self.towers.forEach(function (tower, index) { self.addChildAt(tower, 6 + index); }); self.updateGoldLabel(); } } } }); stage.on('move', function (obj) {}); stage.on('up', function (obj) {}); var cityWall = self.addChild(new CityWall()); cityWall.y = 2632; cityWall.x = 332; cityWall.scale.y = 0.5; cityWall.scale.x = 0.5; var cityWall2 = self.addChild(new CityWall()); cityWall2.y = 2632; cityWall2.x = 1012; cityWall2.scale.y = 0.5; cityWall2.scale.x = 0.5; var cityWall3 = self.addChild(new CityWall()); cityWall3.y = 2632; cityWall3.x = 1691; cityWall3.scale.y = 0.5; cityWall3.scale.x = 0.5; var bottomBlackBox = self.createAsset('blackBox', 'Black Box at bottom', 0, 1); bottomBlackBox.width = 2048; bottomBlackBox.height = 400; bottomBlackBox.y = 2732; self.addChild(bottomBlackBox); var goldLabel = new Text2('Gold: 30', { size: 100, fill: '#ffd700', align: 'left' }); goldLabel.x = 120; goldLabel.y = 2632 - bottomBlackBox.height + (bottomBlackBox.height - goldLabel.height) / 2; self.addChild(goldLabel); var scoreLabel = new Text2('Score: 0', { size: 100, fill: '#ccbbff', align: 'left' }); scoreLabel.x = 120; scoreLabel.y = 2772 - bottomBlackBox.height + (bottomBlackBox.height - scoreLabel.height) / 2; self.addChild(scoreLabel); });
var playerGold = 30;
var playerScore = 0;
var GoldCoin = Container.expand(function (startX, startY, endX, endY) {
var self = Container.call(this);
var coinGraphics = self.createAsset('goldCoinSprite', 'Gold Coin Sprite', 0.5, 0.5);
self.addChild(coinGraphics);
self.x = startX;
self.y = startY;
var distance = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
var duration = 60;
var vx = (endX - startX) / duration;
var vy = (endY - startY) / duration;
self.move = function () {
self.x += vx;
self.y += vy;
if (--duration <= 0) {
for (var i = 0; i < 4; i++) {
var t = new GoldCoin(this.x, this.y, 200, 2700);
this.game.addChild(t);
self.game.goldCoins.push(t);
}
self.destroy();
}
};
});
var CityWall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.createAsset('cityWallSprite', 'City Wall Sprite', 0.5, 0.5);
self.addChild(wallGraphics);
});
var TrollEnemy = Container.expand(function () {
var self = Container.call(this);
var trollGraphics = self.createAsset('trollSprite', 'Troll Enemy Sprite', .5, .5);
trollGraphics.scale.set(2.5);
self.hitpoints = 30;
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 < closestTower.width / 2 + this.width / 2) {
closestTower.health -= 0.5;
if (closestTower.health <= 0) {
var towerIndex = self.game.towers.indexOf(closestTower);
if (towerIndex > -1) {
self.game.towers.splice(towerIndex, 1);
}
closestTower.destroy();
}
} else if (closestTower && minDist < 100) {
var avoidanceForce = 8;
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.zigzagCounter = this.zigzagCounter || 0;
this.zigzagDirection = this.zigzagDirection || 1;
if (this.zigzagCounter++ % self.zigzagTension === 0) this.zigzagDirection *= -1;
this.x += 4 * this.zigzagDirection;
this.y += 2;
if (Math.random() < 0.01) {
this.zigzagTension = Math.floor(Math.random() * 40) + 10;
}
if (this.x > 2048) {
this.zigzagDirection = -1;
}
if (this.x < 0) {
this.zigzagDirection = 1;
}
var scaleIncrement = (1 - 0.1) / 200;
this.scale.x += scaleIncrement;
this.scale.y += scaleIncrement;
this.scale.x = Math.min(this.scale.x, 1);
this.scale.y = Math.min(this.scale.y, 1);
}
};
self.die = function () {
playerGold += 50;
playerScore += 1111;
this.game.updateScoreLabel();
this.game.updateGoldLabel();
for (var i = 0; i < 10; i++) {
var t = new GoldCoin(this.x, this.y, 200, 2700);
}
var index = this.game.enemies.indexOf(this);
if (index > -1) {
this.game.enemies.splice(index, 1);
}
this.destroy();
};
});
var Tower = Container.expand(function (gameInstance) {
var self = Container.call(this);
self.game = gameInstance;
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.game.addBullet(bullet);
break;
}
}
}
};
self.upgrade = function () {};
self.shootCounter = 0;
self.health = 100;
});
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.zigzagTension = Math.floor(Math.random() * 40) + 10;
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 < closestTower.width / 2 + this.width / 2) {
closestTower.health -= 0.5;
if (closestTower.health <= 0) {
var towerIndex = self.game.towers.indexOf(closestTower);
if (towerIndex > -1) {
self.game.towers.splice(towerIndex, 1);
}
closestTower.destroy();
}
} else if (closestTower && minDist < 100) {
var avoidanceForce = 8;
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.zigzagCounter = this.zigzagCounter || 0;
this.zigzagDirection = this.zigzagDirection || 1;
if (this.zigzagCounter++ % self.zigzagTension === 0) this.zigzagDirection *= -1;
this.x += 4 * this.zigzagDirection;
this.y += 2;
if (Math.random() < 0.01) {
this.zigzagTension = Math.floor(Math.random() * 40) + 10;
}
if (this.x > 2048) {
this.zigzagDirection = -1;
}
if (this.x < 0) {
this.zigzagDirection = 1;
}
var scaleIncrement = (1 - 0.1) / 200;
this.scale.x += scaleIncrement;
this.scale.y += scaleIncrement;
this.scale.x = Math.min(this.scale.x, 1);
this.scale.y = Math.min(this.scale.y, 1);
}
};
self.die = function () {
playerGold += 5;
playerScore += 100;
this.game.updateScoreLabel();
this.game.updateGoldLabel();
for (var i = 0; i < 4; i++) {
var t = new GoldCoin(this.x, this.y, 200, 2700);
this.game.addChild(t);
this.game.goldCoins.push(t);
}
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.updateGoldLabel = function () {
goldLabel.setText('Gold: ' + playerGold);
};
self.updateScoreLabel = function () {
scoreLabel.setText('Score: ' + playerScore);
};
self.playerGold = 0;
self.addBullet = function (bullet) {
bullets.push(bullet);
self.addChild(bullet);
};
self.sufficientDistanceToOtherTowers = function (position) {
for (var i = 0; i < self.towers.length; i++) {
var tower = self.towers[i];
var dx = tower.x - position.x;
var dy = tower.y - position.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 120) {
return false;
}
}
return true;
};
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 = [];
self.goldCoins = [];
var selectedTowerType = null;
var initialEnemy = new Enemy();
initialEnemy.game = self;
initialEnemy.x = 300 + Math.random() * (1848 - 300);
initialEnemy.y = 200;
initialEnemy.scale.set(0.1);
self.enemies.push(initialEnemy);
self.addChild(initialEnemy);
LK.on('tick', function () {
self.enemySpawnCounter = self.enemySpawnCounter || 0;
self.totalEnemiesSpawned = self.totalEnemiesSpawned || 0;
if (++self.enemySpawnCounter >= 120) {
var newEnemy;
if (self.totalEnemiesSpawned > 3 && self.totalEnemiesSpawned % 10 == 0) {
newEnemy = new TrollEnemy();
} else {
newEnemy = new Enemy();
}
if (newEnemy) {
newEnemy.game = self;
newEnemy.x = 300 + Math.random() * (1848 - 300);
newEnemy.y = 200;
newEnemy.scale.set(0.1);
self.enemies.push(newEnemy);
self.addChild(newEnemy);
}
self.totalEnemiesSpawned++;
self.enemySpawnCounter = 0;
}
for (var i = 0; i < self.enemies.length; i++) {
self.enemies[i].move();
if (self.enemies[i].y >= 2332 - 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);
}
}
for (var l = self.goldCoins.length - 1; l >= 0; l--) {
self.goldCoins[l].move();
if (!self.goldCoins[l].parent) {
self.goldCoins.splice(l, 1);
}
}
});
stage.on('down', function (obj) {
var position = obj.event.getLocalPosition(self);
if (position.y >= 400 && position.y <= 2250) {
if (playerGold >= 10) {
if (self.sufficientDistanceToOtherTowers(position)) {
playerGold -= 10;
var newTower = self.addChild(new Tower(self));
newTower.x = position.x;
newTower.y = position.y;
self.towers.push(newTower);
self.towers.sort(function (a, b) {
return a.y - b.y;
});
self.towers.forEach(function (tower, index) {
self.addChildAt(tower, 6 + index);
});
self.updateGoldLabel();
}
}
}
});
stage.on('move', function (obj) {});
stage.on('up', function (obj) {});
var cityWall = self.addChild(new CityWall());
cityWall.y = 2632;
cityWall.x = 332;
cityWall.scale.y = 0.5;
cityWall.scale.x = 0.5;
var cityWall2 = self.addChild(new CityWall());
cityWall2.y = 2632;
cityWall2.x = 1012;
cityWall2.scale.y = 0.5;
cityWall2.scale.x = 0.5;
var cityWall3 = self.addChild(new CityWall());
cityWall3.y = 2632;
cityWall3.x = 1691;
cityWall3.scale.y = 0.5;
cityWall3.scale.x = 0.5;
var bottomBlackBox = self.createAsset('blackBox', 'Black Box at bottom', 0, 1);
bottomBlackBox.width = 2048;
bottomBlackBox.height = 400;
bottomBlackBox.y = 2732;
self.addChild(bottomBlackBox);
var goldLabel = new Text2('Gold: 30', {
size: 100,
fill: '#ffd700',
align: 'left'
});
goldLabel.x = 120;
goldLabel.y = 2632 - bottomBlackBox.height + (bottomBlackBox.height - goldLabel.height) / 2;
self.addChild(goldLabel);
var scoreLabel = new Text2('Score: 0', {
size: 100,
fill: '#ccbbff',
align: 'left'
});
scoreLabel.x = 120;
scoreLabel.y = 2772 - bottomBlackBox.height + (bottomBlackBox.height - scoreLabel.height) / 2;
self.addChild(scoreLabel);
});
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.