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 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; 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; } } }; 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) // 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; 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 var ground = LK.getAsset('ground', { anchorX: 0.5, anchorY: 1, x: 2048 / 2, y: game.groundY + 150 }); game.addChild(ground); // Add runner var runner = new Runner(); runner.x = game.laneCenterX; runner.y = game.groundY; game.addChild(runner); // 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() { 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'); } else { obs.setType('pit'); } // 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; game.addChild(obs); obstacles.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 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) { runner.moveLane(1); // right } else if (dx < -swipeThreshold) { runner.moveLane(-1); // left } } else { // Vertical swipe if (dy < -swipeThreshold) { runner.jump(); } else if (dy > swipeThreshold) { runner.slide(); } } }; // 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 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(); // Remove if off screen if (obs.y > 2732 + 100) { obs.destroy(); obstacles.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) { 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); } } }; // 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; 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; });
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,396 @@
-/****
+/****
+* 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
+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;
+ 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;
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
+ backgroundColor: 0x1a3c1a
+});
+
+/****
+* Game Code
+****/
+// Sound effects
+// Jungle ground
+// 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;
+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
+var ground = LK.getAsset('ground', {
+ anchorX: 0.5,
+ anchorY: 1,
+ x: 2048 / 2,
+ y: game.groundY + 150
+});
+game.addChild(ground);
+// Add runner
+var runner = new Runner();
+runner.x = game.laneCenterX;
+runner.y = game.groundY;
+game.addChild(runner);
+// 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() {
+ 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');
+ } else {
+ obs.setType('pit');
+ }
+ // 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;
+ game.addChild(obs);
+ obstacles.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
+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) {
+ runner.moveLane(1); // right
+ } else if (dx < -swipeThreshold) {
+ runner.moveLane(-1); // left
+ }
+ } else {
+ // Vertical swipe
+ if (dy < -swipeThreshold) {
+ runner.jump();
+ } else if (dy > swipeThreshold) {
+ runner.slide();
+ }
+ }
+};
+// 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 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();
+ // Remove if off screen
+ if (obs.y > 2732 + 100) {
+ obs.destroy();
+ obstacles.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) {
+ 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);
+ }
+ }
+};
+// 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;
+ 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;
});
\ 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