/****
* Classes
****/
var Boss1 = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('Boss1', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 5;
self.angle = 0;
self.radius = 300;
self.update = function () {
self.angle += 0.05;
self.x = marksman.x + Math.cos(self.angle) * self.radius;
self.y = marksman.y + Math.sin(self.angle) * self.radius;
self.circles = (self.circles || 0) + 0.05 / (2 * Math.PI);
if (self.circles >= 8) {
self.circles = 0;
self.attack();
}
};
self.attack = function () {
var dx = marksman.x - self.x;
var dy = marksman.y - self.y;
var angle = Math.atan2(dy, dx);
var bullet = new Bullet(self.x, self.y, angle);
game.addChild(bullet);
bullets.push(bullet);
};
});
// Bullet class
var Bullet = Container.expand(function (x, y, angle) {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.speed = 10;
self.angle = angle;
self.rotation = angle; // Rotate the bullet when it is created
self.update = function () {
self.x += Math.cos(self.angle) * self.speed;
self.y += Math.sin(self.angle) * self.speed;
if (self.y < -50 || self.y > 2732 + 50 || self.x < -50 || self.x > 2048 + 50) {
self.destroy();
bullets.splice(bullets.indexOf(self), 1);
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
var spawnSide = Math.floor(Math.random() * 4);
switch (spawnSide) {
case 0:
self.x = Math.random() * 2048;
self.y = -50;
break;
case 1:
self.x = 2048 + 50;
self.y = Math.random() * 2732;
break;
case 2:
self.x = Math.random() * 2048;
self.y = 2732 + 50;
break;
case 3:
self.x = -50;
self.y = Math.random() * 2732;
break;
}
self.speed = 7 + Math.floor(score / 50);
self.update = function () {
var dx = 2048 / 2 - self.x;
var dy = 2732 / 2 - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
if (self.y < -50 || self.y > 2732 + 50 || self.x < -50 || self.x > 2048 + 50) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
});
// Enemy2 class
var Enemy2 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('Enemy2', {
anchorX: 0.5,
anchorY: 0.5
});
var spawnSide = Math.floor(Math.random() * 4);
switch (spawnSide) {
case 0:
self.x = Math.random() * 2048;
self.y = -50;
break;
case 1:
self.x = 2048 + 50;
self.y = Math.random() * 2732;
break;
case 2:
self.x = Math.random() * 2048;
self.y = 2732 + 50;
break;
case 3:
self.x = -50;
self.y = Math.random() * 2732;
break;
}
self.speed = 7 + Math.floor(score / 50);
self.update = function () {
var dx = 2048 / 2 - self.x;
var dy = 2732 / 2 - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
if (self.y < -50 || self.y > 2732 + 50 || self.x < -50 || self.x > 2048 + 50) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
});
// Enemy3 class
var Enemy3 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('Enemy3', {
anchorX: 0.5,
anchorY: 0.5
});
var spawnSide = Math.floor(Math.random() * 4);
switch (spawnSide) {
case 0:
self.x = Math.random() * 2048;
self.y = -50;
break;
case 1:
self.x = 2048 + 50;
self.y = Math.random() * 2732;
break;
case 2:
self.x = Math.random() * 2048;
self.y = 2732 + 50;
break;
case 3:
self.x = -50;
self.y = Math.random() * 2732;
break;
}
self.speed = 4 + Math.floor(score / 50);
self.health = 2;
self.update = function () {
var dx = 2048 / 2 - self.x;
var dy = 2732 / 2 - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
if (self.y < -50 || self.y > 2732 + 50 || self.x < -50 || self.x > 2048 + 50) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
});
// Assets will be automatically created and loaded during gameplay
// Marksman class
var Marksman = Container.expand(function () {
var self = Container.call(this);
var marksmanGraphics = self.attachAsset('marksman', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function (angle) {
for (var i = 0; i <= upgradeLevel; i++) {
var bullet = new Bullet(self.x, self.y, angle + i * Math.PI / 8);
game.addChild(bullet);
bullets.push(bullet);
}
};
self.upgrade = function () {
if (upgradeLevel < 5 && gold >= (upgradeLevel + 1) * 10) {
gold -= (upgradeLevel + 1) * 10;
upgradeLevel++;
enemySpawnRate = Math.max(30, enemySpawnRate - 5); // Increase spawn rate, minimum 30 ticks
updateGold();
if (upgradeLevel < 5) {
upgradeCostTxt.setText('Upgrade Cost: ' + (upgradeLevel + 1) * 10);
} else {
upgradeCostTxt.setText('Max Upgrades Reached');
enemySpawnRate = Math.max(10, enemySpawnRate - 10); // Increase difficulty by reducing spawn rate
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Update gold
function updateGold() {
goldTxt.setText('Gold: ' + gold);
}
game.move = function (x, y, obj) {
var dx = x - marksman.x;
var dy = y - marksman.y;
var angle = Math.atan2(dy, dx);
marksman.rotation = angle;
};
// Initialize variables
var marksman;
var bullets = [];
var enemies = [];
var score = 0;
var gold = 0;
var upgradeLevel = 0;
var enemySpawnRate = 60; // Initial enemy spawn rate
var scoreTxt;
var upgradeCostTxt;
var boss1 = null;
// Initialize game elements
function initGame() {
var background = LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0
});
game.addChild(background);
marksman = new Marksman();
marksman.x = 2048 / 2;
marksman.y = 2732 / 2;
game.addChild(marksman);
scoreTxt = new Text2('Score: 0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
goldTxt = new Text2('Gold: 0', {
size: 150,
fill: "#ffd700"
});
goldTxt.anchor.set(0, 1);
LK.gui.bottomLeft.addChild(goldTxt);
scoreTxt.anchor.set(0, 1);
LK.gui.bottom.addChild(scoreTxt);
var upgradeButton = LK.getAsset('upgrade', {
anchorX: 0.5,
anchorY: 0.5
});
upgradeButton.x = 2048 - 100;
upgradeButton.y = 2732 - 100;
upgradeButton.down = function () {
marksman.upgrade();
};
game.addChild(upgradeButton);
upgradeCostTxt = new Text2('Upgrade Cost: ' + (upgradeLevel + 1) * 10, {
size: 100,
fill: "#ffffff"
});
upgradeCostTxt.anchor.set(0, 0);
upgradeCostTxt.x = 0;
upgradeCostTxt.y = 0;
game.addChild(upgradeCostTxt);
}
// Update score
function updateScore() {
scoreTxt.setText(score);
}
// Handle shooting
game.down = function (x, y, obj) {
var dx = x - marksman.x;
var dy = y - marksman.y;
var angle = Math.atan2(dy, dx);
marksman.shoot(angle);
};
// Handle game updates
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (enemies[j].intersects(marksman)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update Boss1
if (boss1) {
boss1.update();
for (var k = bullets.length - 1; k >= 0; k--) {
if (bullets[k].intersects(boss1)) {
bullets[k].destroy();
bullets.splice(k, 1);
boss1.health--;
if (boss1.health <= 0) {
boss1.destroy();
boss1 = null;
score += 10;
gold += 10;
updateScore();
updateGold();
if (Math.random() < 0.5) {
boss1 = new Boss1();
game.addChild(boss1);
}
}
}
}
}
// Check for bullet-enemy collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
bullets[k].destroy();
bullets.splice(k, 1);
if (enemies[l] instanceof Enemy3) {
enemies[l].health--;
if (enemies[l].health <= 0) {
enemies[l].destroy();
enemies.splice(l, 1);
score++;
gold++;
updateScore();
updateGold();
}
} else {
enemies[l].destroy();
enemies.splice(l, 1);
score++;
gold++;
updateScore();
updateGold();
}
break;
}
}
}
// Spawn new enemies
if (score >= 20 && score < 50) {
enemySpawnRate = 50;
} else if (score >= 50 && score < 100) {
enemySpawnRate = 40;
} else if (score >= 100 && score < 150) {
enemySpawnRate = 30;
if (!boss1) {
boss1 = new Boss1();
game.addChild(boss1);
}
} else if (score >= 150 && score < 200) {
enemySpawnRate = 20;
} else if (score >= 200 && score < 300) {
enemySpawnRate = 15;
} else if (score >= 300) {
enemySpawnRate = Math.max(5, 40 - Math.floor(score / 50) * 5);
}
if (LK.ticks % enemySpawnRate == 0) {
var newEnemy;
var randomValue = Math.random();
if (randomValue < 0.33) {
newEnemy = new Enemy();
} else if (randomValue < 0.66) {
newEnemy = new Enemy2();
} else {
newEnemy = new Enemy3();
}
game.addChild(newEnemy);
enemies.push(newEnemy);
}
};
// Initialize game
initGame();
A ghost in cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cartoon style upward arrow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cartoon spooky night road from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A man with a crowwbow in a hat from above cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cartoon style bat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cartoon style zombie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A simple arrow made of wood with iron head in bright colour. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cartoon vampire. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.