/**** * Classes ****/ var Archer = Container.expand(function (isPlayer) { var self = Container.call(this, isPlayer); var archerGraphics = isPlayer ? LK.getAsset('playerArcher', {}) : LK.getAsset('enemyArcher', {}); archerGraphics.anchor.set(.5, .5); self.addChild(archerGraphics); var shadow = LK.getAsset('shadow', {}); shadow.alpha = 0.2; shadow.anchor.set(.5, .5); shadow.y = 185; self.addChildAt(shadow, 0); self.health = 1500; self.range = 1500; self.moneyReward = 200; var healthBar = self.addChild(new HealthBar()); healthBar.y = -archerGraphics.height / 2 - 10; self.speed = 4; this.move = function (soldiers, enemies) { var index = soldiers.indexOf(this); if (index > 0 && this.intersects(soldiers[index - 1])) { return; } for (var i = 0; i < enemies.length; i++) { if (this.intersects(enemies[i])) { return; } } this.x += self.speed; }; this.shoot = function (enemies) { for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; if (Math.abs(this.x - enemy.x) <= self.range && LK.ticks % 60 == 0) { var bullet = new Bullet(isPlayer); bullet.x = this.x; bullet.y = this.y; return bullet; } } return null; }; this.takeDamage = function (damage) { this.health -= damage; healthBar.updateHealth(this.health, 1500); if (this.health <= 0) { this.destroy(); return true; } return false; }; }); var Bullet = Container.expand(function (isPlayer) { var self = Container.call(this); var bulletGraphics = isPlayer ? LK.getAsset('playerBullet', {}) : LK.getAsset('enemyBullet', {}); bulletGraphics.anchor.set(.5, .5); self.addChild(bulletGraphics); self.speed = isPlayer ? 10 : -10; this.move = function () { this.x += self.speed; }; }); var EnemyBase = Container.expand(function () { var self = Container.call(this); var baseGraphics = LK.getAsset('enemyBase', {}); console.warn(baseGraphics.width); baseGraphics.anchor.set(1, 1); self.addChild(baseGraphics); self.health = 10000; var healthBar = self.addChild(new HealthBar()); healthBar.scale.set(3, 3); healthBar.y = -baseGraphics.height - 20; healthBar.x = -baseGraphics.width / 2; this.takeDamage = function (damage) { this.health -= damage; healthBar.updateHealth(this.health, 10000); if (this.health <= 0) { currentLevel++; if (currentLevel > 3) { alert('You won the game!'); restartGame(); } else { alert('Level ' + currentLevel + ' start!'); enemyBase.health = 10000; enemyBase.children[1].updateHealth(enemyBase.health, 10000); } return true; } return false; }; }); var Ground = Container.expand(function () { var self = Container.call(this); var groundGraphics = LK.getAsset('ground', {}); groundGraphics.anchor.set(.5, 0); self.addChild(groundGraphics); }); var HealthBar = Container.expand(function () { var self = Container.call(this); var healthBarGraphics = LK.getAsset('healthBar', {}); healthBarGraphics.anchor.set(.5, .5); self.addChild(healthBarGraphics); this.updateHealth = function (health, maxHealth) { healthBarGraphics.scale.x = health / maxHealth; }; }); var PlayerBase = Container.expand(function () { var self = Container.call(this); var baseGraphics = LK.getAsset('base', {}); console.warn(baseGraphics.width); baseGraphics.anchor.set(0, 1); self.addChild(baseGraphics); self.health = 10000; var healthBar = self.addChild(new HealthBar()); healthBar.scale.set(3, 3); healthBar.y = -baseGraphics.height - 20; healthBar.x = baseGraphics.width / 2; this.takeDamage = function (damage) { this.health -= damage; healthBar.updateHealth(this.health, 10000); if (this.health <= 0) { return true; } return false; }; }); var Soldier = Container.expand(function (isPlayer) { var self = Container.call(this); var soldierGraphics = isPlayer ? LK.getAsset('playerSoldier', {}) : LK.getAsset('enemySoldier', {}); soldierGraphics.anchor.set(.5, .5); self.addChild(soldierGraphics); var shadow = LK.getAsset('shadow', {}); shadow.alpha = 0.2; shadow.anchor.set(.5, .5); shadow.y = 185; self.addChildAt(shadow, 0); self.health = 2000; self.moneyReward = 100; var healthBar = self.addChild(new HealthBar()); healthBar.y = -soldierGraphics.height / 2 - 10; self.speed = 5; this.move = function (soldiers, enemies) { var index = soldiers.indexOf(this); if (index > 0 && this.intersects(soldiers[index - 1])) { return; } for (var i = 0; i < enemies.length; i++) { if (this.intersects(enemies[i])) { return; } } this.x += self.speed; }; this.takeDamage = function (damage) { this.health -= damage; healthBar.updateHealth(this.health, 2000); if (this.health <= 0) { this.destroy(); return true; } return false; }; }); var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = LK.getAsset('tree' + Math.ceil(Math.random() * 5), {}); treeGraphics.anchor.set(.5, 1); self.addChild(treeGraphics); self.y = 2732 - 50; }); var World = Container.expand(function () { var self = Container.call(this); var ground = self.addChild(new Ground()); ground.y = 2732 - 150; for (var i = 0; i < 100; i++) { var tree = self.addChild(new Tree()); tree.x = Math.random() * 2048 * 4; } }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var currentLevel = 1; game.setBackgroundColor(0x87CEEB); var world = game.addChild(new World()); var startText = new Text2('Defend your base', { size: 120, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", fill: "#ffffff", dropShadow: true, dropShadowColor: "#000000", dropShadowBlur: 4, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); startText.anchor.set(.5, .5); startText.x = 2048 / 2; startText.y = 2732 / 2; game.addChild(startText); LK.setTimeout(function () { startText.destroy(); }, 4000); var playerBase = world.addChild(new PlayerBase()); playerBase.x = 0; playerBase.y = 2732; var enemyBase = world.addChild(new EnemyBase()); enemyBase.x = 2048 * 4; enemyBase.y = 2732; var playerSoldiers = []; var enemySoldiers = []; var playerBullets = []; var enemyBullets = []; var playerMoney = 1000; var enemyMoney = 1000; var nextEnemy = Math.random() < 0.5 ? 'soldier' : 'archer'; var xp = 0; var moneyTxt = new Text2('Money: ' + playerMoney, { size: 30, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", fill: "#ffffff" }); moneyTxt.anchor.set(1, 0); LK.gui.topRight.addChild(moneyTxt); var xpTxt = new Text2('XP: ' + xp, { size: 30, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", fill: "#ffffff" }); xpTxt.y = 60; xpTxt.anchor.set(1, 0); LK.gui.topRight.addChild(xpTxt); var buttonGraphics1 = LK.getAsset('button', {}); buttonGraphics1.anchor.set(1, 0); buttonGraphics1.y = 120; LK.gui.topRight.addChild(buttonGraphics1); buttonGraphics1.on('down', function () { spawnSoldier(true); }); var buttonGraphics2 = LK.getAsset('newButton', {}); buttonGraphics2.anchor.set(1, 0); buttonGraphics2.y = 120; buttonGraphics2.x = buttonGraphics1.x - buttonGraphics1.width - 10; LK.gui.topRight.addChild(buttonGraphics2); buttonGraphics2.on('down', function () { spawnArcher(true); }); function spawnSoldier(isPlayer) { if (isPlayer ? playerMoney >= 100 : enemyMoney >= 100) { isPlayer ? playerMoney -= 100 : enemyMoney -= 100; var soldier = new Soldier(isPlayer); soldier.health *= currentLevel; soldier.speed *= currentLevel; soldier.x = isPlayer ? playerBase.x + playerBase.width / 2 : enemyBase.x - enemyBase.width / 2; soldier.y = 2732 - soldier.height / 2; soldier.speed = isPlayer ? 5 : -5; world.addChild(soldier); if (isPlayer) { playerSoldiers.push(soldier); } else { enemySoldiers.push(soldier); } } } function spawnArcher(isPlayer) { if (isPlayer ? playerMoney >= 200 : enemyMoney >= 200) { isPlayer ? playerMoney -= 200 : enemyMoney -= 200; var archer = new Archer(isPlayer); archer.health *= currentLevel; archer.speed *= currentLevel; archer.range *= currentLevel; archer.x = isPlayer ? playerBase.x + playerBase.width / 2 : enemyBase.x - enemyBase.width / 2; archer.y = 2732 - archer.height / 2; archer.speed = isPlayer ? 8 : -8; world.addChild(archer); if (isPlayer) { playerSoldiers.push(archer); } else { enemySoldiers.push(archer); } } } function handleTick() { for (var i = 0; i < playerSoldiers.length; i++) { var soldier = playerSoldiers[i]; soldier.move(playerSoldiers, enemySoldiers); if (soldier instanceof Archer) { var bullet = soldier.shoot(enemySoldiers); if (bullet) { world.addChild(bullet); playerBullets.push(bullet); } } for (var j = 0; j < enemySoldiers.length; j++) { var enemy = enemySoldiers[j]; if (soldier.intersects(enemy)) { if (soldier.takeDamage(10)) { playerSoldiers.splice(i, 1); i--; enemyMoney += soldier.moneyReward; } if (enemy.takeDamage(10)) { enemySoldiers.splice(j, 1); j--; playerMoney += enemy.moneyReward; } } } if (soldier.intersects(enemyBase)) { if (enemyBase.takeDamage(50)) { alert("You won"); restartGame(); } else { soldier.speed = 0; } } } for (var i = 0; i < enemySoldiers.length; i++) { var soldier = enemySoldiers[i]; soldier.move(enemySoldiers, playerSoldiers); if (soldier instanceof Archer) { var bullet = soldier.shoot(playerSoldiers); if (bullet) { world.addChild(bullet); enemyBullets.push(bullet); } } if (soldier.intersects(playerBase)) { if (playerBase.takeDamage(50)) { LK.showGameOver(restartGame); } else { soldier.speed = 0; } } } if (LK.ticks % 60 == 0) { if (nextEnemy === 'soldier' && enemyMoney >= 100) { spawnSoldier(false); nextEnemy = Math.random() < 0.5 ? 'soldier' : 'archer'; } else if (nextEnemy === 'archer' && enemyMoney >= 200) { spawnArcher(false); nextEnemy = Math.random() < 0.5 ? 'soldier' : 'archer'; } } for (var i = 0; i < playerBullets.length; i++) { var bullet = playerBullets[i]; bullet.move(); for (var j = 0; j < enemySoldiers.length; j++) { var enemy = enemySoldiers[j]; if (bullet.intersects(enemy)) { if (enemy.takeDamage(100)) { enemySoldiers.splice(j, 1); j--; playerMoney += enemy.moneyReward; } bullet.destroy(); playerBullets.splice(i, 1); i--; } } } for (var i = 0; i < enemyBullets.length; i++) { var bullet = enemyBullets[i]; bullet.move(); for (var j = 0; j < playerSoldiers.length; j++) { var soldier = playerSoldiers[j]; if (bullet.intersects(soldier)) { if (soldier.takeDamage(100)) { playerSoldiers.splice(j, 1); j--; enemyMoney += soldier.moneyReward; } bullet.destroy(); enemyBullets.splice(i, 1); i--; } } } moneyTxt.setText('Player Money: ' + playerMoney + ' Enemy Money: ' + enemyMoney); xpTxt.setText('XP: ' + xp); } LK.on('tick', handleTick); var dragWorld = null; var initialMousePos = null; game.on('down', function (obj) { dragWorld = world; initialMousePos = obj.event.getLocalPosition(game); }); game.on('move', function (obj) { if (dragWorld && initialMousePos) { var event = obj.event; var pos = event.getLocalPosition(game); var newX = dragWorld.x + pos.x - initialMousePos.x; if (newX > 0) { newX = 0; } else if (newX < game.width - 2048 * 5) { newX = game.width - 2048 * 5; } dragWorld.x = newX; initialMousePos = pos; } }); game.on('up', function (obj) { dragWorld = null; initialMousePos = null; }); function restartGame() { playerBase.health = 10000; playerBase.children[1].updateHealth(playerBase.health, 10000); enemyBase.health = 10000; enemyBase.children[1].updateHealth(enemyBase.health, 10000); playerMoney = 1000; enemyMoney = 1000; xp = 0; for (var i = 0; i < playerSoldiers.length; i++) { playerSoldiers[i].destroy(); } for (var i = 0; i < enemySoldiers.length; i++) { enemySoldiers[i].destroy(); } playerSoldiers = []; enemySoldiers = []; }
/****
* Classes
****/
var Archer = Container.expand(function (isPlayer) {
var self = Container.call(this, isPlayer);
var archerGraphics = isPlayer ? LK.getAsset('playerArcher', {}) : LK.getAsset('enemyArcher', {});
archerGraphics.anchor.set(.5, .5);
self.addChild(archerGraphics);
var shadow = LK.getAsset('shadow', {});
shadow.alpha = 0.2;
shadow.anchor.set(.5, .5);
shadow.y = 185;
self.addChildAt(shadow, 0);
self.health = 1500;
self.range = 1500;
self.moneyReward = 200;
var healthBar = self.addChild(new HealthBar());
healthBar.y = -archerGraphics.height / 2 - 10;
self.speed = 4;
this.move = function (soldiers, enemies) {
var index = soldiers.indexOf(this);
if (index > 0 && this.intersects(soldiers[index - 1])) {
return;
}
for (var i = 0; i < enemies.length; i++) {
if (this.intersects(enemies[i])) {
return;
}
}
this.x += self.speed;
};
this.shoot = function (enemies) {
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
if (Math.abs(this.x - enemy.x) <= self.range && LK.ticks % 60 == 0) {
var bullet = new Bullet(isPlayer);
bullet.x = this.x;
bullet.y = this.y;
return bullet;
}
}
return null;
};
this.takeDamage = function (damage) {
this.health -= damage;
healthBar.updateHealth(this.health, 1500);
if (this.health <= 0) {
this.destroy();
return true;
}
return false;
};
});
var Bullet = Container.expand(function (isPlayer) {
var self = Container.call(this);
var bulletGraphics = isPlayer ? LK.getAsset('playerBullet', {}) : LK.getAsset('enemyBullet', {});
bulletGraphics.anchor.set(.5, .5);
self.addChild(bulletGraphics);
self.speed = isPlayer ? 10 : -10;
this.move = function () {
this.x += self.speed;
};
});
var EnemyBase = Container.expand(function () {
var self = Container.call(this);
var baseGraphics = LK.getAsset('enemyBase', {});
console.warn(baseGraphics.width);
baseGraphics.anchor.set(1, 1);
self.addChild(baseGraphics);
self.health = 10000;
var healthBar = self.addChild(new HealthBar());
healthBar.scale.set(3, 3);
healthBar.y = -baseGraphics.height - 20;
healthBar.x = -baseGraphics.width / 2;
this.takeDamage = function (damage) {
this.health -= damage;
healthBar.updateHealth(this.health, 10000);
if (this.health <= 0) {
currentLevel++;
if (currentLevel > 3) {
alert('You won the game!');
restartGame();
} else {
alert('Level ' + currentLevel + ' start!');
enemyBase.health = 10000;
enemyBase.children[1].updateHealth(enemyBase.health, 10000);
}
return true;
}
return false;
};
});
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = LK.getAsset('ground', {});
groundGraphics.anchor.set(.5, 0);
self.addChild(groundGraphics);
});
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var healthBarGraphics = LK.getAsset('healthBar', {});
healthBarGraphics.anchor.set(.5, .5);
self.addChild(healthBarGraphics);
this.updateHealth = function (health, maxHealth) {
healthBarGraphics.scale.x = health / maxHealth;
};
});
var PlayerBase = Container.expand(function () {
var self = Container.call(this);
var baseGraphics = LK.getAsset('base', {});
console.warn(baseGraphics.width);
baseGraphics.anchor.set(0, 1);
self.addChild(baseGraphics);
self.health = 10000;
var healthBar = self.addChild(new HealthBar());
healthBar.scale.set(3, 3);
healthBar.y = -baseGraphics.height - 20;
healthBar.x = baseGraphics.width / 2;
this.takeDamage = function (damage) {
this.health -= damage;
healthBar.updateHealth(this.health, 10000);
if (this.health <= 0) {
return true;
}
return false;
};
});
var Soldier = Container.expand(function (isPlayer) {
var self = Container.call(this);
var soldierGraphics = isPlayer ? LK.getAsset('playerSoldier', {}) : LK.getAsset('enemySoldier', {});
soldierGraphics.anchor.set(.5, .5);
self.addChild(soldierGraphics);
var shadow = LK.getAsset('shadow', {});
shadow.alpha = 0.2;
shadow.anchor.set(.5, .5);
shadow.y = 185;
self.addChildAt(shadow, 0);
self.health = 2000;
self.moneyReward = 100;
var healthBar = self.addChild(new HealthBar());
healthBar.y = -soldierGraphics.height / 2 - 10;
self.speed = 5;
this.move = function (soldiers, enemies) {
var index = soldiers.indexOf(this);
if (index > 0 && this.intersects(soldiers[index - 1])) {
return;
}
for (var i = 0; i < enemies.length; i++) {
if (this.intersects(enemies[i])) {
return;
}
}
this.x += self.speed;
};
this.takeDamage = function (damage) {
this.health -= damage;
healthBar.updateHealth(this.health, 2000);
if (this.health <= 0) {
this.destroy();
return true;
}
return false;
};
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = LK.getAsset('tree' + Math.ceil(Math.random() * 5), {});
treeGraphics.anchor.set(.5, 1);
self.addChild(treeGraphics);
self.y = 2732 - 50;
});
var World = Container.expand(function () {
var self = Container.call(this);
var ground = self.addChild(new Ground());
ground.y = 2732 - 150;
for (var i = 0; i < 100; i++) {
var tree = self.addChild(new Tree());
tree.x = Math.random() * 2048 * 4;
}
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var currentLevel = 1;
game.setBackgroundColor(0x87CEEB);
var world = game.addChild(new World());
var startText = new Text2('Defend your base', {
size: 120,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff",
dropShadow: true,
dropShadowColor: "#000000",
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
startText.anchor.set(.5, .5);
startText.x = 2048 / 2;
startText.y = 2732 / 2;
game.addChild(startText);
LK.setTimeout(function () {
startText.destroy();
}, 4000);
var playerBase = world.addChild(new PlayerBase());
playerBase.x = 0;
playerBase.y = 2732;
var enemyBase = world.addChild(new EnemyBase());
enemyBase.x = 2048 * 4;
enemyBase.y = 2732;
var playerSoldiers = [];
var enemySoldiers = [];
var playerBullets = [];
var enemyBullets = [];
var playerMoney = 1000;
var enemyMoney = 1000;
var nextEnemy = Math.random() < 0.5 ? 'soldier' : 'archer';
var xp = 0;
var moneyTxt = new Text2('Money: ' + playerMoney, {
size: 30,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff"
});
moneyTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(moneyTxt);
var xpTxt = new Text2('XP: ' + xp, {
size: 30,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff"
});
xpTxt.y = 60;
xpTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(xpTxt);
var buttonGraphics1 = LK.getAsset('button', {});
buttonGraphics1.anchor.set(1, 0);
buttonGraphics1.y = 120;
LK.gui.topRight.addChild(buttonGraphics1);
buttonGraphics1.on('down', function () {
spawnSoldier(true);
});
var buttonGraphics2 = LK.getAsset('newButton', {});
buttonGraphics2.anchor.set(1, 0);
buttonGraphics2.y = 120;
buttonGraphics2.x = buttonGraphics1.x - buttonGraphics1.width - 10;
LK.gui.topRight.addChild(buttonGraphics2);
buttonGraphics2.on('down', function () {
spawnArcher(true);
});
function spawnSoldier(isPlayer) {
if (isPlayer ? playerMoney >= 100 : enemyMoney >= 100) {
isPlayer ? playerMoney -= 100 : enemyMoney -= 100;
var soldier = new Soldier(isPlayer);
soldier.health *= currentLevel;
soldier.speed *= currentLevel;
soldier.x = isPlayer ? playerBase.x + playerBase.width / 2 : enemyBase.x - enemyBase.width / 2;
soldier.y = 2732 - soldier.height / 2;
soldier.speed = isPlayer ? 5 : -5;
world.addChild(soldier);
if (isPlayer) {
playerSoldiers.push(soldier);
} else {
enemySoldiers.push(soldier);
}
}
}
function spawnArcher(isPlayer) {
if (isPlayer ? playerMoney >= 200 : enemyMoney >= 200) {
isPlayer ? playerMoney -= 200 : enemyMoney -= 200;
var archer = new Archer(isPlayer);
archer.health *= currentLevel;
archer.speed *= currentLevel;
archer.range *= currentLevel;
archer.x = isPlayer ? playerBase.x + playerBase.width / 2 : enemyBase.x - enemyBase.width / 2;
archer.y = 2732 - archer.height / 2;
archer.speed = isPlayer ? 8 : -8;
world.addChild(archer);
if (isPlayer) {
playerSoldiers.push(archer);
} else {
enemySoldiers.push(archer);
}
}
}
function handleTick() {
for (var i = 0; i < playerSoldiers.length; i++) {
var soldier = playerSoldiers[i];
soldier.move(playerSoldiers, enemySoldiers);
if (soldier instanceof Archer) {
var bullet = soldier.shoot(enemySoldiers);
if (bullet) {
world.addChild(bullet);
playerBullets.push(bullet);
}
}
for (var j = 0; j < enemySoldiers.length; j++) {
var enemy = enemySoldiers[j];
if (soldier.intersects(enemy)) {
if (soldier.takeDamage(10)) {
playerSoldiers.splice(i, 1);
i--;
enemyMoney += soldier.moneyReward;
}
if (enemy.takeDamage(10)) {
enemySoldiers.splice(j, 1);
j--;
playerMoney += enemy.moneyReward;
}
}
}
if (soldier.intersects(enemyBase)) {
if (enemyBase.takeDamage(50)) {
alert("You won");
restartGame();
} else {
soldier.speed = 0;
}
}
}
for (var i = 0; i < enemySoldiers.length; i++) {
var soldier = enemySoldiers[i];
soldier.move(enemySoldiers, playerSoldiers);
if (soldier instanceof Archer) {
var bullet = soldier.shoot(playerSoldiers);
if (bullet) {
world.addChild(bullet);
enemyBullets.push(bullet);
}
}
if (soldier.intersects(playerBase)) {
if (playerBase.takeDamage(50)) {
LK.showGameOver(restartGame);
} else {
soldier.speed = 0;
}
}
}
if (LK.ticks % 60 == 0) {
if (nextEnemy === 'soldier' && enemyMoney >= 100) {
spawnSoldier(false);
nextEnemy = Math.random() < 0.5 ? 'soldier' : 'archer';
} else if (nextEnemy === 'archer' && enemyMoney >= 200) {
spawnArcher(false);
nextEnemy = Math.random() < 0.5 ? 'soldier' : 'archer';
}
}
for (var i = 0; i < playerBullets.length; i++) {
var bullet = playerBullets[i];
bullet.move();
for (var j = 0; j < enemySoldiers.length; j++) {
var enemy = enemySoldiers[j];
if (bullet.intersects(enemy)) {
if (enemy.takeDamage(100)) {
enemySoldiers.splice(j, 1);
j--;
playerMoney += enemy.moneyReward;
}
bullet.destroy();
playerBullets.splice(i, 1);
i--;
}
}
}
for (var i = 0; i < enemyBullets.length; i++) {
var bullet = enemyBullets[i];
bullet.move();
for (var j = 0; j < playerSoldiers.length; j++) {
var soldier = playerSoldiers[j];
if (bullet.intersects(soldier)) {
if (soldier.takeDamage(100)) {
playerSoldiers.splice(j, 1);
j--;
enemyMoney += soldier.moneyReward;
}
bullet.destroy();
enemyBullets.splice(i, 1);
i--;
}
}
}
moneyTxt.setText('Player Money: ' + playerMoney + ' Enemy Money: ' + enemyMoney);
xpTxt.setText('XP: ' + xp);
}
LK.on('tick', handleTick);
var dragWorld = null;
var initialMousePos = null;
game.on('down', function (obj) {
dragWorld = world;
initialMousePos = obj.event.getLocalPosition(game);
});
game.on('move', function (obj) {
if (dragWorld && initialMousePos) {
var event = obj.event;
var pos = event.getLocalPosition(game);
var newX = dragWorld.x + pos.x - initialMousePos.x;
if (newX > 0) {
newX = 0;
} else if (newX < game.width - 2048 * 5) {
newX = game.width - 2048 * 5;
}
dragWorld.x = newX;
initialMousePos = pos;
}
});
game.on('up', function (obj) {
dragWorld = null;
initialMousePos = null;
});
function restartGame() {
playerBase.health = 10000;
playerBase.children[1].updateHealth(playerBase.health, 10000);
enemyBase.health = 10000;
enemyBase.children[1].updateHealth(enemyBase.health, 10000);
playerMoney = 1000;
enemyMoney = 1000;
xp = 0;
for (var i = 0; i < playerSoldiers.length; i++) {
playerSoldiers[i].destroy();
}
for (var i = 0; i < enemySoldiers.length; i++) {
enemySoldiers[i].destroy();
}
playerSoldiers = [];
enemySoldiers = [];
}
single background tree, full view. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
giant armored skeleton with a great sword. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cyberpunk archer with aiming plasma arrows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cyberpunk bodybuilder with a sledgehammer. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Enemy zombie archer walking to the left. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Full view Hero stronghold with gate at the right. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
single background tree, full view. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.