User prompt
Yukarı ve aşağidaki direklere temas halinde karakter ölmeli
User prompt
Direklere temas ettiğimizde oyunun bitmesi gerekiyor
User prompt
Geçtiğimiz engeller oyunun ortasında değil, altından ve üstünden iki ayrı direk olarak durmalı. Bizde iki direğin arasından geçmeliyiz
User prompt
Direkler aşağıdan ve yukarıdan gelmeli. bizde ikisinin ortadından geçmeliyiz.
User prompt
Oyunun akış hızını yüzde 50 azalt
Initial prompt
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Obstacle (coral/rock) class var Obstacle = Container.expand(function () { var self = Container.call(this); // Top or bottom self.isTop = false; self.passed = false; // Attach asset var obs = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.0 }); // For top obstacles, flip vertically self.setTop = function () { self.isTop = true; obs.scaleY = -1; obs.anchorY = 1.0; }; // Move left every frame self.update = function () { self.x -= obstacleSpeed; }; return self; }); // Penguin class var Penguin = Container.expand(function () { var self = Container.call(this); var penguinSprite = self.attachAsset('penguin', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = 0; self.gravity = 2.2; self.lift = -48; self.maxFall = 36; self.alive = true; // Flap animation self.flap = function () { if (!self.alive) return; self.velocity = self.lift; // Animate penguin up a bit tween(self, { rotation: -0.35 }, { duration: 120, easing: tween.cubicOut }); }; // Call every frame self.update = function () { if (!self.alive) return; self.velocity += self.gravity; if (self.velocity > self.maxFall) self.velocity = self.maxFall; self.y += self.velocity; // Rotate penguin based on velocity var targetRot = Math.max(-0.4, Math.min(0.7, self.velocity / 50)); tween(self, { rotation: targetRot }, { duration: 120, easing: tween.linear }); }; // On death self.die = function () { self.alive = false; tween(self, { rotation: 1.2 }, { duration: 400, easing: tween.cubicIn }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x6ec6f7 }); /**** * Game Code ****/ // Background (ocean blue, for parallax effect) // Sea floor/ceiling // Obstacle (coral/rock) - top and bottom // Penguin (player) // Game constants var GAP_SIZE = 420; // Gap between top and bottom obstacles var OBSTACLE_INTERVAL = 60; // Frames between obstacles var obstacleSpeed = 18; var penguinStartX = 600; var penguinStartY = 1366; var floorY = 2732 - 80; var ceilingY = 80; // Background var bg = LK.getAsset('bgwave', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.addChild(bg); // Sea floor var floor = LK.getAsset('seabound', { anchorX: 0, anchorY: 0, x: 0, y: floorY }); game.addChild(floor); // Sea ceiling var ceiling = LK.getAsset('seabound', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.addChild(ceiling); // Penguin var penguin = new Penguin(); penguin.x = penguinStartX; penguin.y = penguinStartY; game.addChild(penguin); // Obstacles array var obstacles = []; // Score var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Drag/tap handler var gameStarted = false; var gameOver = false; // Start the game on first tap function startGame() { if (!gameStarted) { gameStarted = true; } penguin.flap(); } // Touch/click events game.down = function (x, y, obj) { if (gameOver) return; startGame(); }; // No drag, so no move/up needed // Main update loop game.update = function () { if (gameOver) return; // Penguin physics penguin.update(); // Prevent penguin from going off top/ceiling if (penguin.y - 60 < ceilingY) { penguin.y = ceilingY + 60; penguin.velocity = 0; } // Prevent penguin from going below floor if (penguin.y + 60 > floorY) { penguin.y = floorY - 60; penguin.velocity = 0; penguin.die(); endGame(); return; } // Spawn obstacles if (gameStarted && LK.ticks % OBSTACLE_INTERVAL === 0) { var gapY = Math.floor(ceilingY + 200 + Math.random() * (floorY - ceilingY - GAP_SIZE - 400)); // Top obstacle var topObs = new Obstacle(); topObs.setTop(); topObs.x = 2048 + 90; topObs.y = gapY - GAP_SIZE / 2; obstacles.push(topObs); game.addChild(topObs); // Bottom obstacle var botObs = new Obstacle(); botObs.x = 2048 + 90; botObs.y = gapY + GAP_SIZE / 2; obstacles.push(botObs); game.addChild(botObs); } // Move and manage obstacles for (var i = obstacles.length - 1; i >= 0; i--) { var obs = obstacles[i]; obs.update(); // Remove if off screen if (obs.x < -200) { obs.destroy(); obstacles.splice(i, 1); continue; } // Collision with penguin if (penguin.alive && penguin.intersects(obs)) { penguin.die(); endGame(); return; } // Score: Only count bottom obstacles, and only once per pair if (!obs.isTop && !obs.passed && obs.x + 90 < penguin.x) { obs.passed = true; score += 1; scoreTxt.setText(score); } } }; // End game function endGame() { gameOver = true; // Flash red LK.effects.flashScreen(0xff0000, 800); // Show game over popup LK.setTimeout(function () { LK.showGameOver(); }, 800); }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Obstacle (coral/rock) class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
// Top or bottom
self.isTop = false;
self.passed = false;
// Attach asset
var obs = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.0
});
// For top obstacles, flip vertically
self.setTop = function () {
self.isTop = true;
obs.scaleY = -1;
obs.anchorY = 1.0;
};
// Move left every frame
self.update = function () {
self.x -= obstacleSpeed;
};
return self;
});
// Penguin class
var Penguin = Container.expand(function () {
var self = Container.call(this);
var penguinSprite = self.attachAsset('penguin', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = 0;
self.gravity = 2.2;
self.lift = -48;
self.maxFall = 36;
self.alive = true;
// Flap animation
self.flap = function () {
if (!self.alive) return;
self.velocity = self.lift;
// Animate penguin up a bit
tween(self, {
rotation: -0.35
}, {
duration: 120,
easing: tween.cubicOut
});
};
// Call every frame
self.update = function () {
if (!self.alive) return;
self.velocity += self.gravity;
if (self.velocity > self.maxFall) self.velocity = self.maxFall;
self.y += self.velocity;
// Rotate penguin based on velocity
var targetRot = Math.max(-0.4, Math.min(0.7, self.velocity / 50));
tween(self, {
rotation: targetRot
}, {
duration: 120,
easing: tween.linear
});
};
// On death
self.die = function () {
self.alive = false;
tween(self, {
rotation: 1.2
}, {
duration: 400,
easing: tween.cubicIn
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x6ec6f7
});
/****
* Game Code
****/
// Background (ocean blue, for parallax effect)
// Sea floor/ceiling
// Obstacle (coral/rock) - top and bottom
// Penguin (player)
// Game constants
var GAP_SIZE = 420; // Gap between top and bottom obstacles
var OBSTACLE_INTERVAL = 60; // Frames between obstacles
var obstacleSpeed = 18;
var penguinStartX = 600;
var penguinStartY = 1366;
var floorY = 2732 - 80;
var ceilingY = 80;
// Background
var bg = LK.getAsset('bgwave', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(bg);
// Sea floor
var floor = LK.getAsset('seabound', {
anchorX: 0,
anchorY: 0,
x: 0,
y: floorY
});
game.addChild(floor);
// Sea ceiling
var ceiling = LK.getAsset('seabound', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(ceiling);
// Penguin
var penguin = new Penguin();
penguin.x = penguinStartX;
penguin.y = penguinStartY;
game.addChild(penguin);
// Obstacles array
var obstacles = [];
// Score
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Drag/tap handler
var gameStarted = false;
var gameOver = false;
// Start the game on first tap
function startGame() {
if (!gameStarted) {
gameStarted = true;
}
penguin.flap();
}
// Touch/click events
game.down = function (x, y, obj) {
if (gameOver) return;
startGame();
};
// No drag, so no move/up needed
// Main update loop
game.update = function () {
if (gameOver) return;
// Penguin physics
penguin.update();
// Prevent penguin from going off top/ceiling
if (penguin.y - 60 < ceilingY) {
penguin.y = ceilingY + 60;
penguin.velocity = 0;
}
// Prevent penguin from going below floor
if (penguin.y + 60 > floorY) {
penguin.y = floorY - 60;
penguin.velocity = 0;
penguin.die();
endGame();
return;
}
// Spawn obstacles
if (gameStarted && LK.ticks % OBSTACLE_INTERVAL === 0) {
var gapY = Math.floor(ceilingY + 200 + Math.random() * (floorY - ceilingY - GAP_SIZE - 400));
// Top obstacle
var topObs = new Obstacle();
topObs.setTop();
topObs.x = 2048 + 90;
topObs.y = gapY - GAP_SIZE / 2;
obstacles.push(topObs);
game.addChild(topObs);
// Bottom obstacle
var botObs = new Obstacle();
botObs.x = 2048 + 90;
botObs.y = gapY + GAP_SIZE / 2;
obstacles.push(botObs);
game.addChild(botObs);
}
// Move and manage obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obs = obstacles[i];
obs.update();
// Remove if off screen
if (obs.x < -200) {
obs.destroy();
obstacles.splice(i, 1);
continue;
}
// Collision with penguin
if (penguin.alive && penguin.intersects(obs)) {
penguin.die();
endGame();
return;
}
// Score: Only count bottom obstacles, and only once per pair
if (!obs.isTop && !obs.passed && obs.x + 90 < penguin.x) {
obs.passed = true;
score += 1;
scoreTxt.setText(score);
}
}
};
// End game
function endGame() {
gameOver = true;
// Flash red
LK.effects.flashScreen(0xff0000, 800);
// Show game over popup
LK.setTimeout(function () {
LK.showGameOver();
}, 800);
}