/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Alien = Container.expand(function () { var self = Container.call(this); var alienGraphics = self.attachAsset('bomb', { // Using bomb asset as alien placeholder anchorX: 0.5, anchorY: 0.5 }); alienGraphics.scaleX = 3; alienGraphics.scaleY = 3; alienGraphics.tint = 0x00FF00; // Green tint for alien self.health = 50; self.maxHealth = 50; self.shootTimer = 0; self.moveTimer = 0; self.verticalDirection = 1; self.update = function () { // Move alien up and down self.moveTimer++; if (self.moveTimer >= 60) { self.verticalDirection *= -1; self.moveTimer = 0; } self.y += self.verticalDirection * 2; // Keep alien within bounds if (self.y < 400) self.y = 400; if (self.y > 1800) self.y = 1800; // Shoot at player self.shootTimer++; if (self.shootTimer >= 90) { // Shoot every 1.5 seconds shootAtPlayer(); self.shootTimer = 0; } }; return self; }); var AlienBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('thorn', { anchorX: 0.5, anchorY: 0.5 }); bulletGraphics.scaleX = 0.5; bulletGraphics.scaleY = 0.5; bulletGraphics.tint = 0xFF0000; // Red alien bullets self.velocityX = 0; self.velocityY = 0; self.hasHit = false; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; if (!self.hasHit && self.intersects(mario)) { self.hasHit = true; takeDamage(); } }; return self; }); var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.hasHit = false; self.verticalDirection = 0; // Always fly straight horizontally self.update = function () { // Move towards character (left) faster than game speed self.x -= gameSpeed + 6; // Birds fly straight horizontally - no vertical movement if (!self.hasHit && self.intersects(mario)) { self.hasHit = true; takeDamage(); } }; return self; }); var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 1.0 }); self.hasHit = false; self.update = function () { self.x -= gameSpeed; if (!self.hasHit && self.intersects(mario)) { self.hasHit = true; takeDamage(); } }; return self; }); var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.collected = false; self.update = function () { self.x -= gameSpeed; if (!self.collected && self.intersects(mario)) { self.collected = true; LK.setScore(LK.getScore() + 10); scoreTxt.setText(LK.getScore()); LK.getSound('coin').play(); self.alpha = 0; // Check if we collected coins to spawn door if (LK.getScore() % 200 === 0 && LK.getScore() > 0) { spawnDoor(); } } }; return self; }); var Door = Container.expand(function () { var self = Container.call(this); var doorGraphics = self.attachAsset('door', { anchorX: 0.5, anchorY: 1.0 }); self.hasEntered = false; self.update = function () { self.x -= gameSpeed; if (!self.hasEntered && self.intersects(mario)) { self.hasEntered = true; nextLevel(); } }; return self; }); var GameOverScreen = Container.expand(function () { var self = Container.call(this); self.visible = false; // Add background image var backgroundImg = self.attachAsset('gameOverBackground', { anchorX: 0.5, anchorY: 0.5 }); backgroundImg.x = 1024; backgroundImg.y = 800; // Game over image var gameOverImg = self.attachAsset('gameOverImage', { anchorX: 0.5, anchorY: 0.5 }); gameOverImg.x = 1024; gameOverImg.y = 800; // Coins collected text self.coinsText = new Text2('', { size: 80, fill: 0xFFD700 }); self.coinsText.anchor.set(0.5, 0.5); self.coinsText.x = 1024; self.coinsText.y = 1500; // Position lower on screen self.addChild(self.coinsText); // Retry text with bold black styling self.retryText = new Text2('TRY AGAIN', { size: 80, fill: 0x000000, fontStyle: 'bold' }); self.retryText.anchor.set(0.5, 0.5); self.retryText.x = 1024; self.retryText.y = 1700; self.addChild(self.retryText); self.retryText.down = function (x, y, obj) { // Restart game when retry text is clicked LK.stopMusic(); self.hide(); restartGame(); }; self.show = function (coinCount) { self.coinsText.setText('TOPLANAN COIN ' + coinCount); self.visible = true; LK.playMusic('gameOverMusic'); // Start upward movement animation for 5 seconds var startY = self.coinsText.y; var targetY = startY - 100; // Move up 100 pixels tween(self.coinsText, { y: targetY }, { duration: 2500, easing: tween.easeInOut }); tween(self.coinsText, { y: startY }, { duration: 2500, easing: tween.easeInOut, onFinish: function onFinish() { // Animation complete after 5 seconds total } }); }; self.hide = function () { self.visible = false; }; self.down = function (x, y, obj) { // Restart game when clicked LK.stopMusic(); self.hide(); restartGame(); }; return self; }); var Ground = Container.expand(function () { var self = Container.call(this); var groundGraphics = self.attachAsset('ground', { anchorX: 0, anchorY: 0 }); self.update = function () { self.x -= gameSpeed; }; return self; }); var Mario = Container.expand(function () { var self = Container.call(this); var marioGraphics = self.attachAsset('mario', { anchorX: 0.5, anchorY: 1.0 }); self.velocityY = 0; self.gravity = 0.8; self.jumpPower = -30; self.isOnGround = false; self.isJumping = false; self.jump = function () { if (self.isOnGround && !self.isJumping) { self.velocityY = self.jumpPower; self.isOnGround = false; self.isJumping = true; LK.getSound('jump').play(); } }; self.update = function () { self.velocityY += self.gravity; self.y += self.velocityY; // Check platform collisions var onPlatform = false; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; // Better platform collision - check if Mario is above platform and falling down var marioBottom = self.y; var platformTop = platform.y - 10; var platformLeft = platform.x - 300; // Half of platform width (600/2) var platformRight = platform.x + 300; // Half of platform width (600/2) if (self.velocityY >= 0 && marioBottom >= platformTop - 20 && marioBottom <= platformTop + 20 && self.x >= platformLeft && self.x <= platformRight) { self.y = platformTop; self.velocityY = 0; self.isOnGround = true; self.isJumping = false; onPlatform = true; break; } } // Check ground collision if (!onPlatform && self.y >= groundY) { self.y = groundY; self.velocityY = 0; self.isOnGround = true; self.isJumping = false; } }; return self; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.x -= gameSpeed; }; return self; }); var PlayerBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); bulletGraphics.scaleX = 0.7; bulletGraphics.scaleY = 0.7; bulletGraphics.tint = 0x0000FF; // Blue player bullets self.velocityX = 15; self.velocityY = 0; self.hasHit = false; self.update = function () { self.x += self.velocityX; if (!self.hasHit && alien && self.intersects(alien)) { self.hasHit = true; alien.health--; if (alien.health <= 0) { defeatedAlien(); } updateAlienHealthBar(); } }; return self; }); var Thorn = Container.expand(function () { var self = Container.call(this); var thornGraphics = self.attachAsset('thorn', { anchorX: 0.5, anchorY: 1.0 }); self.hasHit = false; self.update = function () { self.x -= gameSpeed; if (!self.hasHit && self.intersects(mario)) { self.hasHit = true; takeDamage(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ var mario; var groundTiles = []; var coins = []; var bombs = []; var thorns = []; var platforms = []; var hearts = []; var doors = []; var birds = []; var gameSpeed = 10; var groundY = 2400; var maxHealth = 5; var currentHealth = maxHealth; var spawnTimer = 0; var gameStarted = false; var gameOver = false; var currentLevel = storage.currentLevel || 1; var doorSpawned = false; var gameOverScreen; var levelTxt = new Text2('Level ' + currentLevel, { size: 60, fill: 0xFFFFFF }); levelTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(levelTxt); levelTxt.x = 120; // Avoid the platform menu icon levelTxt.y = 20; var scoreTxt = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var startButton = new Text2('PLAY', { size: 120, fill: 0xFFFFFF }); startButton.anchor.set(0.5, 0.5); LK.gui.center.addChild(startButton); var healthInfoText = new Text2('(Oyunda 5 canınız vardır)', { size: 100, fill: 0xFF0000 }); healthInfoText.anchor.set(0.5, 0.5); healthInfoText.x = 0; healthInfoText.y = 100; // Position below the play button LK.gui.center.addChild(healthInfoText); var healthInfoEnglishText = new Text2('( You have 5 lives )', { size: 100, fill: 0xFF0000 }); healthInfoEnglishText.anchor.set(0.5, 0.5); healthInfoEnglishText.x = 0; healthInfoEnglishText.y = 200; // Position below the Turkish text LK.gui.center.addChild(healthInfoEnglishText); // Add background image to start screen immediately var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); background.x = 0; background.y = 0; // Play start music on game load LK.playMusic('startMusic'); function initializeGame() { game.setBackgroundColor(0x87ceeb); // Destroy existing Mario if it exists if (mario) { mario.destroy(); } mario = game.addChild(new Mario()); mario.x = 300; mario.y = groundY; for (var i = 0; i < 15; i++) { var ground = game.addChild(new Ground()); ground.x = i * 200; ground.y = groundY; groundTiles.push(ground); } if (!gameOverScreen) { gameOverScreen = game.addChild(new GameOverScreen()); } gameStarted = true; gameOver = false; startButton.visible = false; healthInfoText.visible = false; healthInfoEnglishText.visible = false; gameSpeed = 10 + (currentLevel - 1) * 3; // Adjust speed based on level levelTxt.setText('Level ' + currentLevel); game.setBackgroundColor(0x87ceeb); LK.stopMusic(); } function takeDamage() { if (currentHealth > 0) { currentHealth--; LK.getSound('hurt').play(); LK.effects.flashScreen(0xff0000, 300); if (currentHealth <= 0) { // Show custom game over screen with coin count gameOverScreen.show(LK.getScore()); gameStarted = false; // Stop game updates gameOver = true; // Prevent character movement } } } function nextLevel() { currentLevel++; storage.currentLevel = currentLevel; levelTxt.setText('Level ' + currentLevel); // Show level announcement showLevelAnnouncement(); // Increase speed each level gameSpeed = 10 + (currentLevel - 1) * 3; // Clear obstacles but keep coins and score for (var i = 0; i < doors.length; i++) { doors[i].destroy(); } doors = []; doorSpawned = false; for (var i = 0; i < bombs.length; i++) { bombs[i].destroy(); } bombs = []; for (var i = 0; i < thorns.length; i++) { thorns[i].destroy(); } thorns = []; for (var i = 0; i < platforms.length; i++) { platforms[i].destroy(); } platforms = []; for (var i = 0; i < birds.length; i++) { birds[i].destroy(); } birds = []; // Reset Mario position but keep coins mario.x = 300; mario.y = groundY; mario.velocityY = 0; mario.isOnGround = true; mario.isJumping = false; } function restartGame() { // Reset all game variables currentHealth = maxHealth; currentLevel = 1; storage.currentLevel = currentLevel; doorSpawned = false; spawnTimer = 0; gameSpeed = 10; gameOver = false; // Clear all objects for (var i = 0; i < coins.length; i++) { coins[i].destroy(); } coins = []; for (var i = 0; i < bombs.length; i++) { bombs[i].destroy(); } bombs = []; for (var i = 0; i < thorns.length; i++) { thorns[i].destroy(); } thorns = []; for (var i = 0; i < platforms.length; i++) { platforms[i].destroy(); } platforms = []; for (var i = 0; i < doors.length; i++) { doors[i].destroy(); } doors = []; for (var i = 0; i < birds.length; i++) { birds[i].destroy(); } birds = []; // Reset Mario mario.x = 300; mario.y = groundY; mario.velocityY = 0; mario.isOnGround = true; mario.isJumping = false; // Reset score and UI LK.setScore(0); scoreTxt.setText('0'); levelTxt.setText('Level ' + currentLevel); gameStarted = false; startButton.visible = true; healthInfoText.visible = true; healthInfoEnglishText.visible = true; LK.playMusic('startMusic'); } function spawnDoor() { if (!doorSpawned) { var door = game.addChild(new Door()); door.x = 2400; // Spawn further away to give player time door.y = groundY; doors.push(door); doorSpawned = true; } } function spawnObstacle() { // Don't spawn obstacles if door is active if (doorSpawned) { return; } var rand = Math.random(); var spawnX = 2200; if (rand < 0.25) { var coin = game.addChild(new Coin()); coin.x = spawnX; coin.y = groundY - 100 - Math.random() * 150; coins.push(coin); } else if (rand < 0.45) { var bomb = game.addChild(new Bomb()); bomb.x = spawnX + Math.random() * 100 + 50; // Add spacing variation bomb.y = groundY; bombs.push(bomb); } else if (rand < 0.65) { var thorn = game.addChild(new Thorn()); thorn.x = spawnX + Math.random() * 100 + 50; // Add spacing variation thorn.y = groundY; thorns.push(thorn); } else if (rand < 0.85) { // Spawn platform with coins on top var platform = game.addChild(new Platform()); platform.x = spawnX + Math.random() * 200 + 100; // Random horizontal position platform.y = groundY - 200 - Math.random() * 300; // Random height platforms.push(platform); // Add 4-6 coins on the platform (spread across the long plank) var numCoins = 4 + Math.floor(Math.random() * 3); for (var i = 0; i < numCoins; i++) { var coin = game.addChild(new Coin()); coin.x = platform.x - 280 + i * 140; // Spread coins across the 600px wide plank coin.y = platform.y - 60; coins.push(coin); } } else { // Spawn flying bird var bird = game.addChild(new Bird()); bird.x = spawnX + Math.random() * 100 + 50; // Spawn birds either from top or bottom of screen if (Math.random() < 0.5) { // Spawn from top at platform level bird.y = groundY - 200; bird.verticalDirection = 0; // Fly straight horizontally } else { // Spawn from bottom bird.y = groundY - 100; bird.verticalDirection = 0; // Fly straight horizontally } birds.push(bird); } } function cleanupObjects() { for (var i = coins.length - 1; i >= 0; i--) { if (coins[i].x < -100) { coins[i].destroy(); coins.splice(i, 1); } } for (var i = bombs.length - 1; i >= 0; i--) { if (bombs[i].x < -100) { bombs[i].destroy(); bombs.splice(i, 1); } } for (var i = thorns.length - 1; i >= 0; i--) { if (thorns[i].x < -100) { thorns[i].destroy(); thorns.splice(i, 1); } } for (var i = platforms.length - 1; i >= 0; i--) { if (platforms[i].x < -500) { platforms[i].destroy(); platforms.splice(i, 1); } } for (var i = doors.length - 1; i >= 0; i--) { if (doors[i].x < -100) { doors[i].destroy(); doors.splice(i, 1); } } for (var i = birds.length - 1; i >= 0; i--) { if (birds[i].x < -100) { birds[i].destroy(); birds.splice(i, 1); } } for (var i = groundTiles.length - 1; i >= 0; i--) { if (groundTiles[i].x < -400) { var ground = game.addChild(new Ground()); ground.x = groundTiles[groundTiles.length - 1].x + 200; ground.y = groundY; groundTiles.push(ground); groundTiles[i].destroy(); groundTiles.splice(i, 1); } } } game.down = function (x, y, obj) { if (!gameStarted) { initializeGame(); } else if (!gameOver) { mario.jump(); } }; startButton.down = function (x, y, obj) { initializeGame(); }; var levelAnnouncementTxt = null; var levelAnnouncementTimer = 0; function showLevelAnnouncement() { if (levelAnnouncementTxt) { LK.gui.center.removeChild(levelAnnouncementTxt); } levelAnnouncementTxt = new Text2(currentLevel + '. LEVEL', { size: 120, fill: 0xFFD700 }); levelAnnouncementTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(levelAnnouncementTxt); levelAnnouncementTimer = 120; // Show for 2 seconds at 60fps } game.update = function () { if (!gameStarted) { return; } // Handle level announcement display if (levelAnnouncementTimer > 0) { levelAnnouncementTimer--; if (levelAnnouncementTimer <= 0 && levelAnnouncementTxt) { LK.gui.center.removeChild(levelAnnouncementTxt); levelAnnouncementTxt = null; } return; // Don't spawn obstacles while showing level announcement } spawnTimer++; if (spawnTimer >= 60) { // Reduced from 90 to 60 for faster spawning spawnObstacle(); spawnTimer = 0; } cleanupObjects(); gameSpeed += 0.005; };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Alien = Container.expand(function () {
var self = Container.call(this);
var alienGraphics = self.attachAsset('bomb', {
// Using bomb asset as alien placeholder
anchorX: 0.5,
anchorY: 0.5
});
alienGraphics.scaleX = 3;
alienGraphics.scaleY = 3;
alienGraphics.tint = 0x00FF00; // Green tint for alien
self.health = 50;
self.maxHealth = 50;
self.shootTimer = 0;
self.moveTimer = 0;
self.verticalDirection = 1;
self.update = function () {
// Move alien up and down
self.moveTimer++;
if (self.moveTimer >= 60) {
self.verticalDirection *= -1;
self.moveTimer = 0;
}
self.y += self.verticalDirection * 2;
// Keep alien within bounds
if (self.y < 400) self.y = 400;
if (self.y > 1800) self.y = 1800;
// Shoot at player
self.shootTimer++;
if (self.shootTimer >= 90) {
// Shoot every 1.5 seconds
shootAtPlayer();
self.shootTimer = 0;
}
};
return self;
});
var AlienBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('thorn', {
anchorX: 0.5,
anchorY: 0.5
});
bulletGraphics.scaleX = 0.5;
bulletGraphics.scaleY = 0.5;
bulletGraphics.tint = 0xFF0000; // Red alien bullets
self.velocityX = 0;
self.velocityY = 0;
self.hasHit = false;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
if (!self.hasHit && self.intersects(mario)) {
self.hasHit = true;
takeDamage();
}
};
return self;
});
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.hasHit = false;
self.verticalDirection = 0; // Always fly straight horizontally
self.update = function () {
// Move towards character (left) faster than game speed
self.x -= gameSpeed + 6;
// Birds fly straight horizontally - no vertical movement
if (!self.hasHit && self.intersects(mario)) {
self.hasHit = true;
takeDamage();
}
};
return self;
});
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 1.0
});
self.hasHit = false;
self.update = function () {
self.x -= gameSpeed;
if (!self.hasHit && self.intersects(mario)) {
self.hasHit = true;
takeDamage();
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.update = function () {
self.x -= gameSpeed;
if (!self.collected && self.intersects(mario)) {
self.collected = true;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
LK.getSound('coin').play();
self.alpha = 0;
// Check if we collected coins to spawn door
if (LK.getScore() % 200 === 0 && LK.getScore() > 0) {
spawnDoor();
}
}
};
return self;
});
var Door = Container.expand(function () {
var self = Container.call(this);
var doorGraphics = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 1.0
});
self.hasEntered = false;
self.update = function () {
self.x -= gameSpeed;
if (!self.hasEntered && self.intersects(mario)) {
self.hasEntered = true;
nextLevel();
}
};
return self;
});
var GameOverScreen = Container.expand(function () {
var self = Container.call(this);
self.visible = false;
// Add background image
var backgroundImg = self.attachAsset('gameOverBackground', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundImg.x = 1024;
backgroundImg.y = 800;
// Game over image
var gameOverImg = self.attachAsset('gameOverImage', {
anchorX: 0.5,
anchorY: 0.5
});
gameOverImg.x = 1024;
gameOverImg.y = 800;
// Coins collected text
self.coinsText = new Text2('', {
size: 80,
fill: 0xFFD700
});
self.coinsText.anchor.set(0.5, 0.5);
self.coinsText.x = 1024;
self.coinsText.y = 1500; // Position lower on screen
self.addChild(self.coinsText);
// Retry text with bold black styling
self.retryText = new Text2('TRY AGAIN', {
size: 80,
fill: 0x000000,
fontStyle: 'bold'
});
self.retryText.anchor.set(0.5, 0.5);
self.retryText.x = 1024;
self.retryText.y = 1700;
self.addChild(self.retryText);
self.retryText.down = function (x, y, obj) {
// Restart game when retry text is clicked
LK.stopMusic();
self.hide();
restartGame();
};
self.show = function (coinCount) {
self.coinsText.setText('TOPLANAN COIN ' + coinCount);
self.visible = true;
LK.playMusic('gameOverMusic');
// Start upward movement animation for 5 seconds
var startY = self.coinsText.y;
var targetY = startY - 100; // Move up 100 pixels
tween(self.coinsText, {
y: targetY
}, {
duration: 2500,
easing: tween.easeInOut
});
tween(self.coinsText, {
y: startY
}, {
duration: 2500,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Animation complete after 5 seconds total
}
});
};
self.hide = function () {
self.visible = false;
};
self.down = function (x, y, obj) {
// Restart game when clicked
LK.stopMusic();
self.hide();
restartGame();
};
return self;
});
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
self.update = function () {
self.x -= gameSpeed;
};
return self;
});
var Mario = Container.expand(function () {
var self = Container.call(this);
var marioGraphics = self.attachAsset('mario', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityY = 0;
self.gravity = 0.8;
self.jumpPower = -30;
self.isOnGround = false;
self.isJumping = false;
self.jump = function () {
if (self.isOnGround && !self.isJumping) {
self.velocityY = self.jumpPower;
self.isOnGround = false;
self.isJumping = true;
LK.getSound('jump').play();
}
};
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Check platform collisions
var onPlatform = false;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
// Better platform collision - check if Mario is above platform and falling down
var marioBottom = self.y;
var platformTop = platform.y - 10;
var platformLeft = platform.x - 300; // Half of platform width (600/2)
var platformRight = platform.x + 300; // Half of platform width (600/2)
if (self.velocityY >= 0 && marioBottom >= platformTop - 20 && marioBottom <= platformTop + 20 && self.x >= platformLeft && self.x <= platformRight) {
self.y = platformTop;
self.velocityY = 0;
self.isOnGround = true;
self.isJumping = false;
onPlatform = true;
break;
}
}
// Check ground collision
if (!onPlatform && self.y >= groundY) {
self.y = groundY;
self.velocityY = 0;
self.isOnGround = true;
self.isJumping = false;
}
};
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x -= gameSpeed;
};
return self;
});
var PlayerBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
bulletGraphics.scaleX = 0.7;
bulletGraphics.scaleY = 0.7;
bulletGraphics.tint = 0x0000FF; // Blue player bullets
self.velocityX = 15;
self.velocityY = 0;
self.hasHit = false;
self.update = function () {
self.x += self.velocityX;
if (!self.hasHit && alien && self.intersects(alien)) {
self.hasHit = true;
alien.health--;
if (alien.health <= 0) {
defeatedAlien();
}
updateAlienHealthBar();
}
};
return self;
});
var Thorn = Container.expand(function () {
var self = Container.call(this);
var thornGraphics = self.attachAsset('thorn', {
anchorX: 0.5,
anchorY: 1.0
});
self.hasHit = false;
self.update = function () {
self.x -= gameSpeed;
if (!self.hasHit && self.intersects(mario)) {
self.hasHit = true;
takeDamage();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var mario;
var groundTiles = [];
var coins = [];
var bombs = [];
var thorns = [];
var platforms = [];
var hearts = [];
var doors = [];
var birds = [];
var gameSpeed = 10;
var groundY = 2400;
var maxHealth = 5;
var currentHealth = maxHealth;
var spawnTimer = 0;
var gameStarted = false;
var gameOver = false;
var currentLevel = storage.currentLevel || 1;
var doorSpawned = false;
var gameOverScreen;
var levelTxt = new Text2('Level ' + currentLevel, {
size: 60,
fill: 0xFFFFFF
});
levelTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(levelTxt);
levelTxt.x = 120; // Avoid the platform menu icon
levelTxt.y = 20;
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var startButton = new Text2('PLAY', {
size: 120,
fill: 0xFFFFFF
});
startButton.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startButton);
var healthInfoText = new Text2('(Oyunda 5 canınız vardır)', {
size: 100,
fill: 0xFF0000
});
healthInfoText.anchor.set(0.5, 0.5);
healthInfoText.x = 0;
healthInfoText.y = 100; // Position below the play button
LK.gui.center.addChild(healthInfoText);
var healthInfoEnglishText = new Text2('( You have 5 lives )', {
size: 100,
fill: 0xFF0000
});
healthInfoEnglishText.anchor.set(0.5, 0.5);
healthInfoEnglishText.x = 0;
healthInfoEnglishText.y = 200; // Position below the Turkish text
LK.gui.center.addChild(healthInfoEnglishText);
// Add background image to start screen immediately
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
// Play start music on game load
LK.playMusic('startMusic');
function initializeGame() {
game.setBackgroundColor(0x87ceeb);
// Destroy existing Mario if it exists
if (mario) {
mario.destroy();
}
mario = game.addChild(new Mario());
mario.x = 300;
mario.y = groundY;
for (var i = 0; i < 15; i++) {
var ground = game.addChild(new Ground());
ground.x = i * 200;
ground.y = groundY;
groundTiles.push(ground);
}
if (!gameOverScreen) {
gameOverScreen = game.addChild(new GameOverScreen());
}
gameStarted = true;
gameOver = false;
startButton.visible = false;
healthInfoText.visible = false;
healthInfoEnglishText.visible = false;
gameSpeed = 10 + (currentLevel - 1) * 3; // Adjust speed based on level
levelTxt.setText('Level ' + currentLevel);
game.setBackgroundColor(0x87ceeb);
LK.stopMusic();
}
function takeDamage() {
if (currentHealth > 0) {
currentHealth--;
LK.getSound('hurt').play();
LK.effects.flashScreen(0xff0000, 300);
if (currentHealth <= 0) {
// Show custom game over screen with coin count
gameOverScreen.show(LK.getScore());
gameStarted = false; // Stop game updates
gameOver = true; // Prevent character movement
}
}
}
function nextLevel() {
currentLevel++;
storage.currentLevel = currentLevel;
levelTxt.setText('Level ' + currentLevel);
// Show level announcement
showLevelAnnouncement();
// Increase speed each level
gameSpeed = 10 + (currentLevel - 1) * 3;
// Clear obstacles but keep coins and score
for (var i = 0; i < doors.length; i++) {
doors[i].destroy();
}
doors = [];
doorSpawned = false;
for (var i = 0; i < bombs.length; i++) {
bombs[i].destroy();
}
bombs = [];
for (var i = 0; i < thorns.length; i++) {
thorns[i].destroy();
}
thorns = [];
for (var i = 0; i < platforms.length; i++) {
platforms[i].destroy();
}
platforms = [];
for (var i = 0; i < birds.length; i++) {
birds[i].destroy();
}
birds = [];
// Reset Mario position but keep coins
mario.x = 300;
mario.y = groundY;
mario.velocityY = 0;
mario.isOnGround = true;
mario.isJumping = false;
}
function restartGame() {
// Reset all game variables
currentHealth = maxHealth;
currentLevel = 1;
storage.currentLevel = currentLevel;
doorSpawned = false;
spawnTimer = 0;
gameSpeed = 10;
gameOver = false;
// Clear all objects
for (var i = 0; i < coins.length; i++) {
coins[i].destroy();
}
coins = [];
for (var i = 0; i < bombs.length; i++) {
bombs[i].destroy();
}
bombs = [];
for (var i = 0; i < thorns.length; i++) {
thorns[i].destroy();
}
thorns = [];
for (var i = 0; i < platforms.length; i++) {
platforms[i].destroy();
}
platforms = [];
for (var i = 0; i < doors.length; i++) {
doors[i].destroy();
}
doors = [];
for (var i = 0; i < birds.length; i++) {
birds[i].destroy();
}
birds = [];
// Reset Mario
mario.x = 300;
mario.y = groundY;
mario.velocityY = 0;
mario.isOnGround = true;
mario.isJumping = false;
// Reset score and UI
LK.setScore(0);
scoreTxt.setText('0');
levelTxt.setText('Level ' + currentLevel);
gameStarted = false;
startButton.visible = true;
healthInfoText.visible = true;
healthInfoEnglishText.visible = true;
LK.playMusic('startMusic');
}
function spawnDoor() {
if (!doorSpawned) {
var door = game.addChild(new Door());
door.x = 2400; // Spawn further away to give player time
door.y = groundY;
doors.push(door);
doorSpawned = true;
}
}
function spawnObstacle() {
// Don't spawn obstacles if door is active
if (doorSpawned) {
return;
}
var rand = Math.random();
var spawnX = 2200;
if (rand < 0.25) {
var coin = game.addChild(new Coin());
coin.x = spawnX;
coin.y = groundY - 100 - Math.random() * 150;
coins.push(coin);
} else if (rand < 0.45) {
var bomb = game.addChild(new Bomb());
bomb.x = spawnX + Math.random() * 100 + 50; // Add spacing variation
bomb.y = groundY;
bombs.push(bomb);
} else if (rand < 0.65) {
var thorn = game.addChild(new Thorn());
thorn.x = spawnX + Math.random() * 100 + 50; // Add spacing variation
thorn.y = groundY;
thorns.push(thorn);
} else if (rand < 0.85) {
// Spawn platform with coins on top
var platform = game.addChild(new Platform());
platform.x = spawnX + Math.random() * 200 + 100; // Random horizontal position
platform.y = groundY - 200 - Math.random() * 300; // Random height
platforms.push(platform);
// Add 4-6 coins on the platform (spread across the long plank)
var numCoins = 4 + Math.floor(Math.random() * 3);
for (var i = 0; i < numCoins; i++) {
var coin = game.addChild(new Coin());
coin.x = platform.x - 280 + i * 140; // Spread coins across the 600px wide plank
coin.y = platform.y - 60;
coins.push(coin);
}
} else {
// Spawn flying bird
var bird = game.addChild(new Bird());
bird.x = spawnX + Math.random() * 100 + 50;
// Spawn birds either from top or bottom of screen
if (Math.random() < 0.5) {
// Spawn from top at platform level
bird.y = groundY - 200;
bird.verticalDirection = 0; // Fly straight horizontally
} else {
// Spawn from bottom
bird.y = groundY - 100;
bird.verticalDirection = 0; // Fly straight horizontally
}
birds.push(bird);
}
}
function cleanupObjects() {
for (var i = coins.length - 1; i >= 0; i--) {
if (coins[i].x < -100) {
coins[i].destroy();
coins.splice(i, 1);
}
}
for (var i = bombs.length - 1; i >= 0; i--) {
if (bombs[i].x < -100) {
bombs[i].destroy();
bombs.splice(i, 1);
}
}
for (var i = thorns.length - 1; i >= 0; i--) {
if (thorns[i].x < -100) {
thorns[i].destroy();
thorns.splice(i, 1);
}
}
for (var i = platforms.length - 1; i >= 0; i--) {
if (platforms[i].x < -500) {
platforms[i].destroy();
platforms.splice(i, 1);
}
}
for (var i = doors.length - 1; i >= 0; i--) {
if (doors[i].x < -100) {
doors[i].destroy();
doors.splice(i, 1);
}
}
for (var i = birds.length - 1; i >= 0; i--) {
if (birds[i].x < -100) {
birds[i].destroy();
birds.splice(i, 1);
}
}
for (var i = groundTiles.length - 1; i >= 0; i--) {
if (groundTiles[i].x < -400) {
var ground = game.addChild(new Ground());
ground.x = groundTiles[groundTiles.length - 1].x + 200;
ground.y = groundY;
groundTiles.push(ground);
groundTiles[i].destroy();
groundTiles.splice(i, 1);
}
}
}
game.down = function (x, y, obj) {
if (!gameStarted) {
initializeGame();
} else if (!gameOver) {
mario.jump();
}
};
startButton.down = function (x, y, obj) {
initializeGame();
};
var levelAnnouncementTxt = null;
var levelAnnouncementTimer = 0;
function showLevelAnnouncement() {
if (levelAnnouncementTxt) {
LK.gui.center.removeChild(levelAnnouncementTxt);
}
levelAnnouncementTxt = new Text2(currentLevel + '. LEVEL', {
size: 120,
fill: 0xFFD700
});
levelAnnouncementTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(levelAnnouncementTxt);
levelAnnouncementTimer = 120; // Show for 2 seconds at 60fps
}
game.update = function () {
if (!gameStarted) {
return;
}
// Handle level announcement display
if (levelAnnouncementTimer > 0) {
levelAnnouncementTimer--;
if (levelAnnouncementTimer <= 0 && levelAnnouncementTxt) {
LK.gui.center.removeChild(levelAnnouncementTxt);
levelAnnouncementTxt = null;
}
return; // Don't spawn obstacles while showing level announcement
}
spawnTimer++;
if (spawnTimer >= 60) {
// Reduced from 90 to 60 for faster spawning
spawnObstacle();
spawnTimer = 0;
}
cleanupObjects();
gameSpeed += 0.005;
};
ince bir çimenli zemin. In-Game asset. 2d. High contrast. No shadows
bomb. In-Game asset. 2d. High contrast. No shadows
altın para. In-Game asset. 2d. High contrast. No shadows
dikenler. In-Game asset. 2d. High contrast. No shadows
bulutlu bir hava. In-Game asset. 2d. High contrast. No shadows
portal. In-Game asset. 2d. High contrast. No shadows
sinirli bir uçan kuş. In-Game asset. 2d. High contrast. No shadows
red heart. In-Game asset. 2d. High contrast. No shadows