/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a 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 = 5; // Bullet speed
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
};
});
// Define a Sniper class
var Sniper = Container.expand(function () {
var self = Container.call(this);
var sniperGraphics = self.attachAsset('sniper', {
anchorX: 0.5,
anchorY: 0.5,
width: 300,
height: 300
});
self.down = function (x, y, obj) {
var bullet = new Bullet();
bullet.x = sniper.x;
bullet.y = sniper.y;
if (targets.length > 0) {
var dx = targets[0].x - bullet.x;
var dy = targets[0].y - bullet.y;
}
var distance = Math.sqrt(dx * dx + dy * dy);
bullet.speedX = bullet.speed * dx / distance;
bullet.speedY = bullet.speed * dy / distance;
bullets.push(bullet);
game.addChild(bullet);
// Play the 'shoot' sound effect
LK.getSound('shoot').play();
};
});
// Define a Target class
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
width: 300,
height: 300
});
self.speed = 3; // Target speed
self.update = function () {
var dx = sniper.x - self.x;
var dy = sniper.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += self.speed * dx / distance;
self.y += self.speed * dy / distance;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game variables
var bullets = [];
var targets = [];
var score = 0;
// Play the game music continuously with significantly increased volume
LK.playMusic('gameMusic', {
loop: true,
volume: 3.0
});
// Add background image to the game and increase its size
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1024 / 50,
scaleY: 1366 / 50,
x: 1024,
y: 1366
}));
// Create and position the sniper
var sniper = game.addChild(new Sniper());
sniper.x = 1024; // Center horizontally
sniper.y = 2632; // Move to the starting position
// Create targets
for (var i = 0; i < 2; i++) {
var target = new Target();
target.x = 200 + i * 200; // Staggered horizontally
target.y = Math.random() * 2732;
targets.push(target);
game.addChild(target);
}
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update game logic
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
if (bullets[i].y < 0) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
console.log(bullets);
// Update targets
for (var j = 0; j < targets.length; j++) {
targets[j].update();
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = targets.length - 1; l >= 0; l--) {
if (bullets[k].intersects(targets[l])) {
bullets[k].destroy();
targets[l].destroy();
bullets.splice(k, 1);
targets.splice(l, 1);
score += 1;
scoreTxt.setText('Score: ' + score);
break;
}
// Check if the sniper intersects with any target and end the game if it does
for (var m = 0; m < targets.length; m++) {
if (sniper.intersects(targets[m])) {
LK.showGameOver();
return;
}
}
}
}
// Generate new targets
if (LK.ticks % Math.max(240 - Math.floor(LK.ticks / 3000), 120) == 0) {
var targetCount = Math.floor(score / 10) + 1; // Increase the number of targets every 10 points
for (var i = 0; i < targetCount; i++) {
var target = new Target();
target.x = Math.random() * 2048; // Random position horizontally
target.y = 0; // At the top
targets.push(target);
game.addChild(target);
// Play the 'shoot' sound effect
LK.getSound('shoot').play();
}
}
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a 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 = 5; // Bullet speed
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
};
});
// Define a Sniper class
var Sniper = Container.expand(function () {
var self = Container.call(this);
var sniperGraphics = self.attachAsset('sniper', {
anchorX: 0.5,
anchorY: 0.5,
width: 300,
height: 300
});
self.down = function (x, y, obj) {
var bullet = new Bullet();
bullet.x = sniper.x;
bullet.y = sniper.y;
if (targets.length > 0) {
var dx = targets[0].x - bullet.x;
var dy = targets[0].y - bullet.y;
}
var distance = Math.sqrt(dx * dx + dy * dy);
bullet.speedX = bullet.speed * dx / distance;
bullet.speedY = bullet.speed * dy / distance;
bullets.push(bullet);
game.addChild(bullet);
// Play the 'shoot' sound effect
LK.getSound('shoot').play();
};
});
// Define a Target class
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5,
width: 300,
height: 300
});
self.speed = 3; // Target speed
self.update = function () {
var dx = sniper.x - self.x;
var dy = sniper.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += self.speed * dx / distance;
self.y += self.speed * dy / distance;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game variables
var bullets = [];
var targets = [];
var score = 0;
// Play the game music continuously with significantly increased volume
LK.playMusic('gameMusic', {
loop: true,
volume: 3.0
});
// Add background image to the game and increase its size
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1024 / 50,
scaleY: 1366 / 50,
x: 1024,
y: 1366
}));
// Create and position the sniper
var sniper = game.addChild(new Sniper());
sniper.x = 1024; // Center horizontally
sniper.y = 2632; // Move to the starting position
// Create targets
for (var i = 0; i < 2; i++) {
var target = new Target();
target.x = 200 + i * 200; // Staggered horizontally
target.y = Math.random() * 2732;
targets.push(target);
game.addChild(target);
}
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update game logic
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
if (bullets[i].y < 0) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
console.log(bullets);
// Update targets
for (var j = 0; j < targets.length; j++) {
targets[j].update();
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = targets.length - 1; l >= 0; l--) {
if (bullets[k].intersects(targets[l])) {
bullets[k].destroy();
targets[l].destroy();
bullets.splice(k, 1);
targets.splice(l, 1);
score += 1;
scoreTxt.setText('Score: ' + score);
break;
}
// Check if the sniper intersects with any target and end the game if it does
for (var m = 0; m < targets.length; m++) {
if (sniper.intersects(targets[m])) {
LK.showGameOver();
return;
}
}
}
}
// Generate new targets
if (LK.ticks % Math.max(240 - Math.floor(LK.ticks / 3000), 120) == 0) {
var targetCount = Math.floor(score / 10) + 1; // Increase the number of targets every 10 points
for (var i = 0; i < targetCount; i++) {
var target = new Target();
target.x = Math.random() * 2048; // Random position horizontally
target.y = 0; // At the top
targets.push(target);
game.addChild(target);
// Play the 'shoot' sound effect
LK.getSound('shoot').play();
}
}
};
fighter. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
zombie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
zombie bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
zombie epidemic abaounded place. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.