User prompt
obsticles can run inside lane
User prompt
obsticles can come from any line
User prompt
obsticles slide sideways
User prompt
Please fix the bug: 'TypeError: obs.update is not a function' in or related to this line: 'obs.update();' Line Number: 255
User prompt
obsticles move sliding
User prompt
obsticles move without gaps
User prompt
obsticles can change position
User prompt
stripes run faster than obsticles
User prompt
stripes start at the begining
User prompt
match stripe speed and obsticle speed
User prompt
can we make the stripes roll down
User prompt
background runs down
User prompt
obsticles have different colors
User prompt
slower obsticles
User prompt
draw road lines
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 76
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 76
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 76
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 76
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 76
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 76
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 76
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 73
User prompt
Please fix the bug: 'RangeError: Maximum call stack size exceeded' in or related to this line: 'return {' Line Number: 73
Code edit (1 edits merged)
Please save this source code
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Player Car
var Car = Container.expand(function () {
var self = Container.call(this);
var carAsset = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = carAsset.width;
self.height = carAsset.height;
// For collision box
// Removed custom getBounds to avoid recursion bug
return self;
});
// Coin
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinAsset = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = coinAsset.width;
self.height = coinAsset.height;
self.speed = 18; // Will be increased by game
self.update = function () {
self.y += self.speed;
};
// Removed custom getBounds to avoid recursion bug
return self;
});
// Obstacle
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obsAsset = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = obsAsset.width;
self.height = obsAsset.height;
self.speed = 18; // Will be increased by game
self.update = function () {
self.y += self.speed;
};
// Removed custom getBounds to avoid recursion bug
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Coin
// Obstacle
// Car (player)
// Game area
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
// Lane system (3 lanes)
var LANE_COUNT = 3;
var LANE_WIDTH = GAME_WIDTH / LANE_COUNT;
var LANE_X = [Math.floor(LANE_WIDTH / 2), Math.floor(GAME_WIDTH / 2), Math.floor(GAME_WIDTH - LANE_WIDTH / 2)];
// Player car
var car = new Car();
game.addChild(car);
car.x = GAME_WIDTH / 2;
car.y = GAME_HEIGHT - 400;
// Dragging
var dragCar = false;
var dragOffsetX = 0;
// Obstacles and coins
var obstacles = [];
var coins = [];
// Difficulty
var baseSpeed = 18;
var speed = baseSpeed;
var speedIncreaseInterval = 600; // every 10 seconds (60*10)
var minObstacleInterval = 36; // minimum ticks between obstacles
var obstacleInterval = 60; // ticks between obstacles, will decrease
var minCoinInterval = 30;
var coinInterval = 60;
// Score
var score = 0;
var scoreTxt = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Helper: collision
function rectsIntersect(a, b) {
return !(a.x + a.width < b.x || a.x > b.x + b.width || a.y + a.height < b.y || a.y > b.y + b.height);
}
// Touch controls
function clamp(val, min, max) {
return Math.max(min, Math.min(max, val));
}
game.down = function (x, y, obj) {
// Only start drag if touch is on car
var local = car.toLocal(game.toGlobal({
x: x,
y: y
}));
if (local.x >= -car.width / 2 && local.x <= car.width / 2 && local.y >= -car.height / 2 && local.y <= car.height / 2) {
dragCar = true;
dragOffsetX = car.x - x;
}
};
game.move = function (x, y, obj) {
if (dragCar) {
// Only move horizontally, clamp to game area
var newX = clamp(x + dragOffsetX, car.width / 2, GAME_WIDTH - car.width / 2);
car.x = newX;
}
};
game.up = function (x, y, obj) {
dragCar = false;
};
// Spawning
var lastObstacleTick = 0;
var lastCoinTick = 0;
// Main update loop
game.update = function () {
// Increase speed and difficulty over time
if (LK.ticks % speedIncreaseInterval === 0 && LK.ticks > 0) {
speed += 2;
obstacleInterval = Math.max(minObstacleInterval, obstacleInterval - 4);
coinInterval = Math.max(minCoinInterval, coinInterval - 2);
}
// Spawn obstacles
if (LK.ticks - lastObstacleTick >= obstacleInterval) {
var obs = new Obstacle();
obs.speed = speed;
// Random lane
var lane = Math.floor(Math.random() * LANE_COUNT);
obs.x = LANE_X[lane];
obs.y = -obs.height / 2;
obstacles.push(obs);
game.addChild(obs);
lastObstacleTick = LK.ticks;
}
// Spawn coins
if (LK.ticks - lastCoinTick >= coinInterval) {
var coin = new Coin();
coin.speed = speed;
// Random lane, but not same as last obstacle
var lane = Math.floor(Math.random() * LANE_COUNT);
coin.x = LANE_X[lane];
coin.y = -coin.height / 2 - 200;
coins.push(coin);
game.addChild(coin);
lastCoinTick = LK.ticks;
}
// 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 car
if (rectsIntersect(obs.getBounds(), car.getBounds())) {
// Flash and game over
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
return;
}
}
// Update coins
for (var j = coins.length - 1; j >= 0; j--) {
var coin = coins[j];
coin.update();
// Remove if off screen
if (coin.y - coin.height / 2 > GAME_HEIGHT + 100) {
coin.destroy();
coins.splice(j, 1);
continue;
}
// Collect coin
if (rectsIntersect(coin.getBounds(), car.getBounds())) {
score += 1;
LK.setScore(score);
scoreTxt.setText(score);
// Animate coin
tween(coin, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
coin.destroy();
}
});
coins.splice(j, 1);
}
}
};
// Center score text at top, avoid top left 100x100
scoreTxt.x = LK.gui.top.width / 2;
scoreTxt.y = 20; ===================================================================
--- original.js
+++ change.js
@@ -15,17 +15,9 @@
});
self.width = carAsset.width;
self.height = carAsset.height;
// For collision box
- self.getBounds = function () {
- // Return a simple rectangle for collision, avoid recursion
- return {
- x: self.x - self.width / 2,
- y: self.y - self.height / 2,
- width: self.width,
- height: self.height
- };
- };
+ // Removed custom getBounds to avoid recursion bug
return self;
});
// Coin
var Coin = Container.expand(function () {
@@ -39,17 +31,9 @@
self.speed = 18; // Will be increased by game
self.update = function () {
self.y += self.speed;
};
- self.getBounds = function () {
- // Return a simple rectangle for collision, avoid recursion
- return {
- x: self.x - self.width / 2,
- y: self.y - self.height / 2,
- width: self.width,
- height: self.height
- };
- };
+ // Removed custom getBounds to avoid recursion bug
return self;
});
// Obstacle
var Obstacle = Container.expand(function () {
@@ -63,17 +47,9 @@
self.speed = 18; // Will be increased by game
self.update = function () {
self.y += self.speed;
};
- self.getBounds = function () {
- // Return a simple rectangle for collision, avoid recursion
- return {
- x: self.x - self.width / 2,
- y: self.y - self.height / 2,
- width: self.width,
- height: self.height
- };
- };
+ // Removed custom getBounds to avoid recursion bug
return self;
});
/****