User prompt
move player down near the road line
User prompt
move the obstacle position down near the road line
User prompt
change positions of obstacles and players exactly like firefit asset
User prompt
move the position of obstacle little down
User prompt
add background theme for the game
User prompt
make player hits new obstacles also leads game over
Code edit (1 edits merged)
Please save this source code
User prompt
make player hit the barrier also leads game over and add two more obstsacle
Code edit (2 edits merged)
Please save this source code
User prompt
Increase player's jump height by adjusting jumpSpeed
User prompt
dont show jumping values text in the screen
User prompt
jump the player some more height
User prompt
i need the player jump some height while i swipe up so that player jumps over the obstacles
User prompt
remove all the jump mechanics from player
User prompt
remove jump mechanics
User prompt
Ensured precise return to original position after jumping
User prompt
Simplified the jump animation with fixed height (300px) Used proper easing functions (easeOutQuad/easeInQuad) Ensured precise return to original position
User prompt
activate jump mechanics
User prompt
remove duck functionality
Code edit (1 edits merged)
Please save this source code
User prompt
Ensure player jumps triple the height of the player when swiping up anywhere in the screen
User prompt
make it work Ensure player jumps triple the height of the player when swiping up
User prompt
ensure player jump upside triple of height of the player when swipe the screen
User prompt
player mechanics not working
User prompt
remove old player mmechanic and add this Swipe up to jump,\ndown to dive
/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Obstacle = Container.expand(function (type) { var self = Container.call(this); var obstacleGraphics; self.type = type || 'step'; self.speed = 0; if (self.type === 'step') { obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 1.0 }); } else if (self.type === 'barrier') { obstacleGraphics = self.attachAsset('barrier', { anchorX: 0.5, anchorY: 1.0 }); } else if (self.type === 'firePit') { obstacleGraphics = self.attachAsset('firePit', { anchorX: 0.5, anchorY: 0.5 }); } else if (self.type === 'car') { obstacleGraphics = self.attachAsset('car', { anchorX: 0.5, anchorY: 1.0 }); } self.update = function () { self.x -= self.speed; }; self.getCollisionBounds = function () { return { x: self.x - obstacleGraphics.width / 2, y: self.y - obstacleGraphics.height, width: obstacleGraphics.width, height: obstacleGraphics.height }; }; self.isLowObstacle = function () { return self.type === 'step' || self.type === 'firePit'; }; self.isHighObstacle = function () { return self.type === 'barrier'; }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 1.0 }); self.isJumping = false; self.isDucking = false; self.defaultHeight = playerGraphics.height; self.defaultY = 0; self.originalHeight = playerGraphics.height; self.jump = function () { if (!self.isJumping && !self.isDucking) { self.isJumping = true; LK.getSound('jump').play(); var startY = self.y; var jumpHeight = 300; // Fixed jump height // Jump up tween(self, { y: startY - jumpHeight }, { duration: 400, easing: tween.easeOutQuad, onFinish: function onFinish() { // Fall down tween(self, { y: startY }, { duration: 400, easing: tween.easeInQuad, onFinish: function onFinish() { self.isJumping = false; self.y = startY; } }); } }); } }; self.duck = function () { if (!self.isJumping && !self.isDucking) { self.isDucking = true; var duckHeight = self.originalHeight * 0.6; // Adjust graphics playerGraphics.height = duckHeight; playerGraphics.y += self.originalHeight - duckHeight; // Auto stand up after duration LK.setTimeout(function () { if (self.isDucking) { playerGraphics.height = self.originalHeight; playerGraphics.y -= self.originalHeight - duckHeight; self.isDucking = false; } }, 800); } }; self.standUp = function () { if (self.isDucking) { playerGraphics.height = self.originalHeight; self.isDucking = false; } }; self.getCollisionBounds = function () { return { x: self.x - playerGraphics.width / 2, y: self.y - playerGraphics.height, width: playerGraphics.width, height: playerGraphics.height }; }; self.update = function () { // Player movement logic (if any) }; return self; }); var RoadLine = Container.expand(function () { var self = Container.call(this); var lineGraphics = self.attachAsset('roadLine', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 0; self.update = function () { self.x -= self.speed; if (self.x < -lineGraphics.width) { self.x = 2048 + lineGraphics.width; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var player; var obstacles = []; var roadLines = []; var gameSpeed = 10; var spawnTimer = 0; var minSpawnTime = 60; var maxSpawnTime = 120; var nextSpawnTime = 100; var distance = 0; var isGameOver = false; var shouldSpawnObstacle = true; // Create road var road = game.addChild(LK.getAsset('road', { anchorX: 0.5, anchorY: 0 })); road.x = 2048 / 2; road.y = 2732 - 600; // Create player player = game.addChild(new Player()); player.x = 300; player.y = 2732 - 600; player.defaultY = player.y; // Create road lines for (var i = 0; i < 20; i++) { var roadLine = new RoadLine(); roadLine.x = i * 200; roadLine.y = 2732 - 600 + 300; roadLine.speed = gameSpeed; roadLines.push(roadLine); game.addChild(roadLine); } // Score display var scoreTxt = new Text2('0m', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Improved Input Handling function handleDown(x, y, obj) { console.log("Input detected:", obj); // Debug input // First try swipe detection if (obj.event && obj.event.type === 'swipe') { if (obj.event.direction === 'up') { console.log("Jump via swipe"); player.jump(); } else if (obj.event.direction === 'down') { console.log("Duck via swipe"); player.duck(); } } // Fallback to touch position else if (y < game.height / 2) { console.log("Jump via touch position"); player.jump(); } else { console.log("Duck via touch position"); player.duck(); } } function handleUp(x, y, obj) { if (player.isDucking) { player.standUp(); } } // Add keyboard controls for testing game.keyDown = function (key) { if (key === 'ArrowUp' || key === 'w') { console.log("Jump via keyboard"); player.jump(); } if (key === 'ArrowDown' || key === 's') { console.log("Duck via keyboard"); player.duck(); } }; game.down = handleDown; game.up = handleUp; // Collision detection function checkCollision(playerBounds, obstacleBounds) { return !(playerBounds.x + playerBounds.width < obstacleBounds.x || playerBounds.x > obstacleBounds.x + obstacleBounds.width || playerBounds.y + playerBounds.height < obstacleBounds.y || playerBounds.y > obstacleBounds.y + obstacleBounds.height); } // Spawn obstacles function spawnObstacle() { if (!shouldSpawnObstacle) { return; } var types = ['step', 'barrier', 'firePit', 'car']; var type = types[Math.floor(Math.random() * types.length)]; var obstacle = new Obstacle(type); obstacle.x = 2048 + 100; obstacle.y = 2732 - 600; obstacle.speed = gameSpeed; if (type === 'firePit') { obstacle.y += 50; } if (type === 'car') { obstacle.x += Math.random() * 500; } obstacles.push(obstacle); game.addChild(obstacle); nextSpawnTime = minSpawnTime + Math.floor(Math.random() * (maxSpawnTime - minSpawnTime)); spawnTimer = 0; } // Game over handling function gameOver() { if (!isGameOver) { isGameOver = true; shouldSpawnObstacle = false; LK.getSound('crash').play(); var highScore = storage.highScore || 0; if (distance > highScore) { storage.highScore = distance; } LK.effects.flashScreen(0xff0000, 500); LK.setTimeout(function () { LK.showGameOver(); }, 1000); } } // Main game loop game.update = function () { if (isGameOver) { return; } // Update score distance += 1; scoreTxt.setText(Math.floor(distance / 10) + "m"); // Increase difficulty if (distance % 500 === 0 && gameSpeed < 25) { gameSpeed += 0.5; roadLines.forEach(function (line) { return line.speed = gameSpeed; }); obstacles.forEach(function (obs) { return obs.speed = gameSpeed; }); if (minSpawnTime > 30) { minSpawnTime -= 2; } if (maxSpawnTime > 60) { maxSpawnTime -= 5; } } // Update road lines roadLines.forEach(function (line) { return line.update(); }); // Spawn obstacles spawnTimer++; if (spawnTimer >= nextSpawnTime) { spawnObstacle(); } // Update player player.update(); // Check collisions for (var j = obstacles.length - 1; j >= 0; j--) { var obstacle = obstacles[j]; obstacle.update(); if (obstacle.x < -200) { obstacle.destroy(); obstacles.splice(j, 1); continue; } var playerBounds = player.getCollisionBounds(); var obstacleBounds = obstacle.getCollisionBounds(); var collisionDetected = false; if (!player.isJumping && obstacle.isLowObstacle()) { collisionDetected = checkCollision(playerBounds, obstacleBounds); } else if (!player.isDucking && obstacle.isHighObstacle()) { collisionDetected = checkCollision(playerBounds, obstacleBounds); } else if (obstacle.type === 'car') { collisionDetected = checkCollision(playerBounds, obstacleBounds); } if (collisionDetected) { gameOver(); break; } } }; // Start music LK.playMusic('bgmusic', { fade: { start: 0, end: 0.5, duration: 1000 } });
===================================================================
--- original.js
+++ change.js
@@ -60,28 +60,31 @@
self.isJumping = false;
self.isDucking = false;
self.defaultHeight = playerGraphics.height;
self.defaultY = 0;
+ self.originalHeight = playerGraphics.height;
self.jump = function () {
if (!self.isJumping && !self.isDucking) {
self.isJumping = true;
LK.getSound('jump').play();
- // Jump animation
+ var startY = self.y;
+ var jumpHeight = 300; // Fixed jump height
+ // Jump up
tween(self, {
- y: self.defaultY - self.defaultHeight * 3
+ y: startY - jumpHeight
}, {
- duration: 500,
- easing: tween.easeOut,
+ duration: 400,
+ easing: tween.easeOutQuad,
onFinish: function onFinish() {
- // Fall down animation
+ // Fall down
tween(self, {
- y: self.defaultY
+ y: startY
}, {
- duration: 500,
- easing: tween.easeIn,
+ duration: 400,
+ easing: tween.easeInQuad,
onFinish: function onFinish() {
self.isJumping = false;
- self.y = self.defaultY; // Ensure player returns to default position
+ self.y = startY;
}
});
}
});
@@ -89,22 +92,25 @@
};
self.duck = function () {
if (!self.isJumping && !self.isDucking) {
self.isDucking = true;
- playerGraphics.height = self.defaultHeight / 2;
- // Auto stand up after 1 second
+ var duckHeight = self.originalHeight * 0.6;
+ // Adjust graphics
+ playerGraphics.height = duckHeight;
+ playerGraphics.y += self.originalHeight - duckHeight;
+ // Auto stand up after duration
LK.setTimeout(function () {
if (self.isDucking) {
- playerGraphics.height = self.defaultHeight;
+ playerGraphics.height = self.originalHeight;
+ playerGraphics.y -= self.originalHeight - duckHeight;
self.isDucking = false;
- self.standUp(); // Ensure player stands up after ducking
}
- }, 1000);
+ }, 800);
}
};
self.standUp = function () {
if (self.isDucking) {
- playerGraphics.height = self.defaultHeight;
+ playerGraphics.height = self.originalHeight;
self.isDucking = false;
}
};
self.getCollisionBounds = function () {
@@ -115,9 +121,9 @@
height: playerGraphics.height
};
};
self.update = function () {
- // Move player to the right automatically
+ // Player movement logic (if any)
};
return self;
});
var RoadLine = Container.expand(function () {
@@ -127,11 +133,9 @@
anchorY: 0.5
});
self.speed = 0;
self.update = function () {
- self.x += gameSpeed; // Move player to the right automatically
self.x -= self.speed;
- // Reset position when off screen
if (self.x < -lineGraphics.width) {
self.x = 2048 + lineGraphics.width;
}
};
@@ -141,15 +145,14 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Black
+ backgroundColor: 0x000000
});
/****
* Game Code
****/
-// Game variables
var player;
var obstacles = [];
var roadLines = [];
var gameSpeed = 10;
@@ -187,32 +190,53 @@
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
-// Initialize player input
+// Improved Input Handling
function handleDown(x, y, obj) {
- // Jump if swiping up
- if (obj.event && obj.event.type === 'swipe' && obj.event.direction === 'up') {
+ console.log("Input detected:", obj); // Debug input
+ // First try swipe detection
+ if (obj.event && obj.event.type === 'swipe') {
+ if (obj.event.direction === 'up') {
+ console.log("Jump via swipe");
+ player.jump();
+ } else if (obj.event.direction === 'down') {
+ console.log("Duck via swipe");
+ player.duck();
+ }
+ }
+ // Fallback to touch position
+ else if (y < game.height / 2) {
+ console.log("Jump via touch position");
player.jump();
- } else if (obj.event && obj.event.type === 'swipe' && obj.event.direction === 'down') {
- // Duck if swiping down
+ } else {
+ console.log("Duck via touch position");
player.duck();
}
}
function handleUp(x, y, obj) {
- // Stand up when releasing swipe down
if (player.isDucking) {
player.standUp();
}
}
-// Set up input handlers
+// Add keyboard controls for testing
+game.keyDown = function (key) {
+ if (key === 'ArrowUp' || key === 'w') {
+ console.log("Jump via keyboard");
+ player.jump();
+ }
+ if (key === 'ArrowDown' || key === 's') {
+ console.log("Duck via keyboard");
+ player.duck();
+ }
+};
game.down = handleDown;
game.up = handleUp;
-// Check collision between player and obstacle
+// Collision detection
function checkCollision(playerBounds, obstacleBounds) {
return !(playerBounds.x + playerBounds.width < obstacleBounds.x || playerBounds.x > obstacleBounds.x + obstacleBounds.width || playerBounds.y + playerBounds.height < obstacleBounds.y || playerBounds.y > obstacleBounds.y + obstacleBounds.height);
}
-// Spawn a new obstacle
+// Spawn obstacles
function spawnObstacle() {
if (!shouldSpawnObstacle) {
return;
}
@@ -220,109 +244,97 @@
var type = types[Math.floor(Math.random() * types.length)];
var obstacle = new Obstacle(type);
obstacle.x = 2048 + 100;
obstacle.y = 2732 - 600;
- // Adjust Y position based on obstacle type
+ obstacle.speed = gameSpeed;
if (type === 'firePit') {
obstacle.y += 50;
- } else if (type === 'car') {
- obstacle.x += Math.random() * 500; // Add some random extra distance for cars
}
- obstacle.speed = gameSpeed;
+ if (type === 'car') {
+ obstacle.x += Math.random() * 500;
+ }
obstacles.push(obstacle);
game.addChild(obstacle);
- // Set next spawn time
nextSpawnTime = minSpawnTime + Math.floor(Math.random() * (maxSpawnTime - minSpawnTime));
spawnTimer = 0;
}
-// Handle game over
+// Game over handling
function gameOver() {
if (!isGameOver) {
isGameOver = true;
shouldSpawnObstacle = false;
LK.getSound('crash').play();
- // Save high score
var highScore = storage.highScore || 0;
if (distance > highScore) {
storage.highScore = distance;
}
- // Show game over screen
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
}
-// Update function called each frame
+// Main game loop
game.update = function () {
if (isGameOver) {
return;
}
- // Increase distance score
+ // Update score
distance += 1;
scoreTxt.setText(Math.floor(distance / 10) + "m");
- // Gradually increase game speed
+ // Increase difficulty
if (distance % 500 === 0 && gameSpeed < 25) {
gameSpeed += 0.5;
- // Update road line speed
- for (var i = 0; i < roadLines.length; i++) {
- roadLines[i].speed = gameSpeed;
- }
- // Update obstacle speed
- for (var j = 0; j < obstacles.length; j++) {
- obstacles[j].speed = gameSpeed;
- }
- // Decrease spawn time as game progresses
+ roadLines.forEach(function (line) {
+ return line.speed = gameSpeed;
+ });
+ obstacles.forEach(function (obs) {
+ return obs.speed = gameSpeed;
+ });
if (minSpawnTime > 30) {
minSpawnTime -= 2;
}
if (maxSpawnTime > 60) {
maxSpawnTime -= 5;
}
}
// Update road lines
- for (var i = 0; i < roadLines.length; i++) {
- roadLines[i].update();
- }
+ roadLines.forEach(function (line) {
+ return line.update();
+ });
// Spawn obstacles
spawnTimer++;
if (spawnTimer >= nextSpawnTime) {
spawnObstacle();
}
- // Update player position
+ // Update player
player.update();
- // Update and check collisions with obstacles
+ // Check collisions
for (var j = obstacles.length - 1; j >= 0; j--) {
var obstacle = obstacles[j];
obstacle.update();
- // Remove obstacles that are off screen
if (obstacle.x < -200) {
obstacle.destroy();
obstacles.splice(j, 1);
continue;
}
- // Check collision
var playerBounds = player.getCollisionBounds();
var obstacleBounds = obstacle.getCollisionBounds();
- // Only check collision if:
- // - Player is not jumping AND obstacle is low (step/fire pit)
- // - Player is not ducking AND obstacle is high (barrier)
var collisionDetected = false;
if (!player.isJumping && obstacle.isLowObstacle()) {
collisionDetected = checkCollision(playerBounds, obstacleBounds);
} else if (!player.isDucking && obstacle.isHighObstacle()) {
collisionDetected = checkCollision(playerBounds, obstacleBounds);
} else if (obstacle.type === 'car') {
- // Cars always need to be jumped over
collisionDetected = checkCollision(playerBounds, obstacleBounds);
}
if (collisionDetected) {
gameOver();
break;
}
}
};
-// Start background music
+// Start music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 0.5,