User prompt
oyunu kolaylaştıralım
Code edit (1 edits merged)
Please save this source code
User prompt
Zıplayan Kutu
Initial prompt
🎮 1. Zıplayan Kutu Amaç: Ekrandaki kutuyu boşluklara düşmeden sağa doğru götür. Nasıl oynanır: Sadece “zıpla” butonu var. Platformlar arasında boşluklar var. Zıplamazsan düşersin. 10 platform geçersen oyun biter. Kodlama zorluğu: Çok kolay Süre: 1-2 dakika
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Box (player) class var Box = Container.expand(function () { var self = Container.call(this); // Box asset: square var box = self.attachAsset('box', { anchorX: 0.5, anchorY: 0.5 }); box.width = 120; box.height = 120; // Physics self.vx = 0; self.vy = 0; self.isJumping = false; // For collision, use self's position and box's size self.getBounds = function () { return { x: self.x - box.width / 2, y: self.y - box.height / 2, width: box.width, height: box.height }; }; return self; }); // Platform class: a static platform the box can land on var Platform = Container.expand(function () { var self = Container.call(this); // Platform asset: wide, short rectangle var plat = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); // Set default width/height for platform plat.width = 400; plat.height = 60; // For collision, use self's position and plat's size self.getBounds = function () { return { x: self.x - plat.width / 2, y: self.y - plat.height / 2, width: plat.width, height: plat.height }; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222244 }); /**** * Game Code ****/ // Game constants // Platform and box colors var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; var PLATFORM_WIDTH = 520; var PLATFORM_HEIGHT = 60; var BOX_SIZE = 120; var PLATFORM_GAP_MIN = 120; var PLATFORM_GAP_MAX = 220; var PLATFORM_Y = GAME_HEIGHT * 0.7; var BOX_START_X = 400; var BOX_START_Y = PLATFORM_Y - PLATFORM_HEIGHT / 2 - BOX_SIZE / 2; var SCROLL_SPEED = 10; // px per frame var JUMP_VY = -44; // initial jump velocity (higher jump) var GRAVITY = 2.2; // gravity per frame (slower fall) var WIN_PLATFORMS = 10; // Game state var platforms = []; var box; var currentPlatformIndex = 0; var jumpButton; var scoreText; var isGameOver = false; var isYouWin = false; var platformsPassed = 0; // --- UI: Score --- scoreText = new Text2('0 / ' + WIN_PLATFORMS, { size: 100, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // --- UI: Jump Button --- jumpButton = new Container(); var btnBg = jumpButton.attachAsset('jumpbtn', { anchorX: 0.5, anchorY: 0.5 }); btnBg.width = 400; btnBg.height = 180; btnBg.tint = 0xFF5A36; var btnLabel = new Text2('Zıpla', { size: 80, fill: "#fff" }); btnLabel.anchor.set(0.5, 0.5); jumpButton.addChild(btnLabel); // Place button at bottom center, above bottom edge jumpButton.x = GAME_WIDTH / 2; jumpButton.y = GAME_HEIGHT - 250; game.addChild(jumpButton); // --- Create Platforms --- function createInitialPlatforms() { // Clear old for (var i = 0; i < platforms.length; i++) { platforms[i].destroy(); } platforms = []; var x = BOX_START_X - 100; // Start a bit left of box for (var i = 0; i < WIN_PLATFORMS + 2; i++) { var plat = new Platform(); plat.x = x; plat.y = PLATFORM_Y; game.addChild(plat); platforms.push(plat); // Next platform: random gap var gap = PLATFORM_GAP_MIN + Math.floor(Math.random() * (PLATFORM_GAP_MAX - PLATFORM_GAP_MIN)); x += PLATFORM_WIDTH + gap; } } // --- Create Box --- function createBox() { if (box) box.destroy(); box = new Box(); box.x = BOX_START_X; box.y = BOX_START_Y; box.vx = 0; box.vy = 0; box.isJumping = false; game.addChild(box); } // --- Reset Game State --- function resetGame() { isGameOver = false; isYouWin = false; platformsPassed = 0; currentPlatformIndex = 0; scoreText.setText('0 / ' + WIN_PLATFORMS); createInitialPlatforms(); createBox(); } // --- Platform Collision Detection --- function boxOnPlatform() { // Check if box is standing on any platform (from currentPlatformIndex and next) var bounds = box.getBounds(); for (var i = 0; i < platforms.length; i++) { var plat = platforms[i]; var pb = plat.getBounds(); // Only check platforms under/near the box if (bounds.x + bounds.width * 0.7 > pb.x && bounds.x + bounds.width * 0.3 < pb.x + pb.width && Math.abs(bounds.y + bounds.height - pb.y) < 30 && box.vy >= 0) { return plat; } } return null; } // --- Game Over --- function triggerGameOver() { if (isGameOver) return; isGameOver = true; LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); } // --- You Win --- function triggerYouWin() { if (isYouWin) return; isYouWin = true; LK.effects.flashScreen(0x00ff00, 800); LK.showYouWin(); } // --- Handle Jump Button --- jumpButton.down = function (x, y, obj) { if (isGameOver || isYouWin) return; if (!box.isJumping) { box.vy = JUMP_VY; box.isJumping = true; // Animate button press tween(jumpButton, { scaleX: 0.92, scaleY: 0.92 }, { duration: 80, easing: tween.easeIn, onFinish: function onFinish() { tween(jumpButton, { scaleX: 1, scaleY: 1 }, { duration: 80, easing: tween.easeOut }); } }); } }; // --- Main Game Update --- game.update = function () { if (isGameOver || isYouWin) return; // --- Move platforms left (simulate box moving right) --- for (var i = 0; i < platforms.length; i++) { platforms[i].x -= SCROLL_SPEED; } // --- Move box horizontally (box stays at fixed x, but can fall/jump) --- // Gravity box.vy += GRAVITY; box.y += box.vy; // --- Platform collision --- var landedPlat = boxOnPlatform(); if (landedPlat) { // Snap box to platform box.y = landedPlat.y - PLATFORM_HEIGHT / 2 - BOX_SIZE / 2; box.vy = 0; box.isJumping = false; } else { // If box falls below screen, game over if (box.y > GAME_HEIGHT + BOX_SIZE) { triggerGameOver(); return; } } // --- Check if box passed a platform --- // Find the next platform to pass var nextPlat = platforms[currentPlatformIndex + 1]; if (nextPlat && box.x > nextPlat.x - PLATFORM_WIDTH / 2) { // Passed a platform currentPlatformIndex++; platformsPassed++; scoreText.setText(platformsPassed + ' / ' + WIN_PLATFORMS); // Win condition if (platformsPassed >= WIN_PLATFORMS) { triggerYouWin(); return; } } // --- Remove platforms that are off screen, add new ones --- if (platforms.length > 0 && platforms[0].x < -PLATFORM_WIDTH) { // Remove from game platforms[0].destroy(); platforms.shift(); // Add new platform at the end var lastPlat = platforms[platforms.length - 1]; var plat = new Platform(); var gap = PLATFORM_GAP_MIN + Math.floor(Math.random() * (PLATFORM_GAP_MAX - PLATFORM_GAP_MIN)); plat.x = lastPlat.x + PLATFORM_WIDTH + gap; plat.y = PLATFORM_Y; game.addChild(plat); platforms.push(plat); } // --- Check for falling into gap (no platform under box) --- // If box is below all platforms and not jumping, game over if (!landedPlat && box.vy > 0 && box.y > PLATFORM_Y + 100) { triggerGameOver(); return; } }; // --- Start Game --- resetGame();
===================================================================
--- original.js
+++ change.js
@@ -67,19 +67,19 @@
// Game constants
// Platform and box colors
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
-var PLATFORM_WIDTH = 400;
+var PLATFORM_WIDTH = 520;
var PLATFORM_HEIGHT = 60;
var BOX_SIZE = 120;
-var PLATFORM_GAP_MIN = 220;
-var PLATFORM_GAP_MAX = 400;
+var PLATFORM_GAP_MIN = 120;
+var PLATFORM_GAP_MAX = 220;
var PLATFORM_Y = GAME_HEIGHT * 0.7;
var BOX_START_X = 400;
var BOX_START_Y = PLATFORM_Y - PLATFORM_HEIGHT / 2 - BOX_SIZE / 2;
var SCROLL_SPEED = 10; // px per frame
-var JUMP_VY = -38; // initial jump velocity
-var GRAVITY = 3; // gravity per frame
+var JUMP_VY = -44; // initial jump velocity (higher jump)
+var GRAVITY = 2.2; // gravity per frame (slower fall)
var WIN_PLATFORMS = 10;
// Game state
var platforms = [];
var box;