/**** * Classes ****/ // Define a class for bullets var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < 0) { self.destroy(); } }; }); // Define a class for d2 enemies var D2 = Container.expand(function () { var self = Container.call(this); var d2Graphics = self.attachAsset('d2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; }); // Define a class for enemies var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Player update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundImage: 'yol' //Set 'yol' image as the game background }); /**** * Game Code ****/ // Create a score text var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - player.height; // Initialize enemies var enemies = []; for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 1000; enemies.push(enemy); game.addChild(enemy); } // Initialize bullets var bullets = []; // Initialize d2 enemies var d2 = []; // Handle player movement game.down = function (x, y, obj) { // player.x = x; // player.y = y; }; // Handle shooting game.up = function (x, y, obj) { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); game.addChild(bullet); LK.getSound('ate').play(); }; // Game update loop game.update = function () { // Update player player.update(); // Update enemies for (var i = 0; i < enemies.length; i++) { if (LK.getScore() >= 50 && LK.getScore() < 100) { enemies[i].speed = 10; } else if (LK.getScore() >= 100) { enemies[i].speed = 15; } enemies[i].update(); if (player.intersects(enemies[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Update D2 enemies for (var i = 0; i < d2.length; i++) { d2[i].update(); if (player.intersects(d2[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.getSound('olme2').play(); LK.showGameOver(); } } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { bullets[j].update(); for (var k = enemies.length - 1; k >= 0; k--) { if (bullets[j].intersects(enemies[k])) { bullets[j].destroy(); bullets.splice(j, 1); enemies[k].destroy(); enemies.splice(k, 1); // Update score LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Play 'olom' sound LK.getSound('olom').play(); break; } } for (var l = d2.length - 1; l >= 0; l--) { if (bullets[j] && bullets[j].intersects(d2[l])) { bullets[j].destroy(); bullets.splice(j, 1); d2[l].destroy(); d2.splice(l, 1); // Update score LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Play 'olme2' sound LK.getSound('olme2').play(); break; } } } // Spawn new enemies in groups of 3 every 60 ticks after 5 seconds from the game starts if (LK.ticks > 300 && LK.ticks % 60 == 0) { for (var i = 0; i < 3; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; // Random x position enemy.y = 0; // Spawn at the top of the screen enemies.push(enemy); game.addChild(enemy); } // Spawn a new D2 enemy every 60 ticks after 5 seconds from the game starts var d2Enemy = new D2(); d2Enemy.x = Math.random() * 2048; // Random x position d2Enemy.y = 0; // Spawn at the top of the screen d2.push(d2Enemy); game.addChild(d2Enemy); } }; 1; // Handle player movement game.move = function (x, y, obj) { // Set the boundary line var boundaryLine = 2732 - player.height; // Allow the player to move inside the boundary line if (y > boundaryLine) { player.y = y; } else { player.y = boundaryLine; } player.x = x; };
/****
* Classes
****/
// Define a class for bullets
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -15;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
});
// Define a class for d2 enemies
var D2 = Container.expand(function () {
var self = Container.call(this);
var d2Graphics = self.attachAsset('d2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
};
});
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Player update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundImage: 'yol' //Set 'yol' image as the game background
});
/****
* Game Code
****/
// Create a score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - player.height;
// Initialize enemies
var enemies = [];
for (var i = 0; i < 5; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 1000;
enemies.push(enemy);
game.addChild(enemy);
}
// Initialize bullets
var bullets = [];
// Initialize d2 enemies
var d2 = [];
// Handle player movement
game.down = function (x, y, obj) {
// player.x = x;
// player.y = y;
};
// Handle shooting
game.up = function (x, y, obj) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('ate').play();
};
// Game update loop
game.update = function () {
// Update player
player.update();
// Update enemies
for (var i = 0; i < enemies.length; i++) {
if (LK.getScore() >= 50 && LK.getScore() < 100) {
enemies[i].speed = 10;
} else if (LK.getScore() >= 100) {
enemies[i].speed = 15;
}
enemies[i].update();
if (player.intersects(enemies[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update D2 enemies
for (var i = 0; i < d2.length; i++) {
d2[i].update();
if (player.intersects(d2[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('olme2').play();
LK.showGameOver();
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
for (var k = enemies.length - 1; k >= 0; k--) {
if (bullets[j].intersects(enemies[k])) {
bullets[j].destroy();
bullets.splice(j, 1);
enemies[k].destroy();
enemies.splice(k, 1);
// Update score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Play 'olom' sound
LK.getSound('olom').play();
break;
}
}
for (var l = d2.length - 1; l >= 0; l--) {
if (bullets[j] && bullets[j].intersects(d2[l])) {
bullets[j].destroy();
bullets.splice(j, 1);
d2[l].destroy();
d2.splice(l, 1);
// Update score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Play 'olme2' sound
LK.getSound('olme2').play();
break;
}
}
}
// Spawn new enemies in groups of 3 every 60 ticks after 5 seconds from the game starts
if (LK.ticks > 300 && LK.ticks % 60 == 0) {
for (var i = 0; i < 3; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048; // Random x position
enemy.y = 0; // Spawn at the top of the screen
enemies.push(enemy);
game.addChild(enemy);
}
// Spawn a new D2 enemy every 60 ticks after 5 seconds from the game starts
var d2Enemy = new D2();
d2Enemy.x = Math.random() * 2048; // Random x position
d2Enemy.y = 0; // Spawn at the top of the screen
d2.push(d2Enemy);
game.addChild(d2Enemy);
}
};
1;
// Handle player movement
game.move = function (x, y, obj) {
// Set the boundary line
var boundaryLine = 2732 - player.height;
// Allow the player to move inside the boundary line
if (y > boundaryLine) {
player.y = y;
} else {
player.y = boundaryLine;
}
player.x = x;
};