User prompt
make different car types not only one, make the rate of cars passing per second increased
User prompt
No now I automatically win the game, I just want to have a place to arrive so that I can win the game
User prompt
But make the road two sided so when I sucessfully go to other side I should win
User prompt
Make me a game like a character lets say try to go accross a street but cars going through the road so penguin should go to other side without hitting the cars otherwise elemniates
Code edit (1 edits merged)
Please save this source code
User prompt
Jungle Dash Runner
Initial prompt
Hello, I want a game that like subway surfers or temple runner
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Coin class var Coin = Container.expand(function () { var self = Container.call(this); self.lane = 1; self.collected = false; self.attachAsset('coin', { anchorX: 0.5, anchorY: 1 }); self.getCollisionRect = function () { return new Rectangle(self.x - 35, self.y - 80, 70, 70); }; self.update = function () { self.y += game.speed; }; return self; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); self.type = 'log'; // log, rock, pit self.lane = 1; self.passed = false; self.setType = function (type) { self.type = type; self.removeChildren(); if (type === 'log') { self.attachAsset('log', { anchorX: 0.5, anchorY: 1 }); self.width = 200; self.height = 80; } else if (type === 'rock') { self.attachAsset('rock', { anchorX: 0.5, anchorY: 1 }); self.width = 120; self.height = 120; } else if (type === 'pit') { self.attachAsset('pit', { anchorX: 0.5, anchorY: 1 }); self.width = 220; self.height = 40; } }; self.getCollisionRect = function () { if (self.type === 'log') { return new Rectangle(self.x - 90, self.y - 80, 180, 60); } else if (self.type === 'rock') { return new Rectangle(self.x - 60, self.y - 120, 120, 100); } else if (self.type === 'pit') { return new Rectangle(self.x - 110, self.y - 40, 220, 30); } return new Rectangle(self.x - 50, self.y - 50, 100, 100); }; self.update = function () { self.y += game.speed; }; return self; }); // Runner class (Penguin for crossing game) var Runner = Container.expand(function () { var self = Container.call(this); var runnerSprite = self.attachAsset('runner', { anchorX: 0.5, anchorY: 1 }); self.width = runnerSprite.width; self.height = runnerSprite.height; // For collision box self.getCollisionRect = function () { var w = self.width * 0.7; var h = self.height * 0.9; return new Rectangle(self.x - w / 2, self.y - h, w, h); }; self.update = function () { // No-op for penguin (no auto movement) }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a3c1a }); /**** * Game Code ****/ // Sound effects // Jungle ground // Power-up (not yet used, but for future) // Coin // Lane obstacles // Character (runner) // Penguin crossing game setup // Define lanes for cars (3 lanes, horizontal) game.laneY = [2732 - 600, // bottom lane (closest to player) 2732 - 900, // middle lane 2732 - 1200 // top lane (furthest from player) ]; // X positions for cars (off-screen left/right) game.carStartLeft = -200; game.carStartRight = 2048 + 200; // Penguin start position (bottom center) game.penguinStartX = 2048 / 2; game.penguinStartY = 2732 - 200; // Game state game.ticks = 0; game.score = 0; game.isGameOver = false; // Arrays for cars var cars = []; // Add ground (road background) var ground = LK.getAsset('ground', { anchorX: 0.5, anchorY: 1, x: 2048 / 2, y: 2732 }); game.addChild(ground); // Add penguin (player) var penguin = new Runner(); penguin.x = game.penguinStartX; penguin.y = game.penguinStartY; penguin.lane = 1; // start in center game.addChild(penguin); // Score text var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Helper: spawn car function spawnCar() { var obs = new Obstacle(); // Always use 'log' as car for now (could use different shapes/colors for variety) obs.setType('log'); // Random lane (0, 1, 2) obs.lane = Math.floor(Math.random() * 3); // Random direction: left-to-right or right-to-left obs.dir = Math.random() < 0.5 ? 1 : -1; // Set X and Y obs.y = game.laneY[obs.lane]; if (obs.dir === 1) { obs.x = game.carStartLeft; obs.speed = 16 + Math.random() * 8; } else { obs.x = game.carStartRight; obs.speed = -(16 + Math.random() * 8); } obs.width = 260; obs.height = 100; game.addChild(obs); cars.push(obs); } // Touch/Swipe handling for penguin movement (up/down/left/right) var touchStartX = 0, touchStartY = 0, touchStartTime = 0; var swipeThreshold = 80; // px var swipeTime = 400; // ms game.down = function (x, y, obj) { touchStartX = x; touchStartY = y; touchStartTime = Date.now(); }; game.up = function (x, y, obj) { var dx = x - touchStartX; var dy = y - touchStartY; var dt = Date.now() - touchStartTime; if (dt > swipeTime) return; // Too slow if (Math.abs(dx) > Math.abs(dy)) { // Horizontal swipe if (dx > swipeThreshold) { // Move right if (penguin.x < 2048 - 200) penguin.x += 320; } else if (dx < -swipeThreshold) { // Move left if (penguin.x > 200) penguin.x -= 320; } } else { // Vertical swipe if (dy < -swipeThreshold) { // Move up if (penguin.y > 400) penguin.y -= 300; } else if (dy > swipeThreshold) { // Move down if (penguin.y < 2732 - 200) penguin.y += 300; } } }; // Main update loop game.update = function () { if (game.isGameOver) return; game.ticks++; // Spawn cars at intervals if (game.ticks % 36 === 0) { spawnCar(); } // Update cars for (var i = cars.length - 1; i >= 0; i--) { var car = cars[i]; car.x += car.speed; // Remove if off screen if (car.speed > 0 && car.x > 2048 + 300 || car.speed < 0 && car.x < -300) { car.destroy(); cars.splice(i, 1); continue; } // Collision with penguin var pRect = penguin.getCollisionRect(); var cRect = car.getCollisionRect(); if (rectsIntersect(pRect, cRect)) { LK.getSound('hitSound').play(); LK.effects.flashScreen(0xff0000, 800); game.isGameOver = true; LK.showGameOver(); return; } } // Check if penguin reached the top (success) if (penguin.y <= 400) { game.score++; scoreTxt.setText(game.score); // Reset penguin to start penguin.x = game.penguinStartX; penguin.y = game.penguinStartY; // Optionally: increase car speed or spawn rate for difficulty } }; // Rectangle intersection helper function rectsIntersect(r1, r2) { return !(r2.x > r1.x + r1.width || r2.x + r2.width < r1.x || r2.y > r1.y + r1.height || r2.y + r2.height < r1.y); } // Reset on game restart game.on('reset', function () { // Remove all cars for (var i = 0; i < cars.length; i++) cars[i].destroy(); cars = []; game.ticks = 0; game.score = 0; game.isGameOver = false; scoreTxt.setText('0'); penguin.x = game.penguinStartX; penguin.y = game.penguinStartY; });
===================================================================
--- original.js
+++ change.js
@@ -69,85 +69,25 @@
self.y += game.speed;
};
return self;
});
-// Runner class
+// Runner class (Penguin for crossing game)
var Runner = Container.expand(function () {
var self = Container.call(this);
var runnerSprite = self.attachAsset('runner', {
anchorX: 0.5,
anchorY: 1
});
self.width = runnerSprite.width;
self.height = runnerSprite.height;
- self.lane = 1; // 0: left, 1: center, 2: right
- self.isJumping = false;
- self.isSliding = false;
- self.jumpY = 0; // Offset for jump animation
- self.slideTimer = 0;
// For collision box
self.getCollisionRect = function () {
var w = self.width * 0.7;
- var h = self.isSliding ? self.height * 0.5 : self.height * 0.9;
+ var h = self.height * 0.9;
return new Rectangle(self.x - w / 2, self.y - h, w, h);
};
- // Animate jump
- self.jump = function () {
- if (self.isJumping || self.isSliding) return;
- self.isJumping = true;
- tween(self, {
- jumpY: -320
- }, {
- duration: 320,
- easing: tween.cubicOut,
- onFinish: function onFinish() {
- tween(self, {
- jumpY: 0
- }, {
- duration: 320,
- easing: tween.cubicIn,
- onFinish: function onFinish() {
- self.isJumping = false;
- }
- });
- }
- });
- };
- // Animate slide
- self.slide = function () {
- if (self.isSliding || self.isJumping) return;
- self.isSliding = true;
- self.slideTimer = 22; // ~0.36s at 60fps
- };
- // Lane change
- self.moveLane = function (dir) {
- var newLane = self.lane + dir;
- if (newLane < 0) newLane = 0;
- if (newLane > 2) newLane = 2;
- if (newLane !== self.lane) {
- self.lane = newLane;
- LK.getSound('swipeSound').play();
- }
- };
self.update = function () {
- // Lane X positions: 3 lanes, centered
- var laneX = [game.laneLeftX, game.laneCenterX, game.laneRightX];
- // Smoothly move to lane
- var targetX = laneX[self.lane];
- if (Math.abs(self.x - targetX) > 2) {
- self.x += (targetX - self.x) * 0.3;
- } else {
- self.x = targetX;
- }
- // Jump Y offset
- runnerSprite.y = self.jumpY;
- // Slide
- if (self.isSliding) {
- self.slideTimer--;
- if (self.slideTimer <= 0) {
- self.isSliding = false;
- }
- }
+ // No-op for penguin (no auto movement)
};
return self;
});
@@ -166,83 +106,73 @@
// Power-up (not yet used, but for future)
// Coin
// Lane obstacles
// Character (runner)
-// Lane X positions (3 lanes)
-game.laneLeftX = 2048 / 2 - 320;
-game.laneCenterX = 2048 / 2;
-game.laneRightX = 2048 / 2 + 320;
-// Ground Y position (bottom of runner's feet)
-game.groundY = 2732 - 420;
-// Game speed (pixels per frame)
-game.speed = 18;
+// Penguin crossing game setup
+// Define lanes for cars (3 lanes, horizontal)
+game.laneY = [2732 - 600,
+// bottom lane (closest to player)
+2732 - 900,
+// middle lane
+2732 - 1200 // top lane (furthest from player)
+];
+// X positions for cars (off-screen left/right)
+game.carStartLeft = -200;
+game.carStartRight = 2048 + 200;
+// Penguin start position (bottom center)
+game.penguinStartX = 2048 / 2;
+game.penguinStartY = 2732 - 200;
+// Game state
game.ticks = 0;
-game.spawnTimer = 0;
-game.coinSpawnTimer = 0;
game.score = 0;
-game.coins = 0;
game.isGameOver = false;
-// Arrays for obstacles and coins
-var obstacles = [];
-var coinsArr = [];
-// Add ground
+// Arrays for cars
+var cars = [];
+// Add ground (road background)
var ground = LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 1,
x: 2048 / 2,
- y: game.groundY + 150
+ y: 2732
});
game.addChild(ground);
-// Add runner
-var runner = new Runner();
-runner.x = game.laneCenterX;
-runner.y = game.groundY;
-game.addChild(runner);
+// Add penguin (player)
+var penguin = new Runner();
+penguin.x = game.penguinStartX;
+penguin.y = game.penguinStartY;
+penguin.lane = 1; // start in center
+game.addChild(penguin);
// Score text
var scoreTxt = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
-// Coin text
-var coinTxt = new Text2('0', {
- size: 80,
- fill: 0xFFD700
-});
-coinTxt.anchor.set(0, 0);
-LK.gui.topRight.addChild(coinTxt);
-// Helper: spawn obstacle
-function spawnObstacle() {
+// Helper: spawn car
+function spawnCar() {
var obs = new Obstacle();
- // Random type
- var r = Math.random();
- if (r < 0.5) {
- obs.setType('log');
- } else if (r < 0.8) {
- obs.setType('rock');
+ // Always use 'log' as car for now (could use different shapes/colors for variety)
+ obs.setType('log');
+ // Random lane (0, 1, 2)
+ obs.lane = Math.floor(Math.random() * 3);
+ // Random direction: left-to-right or right-to-left
+ obs.dir = Math.random() < 0.5 ? 1 : -1;
+ // Set X and Y
+ obs.y = game.laneY[obs.lane];
+ if (obs.dir === 1) {
+ obs.x = game.carStartLeft;
+ obs.speed = 16 + Math.random() * 8;
} else {
- obs.setType('pit');
+ obs.x = game.carStartRight;
+ obs.speed = -(16 + Math.random() * 8);
}
- // Random lane
- obs.lane = Math.floor(Math.random() * 3);
- var laneX = [game.laneLeftX, game.laneCenterX, game.laneRightX];
- obs.x = laneX[obs.lane];
- obs.y = -100;
+ obs.width = 260;
+ obs.height = 100;
game.addChild(obs);
- obstacles.push(obs);
+ cars.push(obs);
}
-// Helper: spawn coin
-function spawnCoin() {
- var coin = new Coin();
- coin.lane = Math.floor(Math.random() * 3);
- var laneX = [game.laneLeftX, game.laneCenterX, game.laneRightX];
- coin.x = laneX[coin.lane];
- coin.y = -80;
- game.addChild(coin);
- coinsArr.push(coin);
-}
-// Touch/Swipe handling
+// Touch/Swipe handling for penguin movement (up/down/left/right)
var touchStartX = 0,
touchStartY = 0,
touchStartTime = 0;
var swipeThreshold = 80; // px
@@ -259,138 +189,76 @@
if (dt > swipeTime) return; // Too slow
if (Math.abs(dx) > Math.abs(dy)) {
// Horizontal swipe
if (dx > swipeThreshold) {
- runner.moveLane(1); // right
+ // Move right
+ if (penguin.x < 2048 - 200) penguin.x += 320;
} else if (dx < -swipeThreshold) {
- runner.moveLane(-1); // left
+ // Move left
+ if (penguin.x > 200) penguin.x -= 320;
}
} else {
// Vertical swipe
if (dy < -swipeThreshold) {
- runner.jump();
+ // Move up
+ if (penguin.y > 400) penguin.y -= 300;
} else if (dy > swipeThreshold) {
- runner.slide();
+ // Move down
+ if (penguin.y < 2732 - 200) penguin.y += 300;
}
}
};
-// No drag/move needed for runner
// Main update loop
game.update = function () {
if (game.isGameOver) return;
game.ticks++;
- // Increase speed over time
- if (game.ticks % 180 === 0 && game.speed < 38) {
- game.speed += 1.2;
+ // Spawn cars at intervals
+ if (game.ticks % 36 === 0) {
+ spawnCar();
}
- // Spawn obstacles
- game.spawnTimer--;
- if (game.spawnTimer <= 0) {
- spawnObstacle();
- game.spawnTimer = 54 + Math.floor(Math.random() * 32); // ~1s
- }
- // Spawn coins
- game.coinSpawnTimer--;
- if (game.coinSpawnTimer <= 0) {
- spawnCoin();
- game.coinSpawnTimer = 38 + Math.floor(Math.random() * 40);
- }
- // Update runner
- runner.update();
- // Update obstacles
- for (var i = obstacles.length - 1; i >= 0; i--) {
- var obs = obstacles[i];
- obs.update();
+ // Update cars
+ for (var i = cars.length - 1; i >= 0; i--) {
+ var car = cars[i];
+ car.x += car.speed;
// Remove if off screen
- if (obs.y > 2732 + 100) {
- obs.destroy();
- obstacles.splice(i, 1);
+ if (car.speed > 0 && car.x > 2048 + 300 || car.speed < 0 && car.x < -300) {
+ car.destroy();
+ cars.splice(i, 1);
continue;
}
- // Collision
- var rRect = runner.getCollisionRect();
- var oRect = obs.getCollisionRect();
- var hit = false;
- if (obs.type === 'log') {
- // Jump over
- if (!runner.isJumping && !runner.isSliding && rectsIntersect(rRect, oRect)) hit = true;
- if (runner.isSliding && rectsIntersect(rRect, oRect)) hit = true;
- } else if (obs.type === 'rock') {
- // Slide under
- if (!runner.isSliding && rectsIntersect(rRect, oRect)) hit = true;
- } else if (obs.type === 'pit') {
- // Must jump
- if (!runner.isJumping && rectsIntersect(rRect, oRect)) hit = true;
- }
- if (hit) {
+ // Collision with penguin
+ var pRect = penguin.getCollisionRect();
+ var cRect = car.getCollisionRect();
+ if (rectsIntersect(pRect, cRect)) {
LK.getSound('hitSound').play();
LK.effects.flashScreen(0xff0000, 800);
game.isGameOver = true;
LK.showGameOver();
return;
}
- // Score for passing
- if (!obs.passed && obs.y > runner.y) {
- game.score++;
- scoreTxt.setText(game.score);
- obs.passed = true;
- }
}
- // Update coins
- for (var j = coinsArr.length - 1; j >= 0; j--) {
- var coin = coinsArr[j];
- coin.update();
- // Remove if off screen
- if (coin.y > 2732 + 80) {
- coin.destroy();
- coinsArr.splice(j, 1);
- continue;
- }
- // Collect
- if (!coin.collected && rectsIntersect(runner.getCollisionRect(), coin.getCollisionRect())) {
- coin.collected = true;
- LK.getSound('coinSound').play();
- game.coins++;
- coinTxt.setText(game.coins);
- // Animate coin
- tween(coin, {
- y: coin.y - 120,
- alpha: 0
- }, {
- duration: 320,
- easing: tween.cubicOut,
- onFinish: function onFinish() {
- coin.destroy();
- }
- });
- coinsArr.splice(j, 1);
- }
+ // Check if penguin reached the top (success)
+ if (penguin.y <= 400) {
+ game.score++;
+ scoreTxt.setText(game.score);
+ // Reset penguin to start
+ penguin.x = game.penguinStartX;
+ penguin.y = game.penguinStartY;
+ // Optionally: increase car speed or spawn rate for difficulty
}
};
// Rectangle intersection helper
function rectsIntersect(r1, r2) {
return !(r2.x > r1.x + r1.width || r2.x + r2.width < r1.x || r2.y > r1.y + r1.height || r2.y + r2.height < r1.y);
}
// Reset on game restart
game.on('reset', function () {
- // Remove all obstacles and coins
- for (var i = 0; i < obstacles.length; i++) obstacles[i].destroy();
- for (var j = 0; j < coinsArr.length; j++) coinsArr[j].destroy();
- obstacles = [];
- coinsArr = [];
- game.speed = 18;
+ // Remove all cars
+ for (var i = 0; i < cars.length; i++) cars[i].destroy();
+ cars = [];
game.ticks = 0;
- game.spawnTimer = 0;
- game.coinSpawnTimer = 0;
game.score = 0;
- game.coins = 0;
game.isGameOver = false;
scoreTxt.setText('0');
- coinTxt.setText('0');
- runner.lane = 1;
- runner.x = game.laneCenterX;
- runner.y = game.groundY;
- runner.isJumping = false;
- runner.isSliding = false;
- runner.jumpY = 0;
- runner.slideTimer = 0;
+ penguin.x = game.penguinStartX;
+ penguin.y = game.penguinStartY;
});
\ No newline at end of file
make a cobblestone sidewalk butt be sure that the image is competible with 2048x300. In-Game asset. 2d. High contrast. No shadows
make the runner as crazy chicken. In-Game asset. 2d. High contrast. No shadows
make a fancy car. In-Game asset. 2d. High contrast. No shadows
pixel hearth. In-Game asset. 2d. High contrast. No shadows
Car image but its head should be on right side not left. Make a fancy car. In-Game asset. 2d. High contrast. No shadows
Make a freeway with image ratio of 2048x2732 but freeway should be seem like top view and should go from left to right. In-Game asset. 2d. High contrast. No shadows
A pixel shield image. In-Game asset. 2d. High contrast. No shadows
Car image but its head should be on right side not left. Make a fancy car colored green.. In-Game asset. 2d. High contrast. No shadows