/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Zemin (sürekli ekranın alt kısmında) var Ground = Container.expand(function () { var self = Container.call(this); var groundGfx = self.attachAsset('ground', { anchorX: 0, anchorY: 0 }); self.width = groundGfx.width; self.height = groundGfx.height; return self; }); // Platform (yeşil platform) var Platform = Container.expand(function () { var self = Container.call(this); var platGfx = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.width = platGfx.width; self.height = platGfx.height; self.speed = platformSpeed; // Sola kayma hızı, global platformSpeed ile başlar self.update = function () { self.x -= self.speed; }; return self; }); // Runner (Oyuncu Karakteri) var Runner = Container.expand(function () { var self = Container.call(this); var runnerGfx = self.attachAsset('runner', { anchorX: 0.5, anchorY: 1 }); self.width = runnerGfx.width; self.height = runnerGfx.height; self.vy = 0; // Dikey hız self.isOnGround = false; self.jumpPower = -80; // Zıplama gücü (daha yüksek zıplar) self.gravity = 4; // Yerçekimi self.maxFallSpeed = 60; self.update = function () { self.vy += self.gravity; if (self.vy > self.maxFallSpeed) self.vy = self.maxFallSpeed; self.y += self.vy; }; self.jump = function () { if (self.isOnGround) { self.vy = self.jumpPower; self.isOnGround = false; LK.getSound('jump').play(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb // Açık mavi gökyüzü }); /**** * Game Code ****/ // Oyun alanı boyutları // Karakter (oyuncu) // Platform // Engel (diken) // Zemin (arka plan platformu) // Zıplama sesi var GAME_W = 2048; var GAME_H = 2732; // Platform ve engel dizileri var platforms = []; // Zorluk ve platform üretim parametreleri var platformMinY = 900; var platformMaxY = 1800; var platformGapMin = 350; var platformGapMax = 650; var platformSpeed = 8; // Oyun başında yavaş başlasın var difficultyTimer = 0; // Runner (oyuncu) oluştur var runner = new Runner(); runner.x = 500; runner.y = 1500; game.addChild(runner); // Zemin ekle var ground = new Ground(); ground.x = 0; ground.y = GAME_H - ground.height; game.addChild(ground); // Skor (katedilen mesafe) var score = 0; var lastRunnerX = runner ? runner.x : 0; // Runner'ın son X konumu var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // İlk platformları oluştur function createInitialPlatforms() { var x = 600; for (var i = 0; i < 5; i++) { var plat = new Platform(); plat.x = x; plat.y = 1700; platforms.push(plat); game.addChild(plat); x += 500; } } createInitialPlatforms(); // Platform üretici function spawnPlatform() { // Son platformun x konumunu bul var lastPlat = platforms.length > 0 ? platforms[platforms.length - 1] : null; var lastX = lastPlat ? lastPlat.x : 1200; var gap = platformGapMin + Math.floor(Math.random() * (platformGapMax - platformGapMin)); var platY = platformMinY + Math.floor(Math.random() * (platformMaxY - platformMinY)); var plat = new Platform(); plat.x = lastX + gap; plat.y = platY; platforms.push(plat); game.addChild(plat); } // Platform ve spike'ları güncelle function updatePlatformsAndSpikes() { // Platformları güncelle ve ekrandan çıkanları sil for (var i = platforms.length - 1; i >= 0; i--) { var plat = platforms[i]; plat.update(); if (plat.x + plat.width / 2 < -100) { plat.destroy(); platforms.splice(i, 1); } } // Yeni platform üret var lastPlat = platforms.length > 0 ? platforms[platforms.length - 1] : null; if (lastPlat && lastPlat.x < GAME_W - 500) { spawnPlatform(); } } // Runner'ın platforma çarpıp çarpmadığını kontrol et function checkRunnerPlatformCollision() { runner.isOnGround = false; for (var i = 0; i < platforms.length; i++) { var plat = platforms[i]; // Runner'ın altı platformun üstüne değiyor mu? var runnerBottom = runner.y; var runnerTop = runner.y - runner.height; var platTop = plat.y - plat.height / 2; var platBottom = plat.y + plat.height / 2; var runnerLeft = runner.x - runner.width / 2 + 10; var runnerRight = runner.x + runner.width / 2 - 10; var platLeft = plat.x - plat.width / 2; var platRight = plat.x + plat.width / 2; // Yalnızca runner aşağıya doğru hareket ediyorsa ve platformun üstüne iniyorsa if (runner.vy >= 0 && runnerBottom > platTop && runnerTop < platTop && runnerRight > platLeft && runnerLeft < platRight) { // Runner'ı platformun üstüne yerleştir runner.y = platTop; runner.vy = 0; runner.isOnGround = true; break; } } // Eğer runner zemin seviyesine değerse, oyun biter var groundTop = ground.y; var runnerBottom = runner.y; var runnerLeft = runner.x - runner.width / 2 + 10; var runnerRight = runner.x + runner.width / 2 - 10; var groundLeft = ground.x; var groundRight = ground.x + ground.width; // Runner'ın altı zeminin üstüne değiyorsa ve yatayda da çakışıyorsa if (runnerBottom >= groundTop && runnerRight > groundLeft && runnerLeft < groundRight) { LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Runner'ın spike'a çarpıp çarpmadığını kontrol et // Runner ekran dışına düşerse oyun biter function checkRunnerFall() { if (runner.y > GAME_H + 200) { LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); } } // Skor güncelle (geçilen platform sayısı) function updateScore() { // Runner'ın geçtiği platformları say for (var i = 0; i < platforms.length; i++) { var plat = platforms[i]; if (!plat.passed && runner.x > plat.x + plat.width / 2) { plat.passed = true; score += 1; scoreTxt.setText(score); } } } // Zorluk arttırıcı function updateDifficulty() { difficultyTimer++; if (difficultyTimer % 300 === 0) { // Her 5 saniyede bir if (platformGapMax < 900) platformGapMax += 30; if (platformSpeed < 32) platformSpeed += 0.5; // Daha yumuşak hız artışı için 0.5 artır // Tüm platformların hızını güncelle for (var i = 0; i < platforms.length; i++) { platforms[i].speed = platformSpeed; } } } // Oyun güncelleme döngüsü game.update = function () { runner.update(); updatePlatformsAndSpikes(); checkRunnerPlatformCollision(); checkRunnerFall(); updateScore(); updateDifficulty(); }; // Dokunma/zıplama kontrolü game.down = function (x, y, obj) { runner.jump(); }; // Oyun başında runner'ı platformun üstüne yerleştir (function placeRunnerOnFirstPlatform() { if (platforms.length > 0) { var plat = platforms[0]; runner.x = plat.x; runner.y = plat.y - plat.height / 2; } })();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Zemin (sürekli ekranın alt kısmında)
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGfx = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
self.width = groundGfx.width;
self.height = groundGfx.height;
return self;
});
// Platform (yeşil platform)
var Platform = Container.expand(function () {
var self = Container.call(this);
var platGfx = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = platGfx.width;
self.height = platGfx.height;
self.speed = platformSpeed; // Sola kayma hızı, global platformSpeed ile başlar
self.update = function () {
self.x -= self.speed;
};
return self;
});
// Runner (Oyuncu Karakteri)
var Runner = Container.expand(function () {
var self = Container.call(this);
var runnerGfx = self.attachAsset('runner', {
anchorX: 0.5,
anchorY: 1
});
self.width = runnerGfx.width;
self.height = runnerGfx.height;
self.vy = 0; // Dikey hız
self.isOnGround = false;
self.jumpPower = -80; // Zıplama gücü (daha yüksek zıplar)
self.gravity = 4; // Yerçekimi
self.maxFallSpeed = 60;
self.update = function () {
self.vy += self.gravity;
if (self.vy > self.maxFallSpeed) self.vy = self.maxFallSpeed;
self.y += self.vy;
};
self.jump = function () {
if (self.isOnGround) {
self.vy = self.jumpPower;
self.isOnGround = false;
LK.getSound('jump').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Açık mavi gökyüzü
});
/****
* Game Code
****/
// Oyun alanı boyutları
// Karakter (oyuncu)
// Platform
// Engel (diken)
// Zemin (arka plan platformu)
// Zıplama sesi
var GAME_W = 2048;
var GAME_H = 2732;
// Platform ve engel dizileri
var platforms = [];
// Zorluk ve platform üretim parametreleri
var platformMinY = 900;
var platformMaxY = 1800;
var platformGapMin = 350;
var platformGapMax = 650;
var platformSpeed = 8; // Oyun başında yavaş başlasın
var difficultyTimer = 0;
// Runner (oyuncu) oluştur
var runner = new Runner();
runner.x = 500;
runner.y = 1500;
game.addChild(runner);
// Zemin ekle
var ground = new Ground();
ground.x = 0;
ground.y = GAME_H - ground.height;
game.addChild(ground);
// Skor (katedilen mesafe)
var score = 0;
var lastRunnerX = runner ? runner.x : 0; // Runner'ın son X konumu
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// İlk platformları oluştur
function createInitialPlatforms() {
var x = 600;
for (var i = 0; i < 5; i++) {
var plat = new Platform();
plat.x = x;
plat.y = 1700;
platforms.push(plat);
game.addChild(plat);
x += 500;
}
}
createInitialPlatforms();
// Platform üretici
function spawnPlatform() {
// Son platformun x konumunu bul
var lastPlat = platforms.length > 0 ? platforms[platforms.length - 1] : null;
var lastX = lastPlat ? lastPlat.x : 1200;
var gap = platformGapMin + Math.floor(Math.random() * (platformGapMax - platformGapMin));
var platY = platformMinY + Math.floor(Math.random() * (platformMaxY - platformMinY));
var plat = new Platform();
plat.x = lastX + gap;
plat.y = platY;
platforms.push(plat);
game.addChild(plat);
}
// Platform ve spike'ları güncelle
function updatePlatformsAndSpikes() {
// Platformları güncelle ve ekrandan çıkanları sil
for (var i = platforms.length - 1; i >= 0; i--) {
var plat = platforms[i];
plat.update();
if (plat.x + plat.width / 2 < -100) {
plat.destroy();
platforms.splice(i, 1);
}
}
// Yeni platform üret
var lastPlat = platforms.length > 0 ? platforms[platforms.length - 1] : null;
if (lastPlat && lastPlat.x < GAME_W - 500) {
spawnPlatform();
}
}
// Runner'ın platforma çarpıp çarpmadığını kontrol et
function checkRunnerPlatformCollision() {
runner.isOnGround = false;
for (var i = 0; i < platforms.length; i++) {
var plat = platforms[i];
// Runner'ın altı platformun üstüne değiyor mu?
var runnerBottom = runner.y;
var runnerTop = runner.y - runner.height;
var platTop = plat.y - plat.height / 2;
var platBottom = plat.y + plat.height / 2;
var runnerLeft = runner.x - runner.width / 2 + 10;
var runnerRight = runner.x + runner.width / 2 - 10;
var platLeft = plat.x - plat.width / 2;
var platRight = plat.x + plat.width / 2;
// Yalnızca runner aşağıya doğru hareket ediyorsa ve platformun üstüne iniyorsa
if (runner.vy >= 0 && runnerBottom > platTop && runnerTop < platTop && runnerRight > platLeft && runnerLeft < platRight) {
// Runner'ı platformun üstüne yerleştir
runner.y = platTop;
runner.vy = 0;
runner.isOnGround = true;
break;
}
}
// Eğer runner zemin seviyesine değerse, oyun biter
var groundTop = ground.y;
var runnerBottom = runner.y;
var runnerLeft = runner.x - runner.width / 2 + 10;
var runnerRight = runner.x + runner.width / 2 - 10;
var groundLeft = ground.x;
var groundRight = ground.x + ground.width;
// Runner'ın altı zeminin üstüne değiyorsa ve yatayda da çakışıyorsa
if (runnerBottom >= groundTop && runnerRight > groundLeft && runnerLeft < groundRight) {
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
return;
}
}
// Runner'ın spike'a çarpıp çarpmadığını kontrol et
// Runner ekran dışına düşerse oyun biter
function checkRunnerFall() {
if (runner.y > GAME_H + 200) {
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
}
}
// Skor güncelle (geçilen platform sayısı)
function updateScore() {
// Runner'ın geçtiği platformları say
for (var i = 0; i < platforms.length; i++) {
var plat = platforms[i];
if (!plat.passed && runner.x > plat.x + plat.width / 2) {
plat.passed = true;
score += 1;
scoreTxt.setText(score);
}
}
}
// Zorluk arttırıcı
function updateDifficulty() {
difficultyTimer++;
if (difficultyTimer % 300 === 0) {
// Her 5 saniyede bir
if (platformGapMax < 900) platformGapMax += 30;
if (platformSpeed < 32) platformSpeed += 0.5; // Daha yumuşak hız artışı için 0.5 artır
// Tüm platformların hızını güncelle
for (var i = 0; i < platforms.length; i++) {
platforms[i].speed = platformSpeed;
}
}
}
// Oyun güncelleme döngüsü
game.update = function () {
runner.update();
updatePlatformsAndSpikes();
checkRunnerPlatformCollision();
checkRunnerFall();
updateScore();
updateDifficulty();
};
// Dokunma/zıplama kontrolü
game.down = function (x, y, obj) {
runner.jump();
};
// Oyun başında runner'ı platformun üstüne yerleştir
(function placeRunnerOnFirstPlatform() {
if (platforms.length > 0) {
var plat = platforms[0];
runner.x = plat.x;
runner.y = plat.y - plat.height / 2;
}
})();