/****
* Classes
****/
// BigEnemy class
var BigEnemy = Container.expand(function () {
var self = Container.call(this);
var bigEnemyGraphics = self.attachAsset('bigEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1.2; // 0.6 times the speed of a normal enemy
self.health = 6;
;
self.healthBar = self.attachAsset('healthBar', {
anchorX: 0.5,
anchorY: 1.0,
y: -self.height / 2 - 10
});
self.update = function () {
self.healthBar.width = self.health / 10 * 400; // Update health bar width based on health
var dx = player.x - self.x;
var dy = player.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += self.speed * Math.cos(angle);
self.y += self.speed * Math.sin(angle);
};
});
//<Assets used in the game will automatically appear here>
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20;
self.update = function () {
self.x += self.speed * Math.cos(self.rotation);
self.y += self.speed * Math.sin(self.rotation);
if (self.x < 1024) {
bulletGraphics.scale.y = -1; // Flip vertically
} else {
bulletGraphics.scale.y = 1; // Reset flip
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += self.speed * Math.cos(angle);
self.y += self.speed * Math.sin(angle);
};
});
// FastEnemy class
var FastEnemy = Container.expand(function () {
var self = Container.call(this);
var fastEnemyGraphics = self.attachAsset('fastEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 16; // 6 times faster than regular enemy, multiplied by 1 + Math.min(1, score/1200)
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += self.speed * Math.cos(angle);
self.y += self.speed * Math.sin(angle);
if (self.x < 1024) {
// If the fast enemy is on the left side of the screen
fastEnemyGraphics.scale.x = -1; // Flip horizontally
} else {
fastEnemyGraphics.scale.x = 1; // Reset flip
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
self.rotation = 0;
self.bullets = [];
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullet.rotation = self.rotation;
self.bullets.push(bullet);
game.addChild(bullet);
};
self.poweredUp = false;
self.powerUpTimer = 0;
self.update = function () {
if (self.poweredUp) {
self.powerUpTimer--;
if (self.powerUpTimer <= 0) {
self.poweredUp = false;
self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
}
}
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics =
// Removed power up character sprite attachment
self.duration = 360; // 6 seconds at 60 FPS
self.update = function () {
self.duration--;
if (self.duration <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Attach background image
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Play background music
LK.playMusic('SunsLastStand');
// Initialize player
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 / 2;
game.addChild(player);
// Initialize score
var score = 0;
var maxScore = 0;
var scoreTxt = new Text2(score.toString(), {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0); // Sets anchor to the top middle of the text.
LK.gui.top.addChild(scoreTxt);
var maxScoreTxt = new Text2(maxScore.toString(), {
size: 100,
fill: "#ffffff"
});
maxScoreTxt.anchor.set(0.5, 1); // Sets anchor to the bottom middle of the text.
LK.gui.bottom.addChild(maxScoreTxt);
// Handle mouse move to rotate player
game.move = function (x, y, obj) {
var localPos = game.toLocal(obj.global);
var dx = localPos.x - player.x;
var dy = localPos.y - player.y;
player.rotation = Math.atan2(dy, dx);
};
// Handle mouse down to shoot
var lastShot = 0;
var mouseDown = false;
game.down = function (x, y, obj) {
mouseDown = true;
};
game.up = function (x, y, obj) {
mouseDown = false;
};
// Update game state
// Initialize enemies array
var enemies = [];
game.update = function () {
// Create enemies at random points along the edge
var spawnRate = 1.5 + 1.5 * Math.min(1, score / 1200);
if (LK.ticks % Math.floor(60 / spawnRate) == 0) {
var enemy = new Enemy();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// top
enemy.x = Math.random() * 2048;
enemy.y = 0;
break;
case 1:
// right
enemy.x = 2048;
enemy.y = Math.random() * 2732;
break;
case 2:
// bottom
enemy.x = Math.random() * 2048;
enemy.y = 2732;
break;
case 3:
// left
enemy.x = 0;
enemy.y = Math.random() * 2732;
break;
}
enemies.push(enemy);
game.addChild(enemy);
}
if (LK.ticks % Math.floor(60 * (16 - 8 * Math.min(1, score / 1200))) == 0) {
var fastEnemy = new FastEnemy();
LK.getSound('EnterDevil').play();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// top
fastEnemy.x = Math.random() * 2048;
fastEnemy.y = 0;
break;
case 1:
// right
fastEnemy.x = 2048;
fastEnemy.y = Math.random() * 2732;
break;
case 2:
// bottom
fastEnemy.x = Math.random() * 2048;
fastEnemy.y = 2732;
break;
case 3:
// left
fastEnemy.x = 0;
fastEnemy.y = Math.random() * 2732;
break;
}
enemies.push(fastEnemy);
game.addChild(fastEnemy);
}
if (LK.ticks % Math.floor(60 * 50) == 0) {
var bigEnemy = new BigEnemy();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// top
bigEnemy.x = Math.random() * 2048;
bigEnemy.y = 0;
break;
case 1:
// right
bigEnemy.x = 2048;
bigEnemy.y = Math.random() * 2732;
break;
case 2:
// bottom
bigEnemy.x = Math.random() * 2048;
bigEnemy.y = 2732;
break;
case 3:
// left
bigEnemy.x = 0;
bigEnemy.y = Math.random() * 2732;
break;
}
enemies.push(bigEnemy);
game.addChild(bigEnemy);
}
if (mouseDown) {
var shootInterval = player.poweredUp ? 12 : 24; // Double rate of fire when powered up
if (LK.ticks - lastShot >= shootInterval) {
player.shoot();
lastShot = LK.ticks;
}
}
player.update();
for (var i = player.bullets.length - 1; i >= 0; i--) {
player.bullets[i].update();
if (player.bullets[i].x < 0 || player.bullets[i].x > 2048 || player.bullets[i].y < 0 || player.bullets[i].y > 2732) {
player.bullets[i].destroy();
player.bullets.splice(i, 1);
} else {
for (var j = enemies.length - 1; j >= 0; j--) {
if (player.bullets[i].intersects(enemies[j])) {
player.bullets[i].destroy();
player.bullets.splice(i, 1);
if (enemies[j] instanceof FastEnemy) {
player.poweredUp = true;
player.powerUpTimer = 360; // 6 seconds at 60 FPS
// Removed power up character sprite attachment
}
if (enemies[j] instanceof BigEnemy) {
enemies[j].health -= 1;
if (enemies[j].health <= 0) {
LK.getSound('boom').play();
// Kill all enemies and add points
for (var k = enemies.length - 1; k >= 0; k--) {
enemies[k].destroy();
enemies.splice(k, 1);
score += 10;
}
// Show explosion effect
LK.effects.flashScreen(0xff0000, 1000);
}
} else {
enemies[j].destroy();
enemies.splice(j, 1);
}
if (enemies[j] instanceof FastEnemy) {
player.poweredUp = true;
player.powerUpTimer = 360; // 6 seconds at 60 FPS
// Removed power up character sprite attachment
}
// Increase score and update score text
score += 10;
scoreTxt.setText(score.toString());
break;
}
}
}
}
for (var j = enemies.length - 1; j >= 0; j--) {
if (player.intersects(enemies[j])) {
LK.getSound('ouch').play();
enemies[j].destroy();
enemies.splice(j, 1);
// Update max score if current score is higher
if (score > maxScore) {
maxScore = score;
maxScoreTxt.setText(maxScore.toString());
}
// Reset score to 0 and update score text
score = 0;
scoreTxt.setText(score.toString());
}
}
}; /****
* Classes
****/
// BigEnemy class
var BigEnemy = Container.expand(function () {
var self = Container.call(this);
var bigEnemyGraphics = self.attachAsset('bigEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 1.2; // 0.6 times the speed of a normal enemy
self.health = 6;
;
self.healthBar = self.attachAsset('healthBar', {
anchorX: 0.5,
anchorY: 1.0,
y: -self.height / 2 - 10
});
self.update = function () {
self.healthBar.width = self.health / 10 * 400; // Update health bar width based on health
var dx = player.x - self.x;
var dy = player.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += self.speed * Math.cos(angle);
self.y += self.speed * Math.sin(angle);
};
});
//<Assets used in the game will automatically appear here>
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20;
self.update = function () {
self.x += self.speed * Math.cos(self.rotation);
self.y += self.speed * Math.sin(self.rotation);
if (self.x < 1024) {
bulletGraphics.scale.y = -1; // Flip vertically
} else {
bulletGraphics.scale.y = 1; // Reset flip
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += self.speed * Math.cos(angle);
self.y += self.speed * Math.sin(angle);
};
});
// FastEnemy class
var FastEnemy = Container.expand(function () {
var self = Container.call(this);
var fastEnemyGraphics = self.attachAsset('fastEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 16; // 6 times faster than regular enemy, multiplied by 1 + Math.min(1, score/1200)
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var angle = Math.atan2(dy, dx);
self.x += self.speed * Math.cos(angle);
self.y += self.speed * Math.sin(angle);
if (self.x < 1024) {
// If the fast enemy is on the left side of the screen
fastEnemyGraphics.scale.x = -1; // Flip horizontally
} else {
fastEnemyGraphics.scale.x = 1; // Reset flip
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
self.rotation = 0;
self.bullets = [];
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullet.rotation = self.rotation;
self.bullets.push(bullet);
game.addChild(bullet);
};
self.poweredUp = false;
self.powerUpTimer = 0;
self.update = function () {
if (self.poweredUp) {
self.powerUpTimer--;
if (self.powerUpTimer <= 0) {
self.poweredUp = false;
self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
}
}
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics =
// Removed power up character sprite attachment
self.duration = 360; // 6 seconds at 60 FPS
self.update = function () {
self.duration--;
if (self.duration <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Attach background image
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Play background music
LK.playMusic('SunsLastStand');
// Initialize player
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 / 2;
game.addChild(player);
// Initialize score
var score = 0;
var maxScore = 0;
var scoreTxt = new Text2(score.toString(), {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0); // Sets anchor to the top middle of the text.
LK.gui.top.addChild(scoreTxt);
var maxScoreTxt = new Text2(maxScore.toString(), {
size: 100,
fill: "#ffffff"
});
maxScoreTxt.anchor.set(0.5, 1); // Sets anchor to the bottom middle of the text.
LK.gui.bottom.addChild(maxScoreTxt);
// Handle mouse move to rotate player
game.move = function (x, y, obj) {
var localPos = game.toLocal(obj.global);
var dx = localPos.x - player.x;
var dy = localPos.y - player.y;
player.rotation = Math.atan2(dy, dx);
};
// Handle mouse down to shoot
var lastShot = 0;
var mouseDown = false;
game.down = function (x, y, obj) {
mouseDown = true;
};
game.up = function (x, y, obj) {
mouseDown = false;
};
// Update game state
// Initialize enemies array
var enemies = [];
game.update = function () {
// Create enemies at random points along the edge
var spawnRate = 1.5 + 1.5 * Math.min(1, score / 1200);
if (LK.ticks % Math.floor(60 / spawnRate) == 0) {
var enemy = new Enemy();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// top
enemy.x = Math.random() * 2048;
enemy.y = 0;
break;
case 1:
// right
enemy.x = 2048;
enemy.y = Math.random() * 2732;
break;
case 2:
// bottom
enemy.x = Math.random() * 2048;
enemy.y = 2732;
break;
case 3:
// left
enemy.x = 0;
enemy.y = Math.random() * 2732;
break;
}
enemies.push(enemy);
game.addChild(enemy);
}
if (LK.ticks % Math.floor(60 * (16 - 8 * Math.min(1, score / 1200))) == 0) {
var fastEnemy = new FastEnemy();
LK.getSound('EnterDevil').play();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// top
fastEnemy.x = Math.random() * 2048;
fastEnemy.y = 0;
break;
case 1:
// right
fastEnemy.x = 2048;
fastEnemy.y = Math.random() * 2732;
break;
case 2:
// bottom
fastEnemy.x = Math.random() * 2048;
fastEnemy.y = 2732;
break;
case 3:
// left
fastEnemy.x = 0;
fastEnemy.y = Math.random() * 2732;
break;
}
enemies.push(fastEnemy);
game.addChild(fastEnemy);
}
if (LK.ticks % Math.floor(60 * 50) == 0) {
var bigEnemy = new BigEnemy();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// top
bigEnemy.x = Math.random() * 2048;
bigEnemy.y = 0;
break;
case 1:
// right
bigEnemy.x = 2048;
bigEnemy.y = Math.random() * 2732;
break;
case 2:
// bottom
bigEnemy.x = Math.random() * 2048;
bigEnemy.y = 2732;
break;
case 3:
// left
bigEnemy.x = 0;
bigEnemy.y = Math.random() * 2732;
break;
}
enemies.push(bigEnemy);
game.addChild(bigEnemy);
}
if (mouseDown) {
var shootInterval = player.poweredUp ? 12 : 24; // Double rate of fire when powered up
if (LK.ticks - lastShot >= shootInterval) {
player.shoot();
lastShot = LK.ticks;
}
}
player.update();
for (var i = player.bullets.length - 1; i >= 0; i--) {
player.bullets[i].update();
if (player.bullets[i].x < 0 || player.bullets[i].x > 2048 || player.bullets[i].y < 0 || player.bullets[i].y > 2732) {
player.bullets[i].destroy();
player.bullets.splice(i, 1);
} else {
for (var j = enemies.length - 1; j >= 0; j--) {
if (player.bullets[i].intersects(enemies[j])) {
player.bullets[i].destroy();
player.bullets.splice(i, 1);
if (enemies[j] instanceof FastEnemy) {
player.poweredUp = true;
player.powerUpTimer = 360; // 6 seconds at 60 FPS
// Removed power up character sprite attachment
}
if (enemies[j] instanceof BigEnemy) {
enemies[j].health -= 1;
if (enemies[j].health <= 0) {
LK.getSound('boom').play();
// Kill all enemies and add points
for (var k = enemies.length - 1; k >= 0; k--) {
enemies[k].destroy();
enemies.splice(k, 1);
score += 10;
}
// Show explosion effect
LK.effects.flashScreen(0xff0000, 1000);
}
} else {
enemies[j].destroy();
enemies.splice(j, 1);
}
if (enemies[j] instanceof FastEnemy) {
player.poweredUp = true;
player.powerUpTimer = 360; // 6 seconds at 60 FPS
// Removed power up character sprite attachment
}
// Increase score and update score text
score += 10;
scoreTxt.setText(score.toString());
break;
}
}
}
}
for (var j = enemies.length - 1; j >= 0; j--) {
if (player.intersects(enemies[j])) {
LK.getSound('ouch').play();
enemies[j].destroy();
enemies.splice(j, 1);
// Update max score if current score is higher
if (score > maxScore) {
maxScore = score;
maxScoreTxt.setText(maxScore.toString());
}
// Reset score to 0 and update score text
score = 0;
scoreTxt.setText(score.toString());
}
}
};
Fireball with angry face. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit
Grinning creepy ball shaped clown face. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit
Burning ball shaped creepy grinning devil. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit
Creepy Jester clown with a fat circular belly, grinning and carying a trident. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit
Dark night sky. Dim stars. DMT psychedelic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 8 bit