User prompt
ParmagÌım ekrana devamlı dokunuyorken bile karakterim parmagÌımı takip etsin
User prompt
Karakter dokunma konumumu takip etsin
User prompt
Karakter parmak konumunu sadece x ekseninde takip etsin
Code edit (1 edits merged)
Please save this source code
User prompt
Swipe Runner
Initial prompt
Mobil oyun olmasını istiyorum
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obsAsset = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); // Speed will be set on creation self.speed = 0; self.update = function () { self.y += self.speed; }; return self; }); // Point collectible class var PointCollectible = Container.expand(function () { var self = Container.call(this); var pointAsset = self.attachAsset('point', { anchorX: 0.5, anchorY: 0.5 }); // Speed will be set on creation self.speed = 0; self.update = function () { self.y += self.speed; }; return self; }); // Runner class var Runner = Container.expand(function () { var self = Container.call(this); var runnerAsset = self.attachAsset('runner', { anchorX: 0.5, anchorY: 0.5 }); // For swipe movement self.targetX = self.x; self.targetY = self.y; // For collision flash self.flash = function () { tween(self, { alpha: 0.3 }, { duration: 80, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 120 }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xf0f0f0 }); /**** * Game Code ****/ // Point collectible: a yellow box // Obstacle: a red ellipse // Runner character: a colorful box // Game area dimensions var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; // Runner start position var runnerStartX = GAME_WIDTH / 2; var runnerStartY = GAME_HEIGHT - 400; // Create runner var runner = new Runner(); runner.x = runnerStartX; runner.y = runnerStartY; runner.targetX = runner.x; runner.targetY = runner.y; game.addChild(runner); // Score var score = 0; var scoreTxt = new Text2('0', { size: 120, fill: 0x222222 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Arrays for obstacles and points var obstacles = []; var points = []; // Difficulty progression var baseSpeed = 14; var speedIncrease = 0.012; // per tick var spawnInterval = 60; // ticks between spawns var minSpawnInterval = 24; var tickCount = 0; // Swipe handling var swipeStartX = null; var swipeStartY = null; var isSwiping = false; // Helper: clamp value function clamp(val, min, max) { return Math.max(min, Math.min(max, val)); } // Touch/drag events for swipe game.down = function (x, y, obj) { // Only start swipe if touch is not in top left 100x100 if (x < 100 && y < 100) return; swipeStartX = x; swipeStartY = y; isSwiping = true; }; game.move = function (x, y, obj) { // Always follow finger as long as touch is held (no need to check isSwiping) // Clamp new x and y to stay within game area (leaving 100px margin on all sides) var newX = clamp(x, 100 + runner.width / 2, GAME_WIDTH - runner.width / 2 - 100); var newY = clamp(y, 100 + runner.height / 2, GAME_HEIGHT - runner.height / 2 - 100); // Tween to new position for smoothness tween.stop(runner, { x: true, y: true }); tween(runner, { x: newX, y: newY }, { duration: 120, easing: tween.cubicOut }); // Update swipe start for continuous drag (optional, but harmless) swipeStartX = x; swipeStartY = y; }; game.up = function (x, y, obj) { isSwiping = false; swipeStartX = null; swipeStartY = null; // Optionally, snap runner back to base Y tween(runner, { y: runnerStartY }, { duration: 180, easing: tween.cubicOut }); }; // Main game update loop game.update = function () { tickCount++; // Increase speed over time var currentSpeed = baseSpeed + speedIncrease * tickCount; // Spawn obstacles and points if (tickCount % spawnInterval === 0) { // Randomly decide: obstacle or point (70% obstacle, 30% point) var spawnType = Math.random() < 0.7 ? 'obstacle' : 'point'; var laneCount = 5; var laneWidth = (GAME_WIDTH - 400) / laneCount; var lane = Math.floor(Math.random() * laneCount); var spawnX = 200 + laneWidth / 2 + lane * laneWidth; var spawnY = -120; if (spawnType === 'obstacle') { var obs = new Obstacle(); obs.x = spawnX; obs.y = spawnY; obs.speed = currentSpeed; obstacles.push(obs); game.addChild(obs); } else { var pt = new PointCollectible(); pt.x = spawnX; pt.y = spawnY; pt.speed = currentSpeed; points.push(pt); game.addChild(pt); } // Gradually decrease spawn interval to increase difficulty if (spawnInterval > minSpawnInterval && tickCount % 600 === 0) { spawnInterval -= 4; if (spawnInterval < minSpawnInterval) spawnInterval = minSpawnInterval; } } // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { var obs = obstacles[i]; obs.update(); // Remove if off screen if (obs.y - obs.height / 2 > GAME_HEIGHT + 100) { obs.destroy(); obstacles.splice(i, 1); continue; } // Collision with runner if (obs.intersects(runner)) { // Flash runner runner.flash(); // Flash screen LK.effects.flashScreen(0xff3b30, 600); // Game over LK.showGameOver(); return; } } // Update points for (var j = points.length - 1; j >= 0; j--) { var pt = points[j]; pt.update(); // Remove if off screen if (pt.y - pt.height / 2 > GAME_HEIGHT + 100) { pt.destroy(); points.splice(j, 1); continue; } // Collectible collision if (pt.intersects(runner)) { // Add score score += 1; LK.setScore(score); scoreTxt.setText(score); // Flash runner yellow tween.stop(runner, { tint: true }); tween(runner, { tint: 0xffe156 }, { duration: 80, onFinish: function onFinish() { tween(runner, { tint: 0x2d9cff }, { duration: 120 }); } }); pt.destroy(); points.splice(j, 1); continue; } } }; // Center score text at top, avoid top left 100x100 scoreTxt.x = 1024; scoreTxt.y = 40;
===================================================================
--- original.js
+++ change.js
@@ -121,9 +121,9 @@
swipeStartY = y;
isSwiping = true;
};
game.move = function (x, y, obj) {
- if (!isSwiping) return;
+ // Always follow finger as long as touch is held (no need to check isSwiping)
// Clamp new x and y to stay within game area (leaving 100px margin on all sides)
var newX = clamp(x, 100 + runner.width / 2, GAME_WIDTH - runner.width / 2 - 100);
var newY = clamp(y, 100 + runner.height / 2, GAME_HEIGHT - runner.height / 2 - 100);
// Tween to new position for smoothness
@@ -137,9 +137,9 @@
}, {
duration: 120,
easing: tween.cubicOut
});
- // Update swipe start for continuous drag
+ // Update swipe start for continuous drag (optional, but harmless)
swipeStartX = x;
swipeStartY = y;
};
game.up = function (x, y, obj) {