User prompt
As que las bombas cuando salgan en 2 segundos explotan y si explota sercas del carro perdemos ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Las bombas explota cuando están secas de nosostros ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Que las bombas no exploten cundo las tocamos explotan cundo salen ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
As que las bombas exploten y si explotan perdemos ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
As unas bombas que salen y explotan ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
As bombas que exploten cuando estén serca el carro ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
As que las bombas exploten ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
As que cada 5 segundos aparezcan bombas pero no quites los animales ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Agrega un sistema de puntos que diga puntos
User prompt
En el menú de pausa pon una velocidad de 10 a 100
User prompt
Agrega unas flechas para poder cambiar de dirección
User prompt
El piso ponlo de color gris
User prompt
En el menú principal pon animales caminando en la carretera ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Quita los carro que te dije orita
User prompt
AS que los carro estén el toda la pantalla y quita el fondo del juego
User prompt
En el fondo del menú principal pon carros
User prompt
Pon un menú inicial
User prompt
Pon 10 de speed y cada 2 segundos sube 1 speed
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Animal = Container.expand(function () {
var self = Container.call(this);
// Randomly choose animal type
var animalTypes = ['animal1', 'animal2', 'animal3'];
var randomType = animalTypes[Math.floor(Math.random() * animalTypes.length)];
var animalGraphics = self.attachAsset(randomType, {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4 + Math.random() * 3; // Slower speed for animals between 4-7
self.lane = 0;
self.checkedForNearMiss = false;
self.update = function () {
self.y += self.speed + gameSpeed;
};
return self;
});
var PlayerCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('playerCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.lane = 1; // Current lane (0-3)
self.targetX = 0;
self.speed = 8;
self.update = function () {
// Smooth movement towards target position
var diff = self.targetX - self.x;
if (Math.abs(diff) > 2) {
self.x += diff * 0.15;
} else {
self.x = self.targetX;
}
};
self.moveTo = function (lane) {
if (lane >= 0 && lane < 4) {
self.lane = lane;
self.targetX = lanePositions[lane];
}
};
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 = 5;
self.update = function () {
self.y += self.speed + gameSpeed;
if (self.y > 2732 + 50) {
self.y = -50;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Green frog
// Orange fox
// Brown bear
// Game variables
var showMenu = true;
var gameStarted = false;
var countdownActive = false;
var countdownNumber = 3;
var gameSpeed = 10;
var speedIncrement = 0.01;
var maxSpeed = 15;
var speedIncreaseTimer = 0;
var speedIncreaseInterval = 120; // 2 seconds at 60 FPS
var lanePositions = [400, 650, 900, 1150]; // X positions for 4 lanes
var animals = [];
var roadLines = [];
var lastTrafficSpawn = 0;
var minSpawnDelay = 60; // Minimum ticks between spawns
var maxSpawnDelay = 120; // Maximum ticks between spawns
var nextSpawnDelay = 90;
var gameStartTime = 0;
var lastNearMissCheck = 0;
var menuAnimals = []; // Array to hold menu background animals
// Create player car
var player = game.addChild(new PlayerCar());
player.x = lanePositions[1]; // Start in second lane
player.y = 2400; // Near bottom of screen
player.targetX = player.x;
// Create road lines for visual effect
for (var i = 0; i < 12; i++) {
var roadLine = game.addChild(new RoadLine());
roadLine.x = 525; // Between lanes 0 and 1
roadLine.y = i * 150 - 100;
roadLines.push(roadLine);
var roadLine2 = game.addChild(new RoadLine());
roadLine2.x = 775; // Between lanes 1 and 2
roadLine2.y = i * 150 - 100;
roadLines.push(roadLine2);
var roadLine3 = game.addChild(new RoadLine());
roadLine3.x = 1025; // Between lanes 2 and 3
roadLine3.y = i * 150 - 100;
roadLines.push(roadLine3);
}
// Create score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create speed display
var speedTxt = new Text2('Speed: 0', {
size: 80,
fill: 0xFFFF00
});
speedTxt.anchor.set(1, 0);
speedTxt.x = -20;
speedTxt.y = 20;
LK.gui.topRight.addChild(speedTxt);
// Create countdown display
var countdownTxt = new Text2('3', {
size: 300,
fill: 0xFF0000
});
countdownTxt.anchor.set(0.5, 0.5);
countdownTxt.visible = false;
LK.gui.center.addChild(countdownTxt);
// Create menu elements
var menuTitle = new Text2('ENDLESS RACING', {
size: 180,
fill: 0xFFFFFF
});
menuTitle.anchor.set(0.5, 0.5);
menuTitle.y = -200;
LK.gui.center.addChild(menuTitle);
var playButton = new Text2('TAP TO PLAY', {
size: 120,
fill: 0x00FF00
});
playButton.anchor.set(0.5, 0.5);
playButton.y = 100;
LK.gui.center.addChild(playButton);
var instructionsText = new Text2('Swipe left/right to dodge traffic', {
size: 80,
fill: 0xCCCCCC
});
instructionsText.anchor.set(0.5, 0.5);
instructionsText.y = 250;
LK.gui.center.addChild(instructionsText);
// Create menu background animals
for (var i = 0; i < 8; i++) {
var menuAnimal = new Animal();
var lane = Math.floor(Math.random() * 4);
menuAnimal.x = lanePositions[lane];
menuAnimal.y = Math.random() * 2732;
menuAnimal.speed = 2 + Math.random() * 3; // Slower speed for menu
menuAnimals.push(menuAnimal);
game.addChild(menuAnimal);
}
// Touch controls
var isDragging = false;
var dragStartX = 0;
var dragStartLane = 0;
game.down = function (x, y, obj) {
if (showMenu) {
// Start game from menu
showMenu = false;
countdownActive = true;
countdownTxt.visible = true;
menuTitle.visible = false;
playButton.visible = false;
instructionsText.visible = false;
// Hide menu animals
for (var i = 0; i < menuAnimals.length; i++) {
menuAnimals[i].destroy();
}
menuAnimals = [];
startCountdown();
return;
}
isDragging = true;
dragStartX = x;
dragStartLane = player.lane;
};
game.move = function (x, y, obj) {
if (isDragging) {
var dragDistance = x - dragStartX;
var laneChange = Math.floor(dragDistance / 150); // Sensitivity for lane changes
var targetLane = Math.max(0, Math.min(3, dragStartLane + laneChange));
player.moveTo(targetLane);
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
// Main game update
game.update = function () {
// Don't update game logic if menu is showing
if (showMenu) {
// Update menu background animals
for (var i = menuAnimals.length - 1; i >= 0; i--) {
var menuAnimal = menuAnimals[i];
menuAnimal.y += menuAnimal.speed;
// Reset animal position when it goes off screen
if (menuAnimal.y > 2732 + 100) {
menuAnimal.y = -100;
var lane = Math.floor(Math.random() * 4);
menuAnimal.x = lanePositions[lane];
}
}
return;
}
// Handle countdown at game start
if (countdownActive) {
// Don't update game logic during countdown
return;
}
// Increase game speed over time
if (gameSpeed < maxSpeed) {
gameSpeed += speedIncrement;
}
// Increase speed by 1 every 2 seconds
speedIncreaseTimer++;
if (speedIncreaseTimer >= speedIncreaseInterval) {
gameSpeed += 1;
speedIncreaseTimer = 0;
}
// Update score based on time survived
var timeScore = Math.floor(LK.ticks / 10);
LK.setScore(timeScore);
scoreTxt.setText(LK.getScore());
speedTxt.setText('Speed: ' + Math.floor(gameSpeed));
// Spawn animals
if (LK.ticks - lastTrafficSpawn > nextSpawnDelay) {
spawnAnimal();
lastTrafficSpawn = LK.ticks;
nextSpawnDelay = minSpawnDelay + Math.random() * (maxSpawnDelay - minSpawnDelay);
// Decrease spawn delay as speed increases
nextSpawnDelay = Math.max(30, nextSpawnDelay - gameSpeed);
}
// Check for collisions and near misses
for (var i = animals.length - 1; i >= 0; i--) {
var animal = animals[i];
// Remove animals that are off screen
if (animal.y > 2732 + 100) {
animal.destroy();
animals.splice(i, 1);
continue;
}
// Check for collision with player
if (animal.intersects(player)) {
// Game over
LK.getSound('crash').play();
LK.showGameOver();
return;
}
// Check for near miss (bonus points)
if (!animal.checkedForNearMiss && animal.y > player.y - 100 && animal.y < player.y + 100) {
var distance = Math.abs(animal.x - player.x);
if (distance < 120 && distance > 80 && animal.lane !== player.lane) {
// Near miss! Award bonus points
LK.setScore(LK.getScore() + 10);
LK.getSound('nearMiss').play();
animal.checkedForNearMiss = true;
}
}
}
};
// Start countdown sequence
function startCountdown() {
if (countdownNumber > 0) {
countdownTxt.setText(countdownNumber.toString());
countdownTxt.alpha = 1;
countdownTxt.scaleX = 1;
countdownTxt.scaleY = 1;
// Animate countdown number
tween(countdownTxt, {
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
countdownNumber--;
if (countdownNumber > 0) {
startCountdown();
} else {
// Show "GO!" message
countdownTxt.setText('GO!');
countdownTxt.fill = 0x00FF00;
countdownTxt.alpha = 1;
countdownTxt.scaleX = 1;
countdownTxt.scaleY = 1;
tween(countdownTxt, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
countdownActive = false;
gameStarted = true;
countdownTxt.visible = false;
}
});
}
}
});
}
}
// Menu is shown by default, countdown starts when user taps to play
function spawnAnimal() {
var animal = new Animal();
var lane = Math.floor(Math.random() * 4);
// Avoid spawning in same lane as player if too close
if (lane === player.lane && Math.random() < 0.3) {
lane = (lane + 1) % 4;
}
animal.lane = lane;
animal.x = lanePositions[lane];
animal.y = -100; // Start above screen
animal.speed += gameSpeed * 0.3; // Animal speed increases with game speed (slower than cars)
animals.push(animal);
game.addChild(animal);
} ===================================================================
--- original.js
+++ change.js
@@ -96,8 +96,9 @@
var maxSpawnDelay = 120; // Maximum ticks between spawns
var nextSpawnDelay = 90;
var gameStartTime = 0;
var lastNearMissCheck = 0;
+var menuAnimals = []; // Array to hold menu background animals
// Create player car
var player = game.addChild(new PlayerCar());
player.x = lanePositions[1]; // Start in second lane
player.y = 2400; // Near bottom of screen
@@ -162,8 +163,18 @@
});
instructionsText.anchor.set(0.5, 0.5);
instructionsText.y = 250;
LK.gui.center.addChild(instructionsText);
+// Create menu background animals
+for (var i = 0; i < 8; i++) {
+ var menuAnimal = new Animal();
+ var lane = Math.floor(Math.random() * 4);
+ menuAnimal.x = lanePositions[lane];
+ menuAnimal.y = Math.random() * 2732;
+ menuAnimal.speed = 2 + Math.random() * 3; // Slower speed for menu
+ menuAnimals.push(menuAnimal);
+ game.addChild(menuAnimal);
+}
// Touch controls
var isDragging = false;
var dragStartX = 0;
var dragStartLane = 0;
@@ -175,8 +186,13 @@
countdownTxt.visible = true;
menuTitle.visible = false;
playButton.visible = false;
instructionsText.visible = false;
+ // Hide menu animals
+ for (var i = 0; i < menuAnimals.length; i++) {
+ menuAnimals[i].destroy();
+ }
+ menuAnimals = [];
startCountdown();
return;
}
isDragging = true;
@@ -197,8 +213,19 @@
// Main game update
game.update = function () {
// Don't update game logic if menu is showing
if (showMenu) {
+ // Update menu background animals
+ for (var i = menuAnimals.length - 1; i >= 0; i--) {
+ var menuAnimal = menuAnimals[i];
+ menuAnimal.y += menuAnimal.speed;
+ // Reset animal position when it goes off screen
+ if (menuAnimal.y > 2732 + 100) {
+ menuAnimal.y = -100;
+ var lane = Math.floor(Math.random() * 4);
+ menuAnimal.x = lanePositions[lane];
+ }
+ }
return;
}
// Handle countdown at game start
if (countdownActive) {