/**** * Classes ****/ 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; }; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.jumpHeight = 40; self.isJumping = false; self.velocityY = 0; self.update = function () { // Yerçekimi self.velocityY += 0.8; self.y += self.velocityY; if (self.y > ground.y - self.height) { self.y = ground.y - self.height; self.velocityY = 0; self.isJumping = false; } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB, width: 8192, height: 10928 }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, width: game.width, height: game.height })); background.x = game.width / 2; background.y = game.height / 2; LK.playMusic('didi', { loop: true }); var ground = game.addChild(LK.getAsset('ground', { anchorX: 0, anchorY: 1 })); ground.x = 0; ground.y = 2732 - 300; // Oyuncu var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = ground.y - player.height - 420; // Düşmanlar var enemies = []; var enemySpawnInterval = 100; var enemySpawnCounter = 0; // Skorlar var score = 0; var highScore = 0; // Skor metni var scoreText = new Text2('Score: 0', { size: 100, fill: 0xFF0000 }); LK.gui.top.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 100; // Oyun güncellemesi game.update = function () { player.update(); // Düşman üretme enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy(); enemy.x = game.width; enemy.y = ground.y - enemy.height; enemies.push(enemy); game.addChild(enemy); enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } // Düşman güncelleme ve çarpışma kontrolü for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; enemy.update(); if (player.intersects(enemy)) { LK.showGameOver(); LK.getSound('gamop').play(); if (score > highScore) { highScore = score; } scoreText.setText('GETOR\nScore: ' + score + '\nHigh Score: ' + highScore); scoreText.x = 2048 / 2; scoreText.y = 2732 / 2 + 200; } } }; // Oyuncu zıplarsa puan kazanma game.down = function (x, y, obj) { player.jump(); for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; if (player.y < enemy.y && player.x > enemy.x && player.x < enemy.x + enemy.width) { score++; scoreText.setText('Score: ' + score); break; } } };
/****
* Classes
****/
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;
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.jumpHeight = 40;
self.isJumping = false;
self.velocityY = 0;
self.update = function () {
// Yerçekimi
self.velocityY += 0.8;
self.y += self.velocityY;
if (self.y > ground.y - self.height) {
self.y = ground.y - self.height;
self.velocityY = 0;
self.isJumping = false;
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB,
width: 8192,
height: 10928
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
width: game.width,
height: game.height
}));
background.x = game.width / 2;
background.y = game.height / 2;
LK.playMusic('didi', {
loop: true
});
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 1
}));
ground.x = 0;
ground.y = 2732 - 300;
// Oyuncu
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = ground.y - player.height - 420;
// Düşmanlar
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
// Skorlar
var score = 0;
var highScore = 0;
// Skor metni
var scoreText = new Text2('Score: 0', {
size: 100,
fill: 0xFF0000
});
LK.gui.top.addChild(scoreText);
scoreText.x = 2048 / 2;
scoreText.y = 100;
// Oyun güncellemesi
game.update = function () {
player.update();
// Düşman üretme
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy();
enemy.x = game.width;
enemy.y = ground.y - enemy.height;
enemies.push(enemy);
game.addChild(enemy);
enemySpawnInterval = Math.floor(Math.random() * 150) + 50;
enemySpawnCounter = 0;
}
// Düşman güncelleme ve çarpışma kontrolü
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
enemy.update();
if (player.intersects(enemy)) {
LK.showGameOver();
LK.getSound('gamop').play();
if (score > highScore) {
highScore = score;
}
scoreText.setText('GETOR\nScore: ' + score + '\nHigh Score: ' + highScore);
scoreText.x = 2048 / 2;
scoreText.y = 2732 / 2 + 200;
}
}
};
// Oyuncu zıplarsa puan kazanma
game.down = function (x, y, obj) {
player.jump();
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
if (player.y < enemy.y && player.x > enemy.x && player.x < enemy.x + enemy.width) {
score++;
scoreText.setText('Score: ' + score);
break;
}
}
};
guzel 2d bir arka plan bulutlu havalar arkada ucan kuslar ve bu 2d olucak. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. 2d
yuzu olan kizqin bir ates topu sinirli yakici ve pixelart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows