/**** * Classes ****/ // Silahlı oyunçu şəkli 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 () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('playerWithGun', { // Silahlı oyunçu anchorX: 0.5, anchorY: 0.5 }); self.health = 100; // Oyunçunun canı self.speed = 5; self.jumpHeight = 40; self.isJumping = false; self.velocityY = 0; self.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; if (self.y >= groundY) { self.y = groundY; self.isJumping = false; self.velocityY = 0; } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; } }; self.takeDamage = function () { self.health -= 5; // Hər toqquşmada can 5 azalır if (self.health <= 0) { LK.showGameOver(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Normal oyunçu var groundY = game.height - 200; var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); background.x = 0; background.y = 0; background.updateTransform = function () {}; var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = groundY; var enemies = []; var enemySpawnInterval = 100; var enemySpawnCounter = 0; var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 0; // Can göstəricisi var healthText = new Text2('Health: 100', { size: 50, fill: 0xFFFFFF }); LK.gui.top.addChild(healthText); healthText.x = 10; // Ekranın sol üst hissəsi healthText.y = 10; game.update = function () { player.update(); healthText.setText('Health: ' + player.health); // Canı ekrana yansıt enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy(); enemy.x = 2048; enemy.y = groundY; enemies.push(enemy); game.addChild(enemy); enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { player.takeDamage(); // Oyunçunun canı 5 azalır LK.effects.flashScreen(0xff0000, 1000); } else if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; LK.setScore(LK.getScore() + 1); scoreText.setText(LK.getScore()); } } }; game.down = function (x, y, obj) { player.jump(); }; // Oyunçunun atış etdiyi funksiya game.right = function (x, y, obj) { if (player.health > 0) { // Burada merminin vurulması üçün kod əlavə ediləcək console.log("Oyunçu atır!"); // Atışın baş verdiyini göstərmək üçün } };
/****
* Classes
****/
// Silahlı oyunçu şəkli
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 () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('playerWithGun', {
// Silahlı oyunçu
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100; // Oyunçunun canı
self.speed = 5;
self.jumpHeight = 40;
self.isJumping = false;
self.velocityY = 0;
self.update = function () {
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7;
if (self.y >= groundY) {
self.y = groundY;
self.isJumping = false;
self.velocityY = 0;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
}
};
self.takeDamage = function () {
self.health -= 5; // Hər toqquşmada can 5 azalır
if (self.health <= 0) {
LK.showGameOver();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Normal oyunçu
var groundY = game.height - 200;
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
background.updateTransform = function () {};
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = groundY;
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
LK.gui.top.addChild(scoreText);
scoreText.x = 2048 / 2;
scoreText.y = 0;
// Can göstəricisi
var healthText = new Text2('Health: 100', {
size: 50,
fill: 0xFFFFFF
});
LK.gui.top.addChild(healthText);
healthText.x = 10; // Ekranın sol üst hissəsi
healthText.y = 10;
game.update = function () {
player.update();
healthText.setText('Health: ' + player.health); // Canı ekrana yansıt
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = groundY;
enemies.push(enemy);
game.addChild(enemy);
enemySpawnInterval = Math.floor(Math.random() * 150) + 50;
enemySpawnCounter = 0;
}
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
player.takeDamage(); // Oyunçunun canı 5 azalır
LK.effects.flashScreen(0xff0000, 1000);
} else if (player.x > enemies[j].x && !enemies[j].passed) {
enemies[j].passed = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
}
}
};
game.down = function (x, y, obj) {
player.jump();
};
// Oyunçunun atış etdiyi funksiya
game.right = function (x, y, obj) {
if (player.health > 0) {
// Burada merminin vurulması üçün kod əlavə ediləcək
console.log("Oyunçu atır!"); // Atışın baş verdiyini göstərmək üçün
}
};