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(); // Randomly pick car type: 'log', 'rock', or 'pit' var carTypes = ['log', 'rock', 'pit']; var carType = carTypes[Math.floor(Math.random() * carTypes.length)]; obs.setType(carType); // 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); } // Set width/height for visual consistency if (carType === 'log') { obs.width = 260; obs.height = 100; } else if (carType === 'rock') { obs.width = 140; obs.height = 140; } else if (carType === 'pit') { obs.width = 240; obs.height = 60; } 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 // Car spawn interval decreases as time passes (minimum 12 ticks, max 36 at start) var minInterval = 12; var maxInterval = 36; var interval = Math.max(minInterval, maxInterval - Math.floor(game.ticks / 300)); if (game.ticks % interval === 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) { // Penguin reached the top side, player wins! LK.showYouWin(); return; } // No win for reaching the bottom, only top is the goal }; // 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
@@ -150,10 +150,12 @@
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');
+ // Randomly pick car type: 'log', 'rock', or 'pit'
+ var carTypes = ['log', 'rock', 'pit'];
+ var carType = carTypes[Math.floor(Math.random() * carTypes.length)];
+ obs.setType(carType);
// 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;
@@ -165,10 +167,19 @@
} else {
obs.x = game.carStartRight;
obs.speed = -(16 + Math.random() * 8);
}
- obs.width = 260;
- obs.height = 100;
+ // Set width/height for visual consistency
+ if (carType === 'log') {
+ obs.width = 260;
+ obs.height = 100;
+ } else if (carType === 'rock') {
+ obs.width = 140;
+ obs.height = 140;
+ } else if (carType === 'pit') {
+ obs.width = 240;
+ obs.height = 60;
+ }
game.addChild(obs);
cars.push(obs);
}
// Touch/Swipe handling for penguin movement (up/down/left/right)
@@ -211,9 +222,13 @@
game.update = function () {
if (game.isGameOver) return;
game.ticks++;
// Spawn cars at intervals
- if (game.ticks % 36 === 0) {
+ // Car spawn interval decreases as time passes (minimum 12 ticks, max 36 at start)
+ var minInterval = 12;
+ var maxInterval = 36;
+ var interval = Math.max(minInterval, maxInterval - Math.floor(game.ticks / 300));
+ if (game.ticks % interval === 0) {
spawnCar();
}
// Update cars
for (var i = cars.length - 1; i >= 0; i--) {
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