Code edit (1 edits merged)
Please save this source code
User prompt
Taş Kaçışı
Initial prompt
🪨 3. Taş Kaçışı Amaç: Yukarıdan düşen taşlardan sağa sola kaçarak kurtul. Kontroller: Sadece sağ ve sol yön tuşları Taşlar hızlanarak düşer Hedef: 20 saniye dayanabilirsen kazanırsın. Zorluk: Kolay başlar, zorlaşır
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Player class: controllable character at the bottom var Player = Container.expand(function () { var self = Container.call(this); // Attach player asset (box, blue) var playerAsset = self.attachAsset('playerBox', { anchorX: 0.5, anchorY: 0.5 }); // Set initial size and color playerAsset.width = 180; playerAsset.height = 120; playerAsset.color = 0x2a6cff; // For collision, expose width/height self.getWidth = function () { return playerAsset.width; }; self.getHeight = function () { return playerAsset.height; }; return self; }); // Rock class: falling obstacles var Rock = Container.expand(function () { var self = Container.call(this); // Attach rock asset (ellipse, gray) var rockAsset = self.attachAsset('rockEllipse', { anchorX: 0.5, anchorY: 0.5 }); rockAsset.width = 140; rockAsset.height = 110; rockAsset.color = 0x888888; // Speed will be set on spawn self.speed = 6; // For collision, expose width/height self.getWidth = function () { return rockAsset.width; }; self.getHeight = function () { return rockAsset.height; }; // Update: move down self.update = function () { self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Game area dimensions var GAME_W = 2048; var GAME_H = 2732; // Player setup var player = new Player(); game.addChild(player); player.x = GAME_W / 2; player.y = GAME_H - 180; // Track dragging var dragPlayer = false; // Rocks array var rocks = []; // Timer and time left var GAME_DURATION = 20; // seconds var timeLeft = GAME_DURATION; var timerText = new Text2('20', { size: 120, fill: "#fff" }); timerText.anchor.set(0.5, 0); LK.gui.top.addChild(timerText); // Difficulty progression var spawnInterval = 900; // ms, will decrease var minSpawnInterval = 320; // ms var spawnTimer = null; var lastSpawnTick = 0; var rockSpeed = 6; var maxRockSpeed = 32; // Helper: clamp function clamp(val, min, max) { return Math.max(min, Math.min(max, val)); } // Spawn a new rock at random x function spawnRock() { var rock = new Rock(); // Random x, but keep fully inside screen var margin = 80; var rx = margin + Math.random() * (GAME_W - 2 * margin); rock.x = rx; rock.y = -rock.getHeight() / 2; // Set speed based on current difficulty rock.speed = rockSpeed + Math.random() * 2; rocks.push(rock); game.addChild(rock); } // Difficulty increases over time function updateDifficulty() { // Progress: 0 at start, 1 at end var progress = 1 - timeLeft / GAME_DURATION; // Spawn interval decreases, speed increases spawnInterval = clamp(900 - progress * 600, minSpawnInterval, 900); rockSpeed = clamp(6 + progress * 18, 6, maxRockSpeed); } // Timer countdown var gameTimer = LK.setInterval(function () { timeLeft -= 1; if (timeLeft < 0) timeLeft = 0; timerText.setText(timeLeft.toString()); if (timeLeft === 0) { // Win! LK.showYouWin(); } }, 1000); // Initial spawn spawnRock(); lastSpawnTick = LK.ticks; // Main update loop game.update = function () { // Difficulty progression updateDifficulty(); // Spawn rocks at interval if (LK.ticks - lastSpawnTick >= spawnInterval / 1000 * 60) { spawnRock(); lastSpawnTick = LK.ticks; } // Update rocks, check for collision or out of bounds for (var i = rocks.length - 1; i >= 0; i--) { var rock = rocks[i]; rock.update(); // Out of screen if (rock.y - rock.getHeight() / 2 > GAME_H + 40) { rock.destroy(); rocks.splice(i, 1); continue; } // Collision with player (AABB) var dx = Math.abs(rock.x - player.x); var dy = Math.abs(rock.y - player.y); var overlapX = dx < rock.getWidth() / 2 + player.getWidth() / 2 - 10; var overlapY = dy < rock.getHeight() / 2 + player.getHeight() / 2 - 10; if (overlapX && overlapY) { // Hit! LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } }; // Touch/mouse controls: drag player left/right only game.down = function (x, y, obj) { // Only start drag if touch is near player (vertical margin) if (Math.abs(y - player.y) < 220) { dragPlayer = true; // Move player immediately movePlayer(x); } }; game.move = function (x, y, obj) { if (dragPlayer) { movePlayer(x); } }; game.up = function (x, y, obj) { dragPlayer = false; }; // Move player horizontally, clamp to screen function movePlayer(x) { var halfW = player.getWidth() / 2; var minX = halfW + 40; var maxX = GAME_W - halfW - 40; player.x = clamp(x, minX, maxX); } // Center timer text at top, avoid top left 100x100 timerText.x = LK.gui.top.width / 2; timerText.y = 20; // Asset initialization (shapes)
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,192 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Player class: controllable character at the bottom
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ // Attach player asset (box, blue)
+ var playerAsset = self.attachAsset('playerBox', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Set initial size and color
+ playerAsset.width = 180;
+ playerAsset.height = 120;
+ playerAsset.color = 0x2a6cff;
+ // For collision, expose width/height
+ self.getWidth = function () {
+ return playerAsset.width;
+ };
+ self.getHeight = function () {
+ return playerAsset.height;
+ };
+ return self;
+});
+// Rock class: falling obstacles
+var Rock = Container.expand(function () {
+ var self = Container.call(this);
+ // Attach rock asset (ellipse, gray)
+ var rockAsset = self.attachAsset('rockEllipse', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ rockAsset.width = 140;
+ rockAsset.height = 110;
+ rockAsset.color = 0x888888;
+ // Speed will be set on spawn
+ self.speed = 6;
+ // For collision, expose width/height
+ self.getWidth = function () {
+ return rockAsset.width;
+ };
+ self.getHeight = function () {
+ return rockAsset.height;
+ };
+ // Update: move down
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x222222
+});
+
+/****
+* Game Code
+****/
+// Game area dimensions
+var GAME_W = 2048;
+var GAME_H = 2732;
+// Player setup
+var player = new Player();
+game.addChild(player);
+player.x = GAME_W / 2;
+player.y = GAME_H - 180;
+// Track dragging
+var dragPlayer = false;
+// Rocks array
+var rocks = [];
+// Timer and time left
+var GAME_DURATION = 20; // seconds
+var timeLeft = GAME_DURATION;
+var timerText = new Text2('20', {
+ size: 120,
+ fill: "#fff"
+});
+timerText.anchor.set(0.5, 0);
+LK.gui.top.addChild(timerText);
+// Difficulty progression
+var spawnInterval = 900; // ms, will decrease
+var minSpawnInterval = 320; // ms
+var spawnTimer = null;
+var lastSpawnTick = 0;
+var rockSpeed = 6;
+var maxRockSpeed = 32;
+// Helper: clamp
+function clamp(val, min, max) {
+ return Math.max(min, Math.min(max, val));
+}
+// Spawn a new rock at random x
+function spawnRock() {
+ var rock = new Rock();
+ // Random x, but keep fully inside screen
+ var margin = 80;
+ var rx = margin + Math.random() * (GAME_W - 2 * margin);
+ rock.x = rx;
+ rock.y = -rock.getHeight() / 2;
+ // Set speed based on current difficulty
+ rock.speed = rockSpeed + Math.random() * 2;
+ rocks.push(rock);
+ game.addChild(rock);
+}
+// Difficulty increases over time
+function updateDifficulty() {
+ // Progress: 0 at start, 1 at end
+ var progress = 1 - timeLeft / GAME_DURATION;
+ // Spawn interval decreases, speed increases
+ spawnInterval = clamp(900 - progress * 600, minSpawnInterval, 900);
+ rockSpeed = clamp(6 + progress * 18, 6, maxRockSpeed);
+}
+// Timer countdown
+var gameTimer = LK.setInterval(function () {
+ timeLeft -= 1;
+ if (timeLeft < 0) timeLeft = 0;
+ timerText.setText(timeLeft.toString());
+ if (timeLeft === 0) {
+ // Win!
+ LK.showYouWin();
+ }
+}, 1000);
+// Initial spawn
+spawnRock();
+lastSpawnTick = LK.ticks;
+// Main update loop
+game.update = function () {
+ // Difficulty progression
+ updateDifficulty();
+ // Spawn rocks at interval
+ if (LK.ticks - lastSpawnTick >= spawnInterval / 1000 * 60) {
+ spawnRock();
+ lastSpawnTick = LK.ticks;
+ }
+ // Update rocks, check for collision or out of bounds
+ for (var i = rocks.length - 1; i >= 0; i--) {
+ var rock = rocks[i];
+ rock.update();
+ // Out of screen
+ if (rock.y - rock.getHeight() / 2 > GAME_H + 40) {
+ rock.destroy();
+ rocks.splice(i, 1);
+ continue;
+ }
+ // Collision with player (AABB)
+ var dx = Math.abs(rock.x - player.x);
+ var dy = Math.abs(rock.y - player.y);
+ var overlapX = dx < rock.getWidth() / 2 + player.getWidth() / 2 - 10;
+ var overlapY = dy < rock.getHeight() / 2 + player.getHeight() / 2 - 10;
+ if (overlapX && overlapY) {
+ // Hit!
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ return;
+ }
+ }
+};
+// Touch/mouse controls: drag player left/right only
+game.down = function (x, y, obj) {
+ // Only start drag if touch is near player (vertical margin)
+ if (Math.abs(y - player.y) < 220) {
+ dragPlayer = true;
+ // Move player immediately
+ movePlayer(x);
+ }
+};
+game.move = function (x, y, obj) {
+ if (dragPlayer) {
+ movePlayer(x);
+ }
+};
+game.up = function (x, y, obj) {
+ dragPlayer = false;
+};
+// Move player horizontally, clamp to screen
+function movePlayer(x) {
+ var halfW = player.getWidth() / 2;
+ var minX = halfW + 40;
+ var maxX = GAME_W - halfW - 40;
+ player.x = clamp(x, minX, maxX);
+}
+// Center timer text at top, avoid top left 100x100
+timerText.x = LK.gui.top.width / 2;
+timerText.y = 20;
+// Asset initialization (shapes)
\ No newline at end of file