User prompt
Cada que inicie el juego pon un contador de 3 segundos ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Pon 10 de speed y cada 1 segundos 1 de speed
User prompt
Pon 20 de speed y cada 5 segundos pon 1 speed
User prompt
Pon más 100 de speed y cada 10 segundos suba más 10 de speed
User prompt
As animales que no los tengo que atropellar
Code edit (1 edits merged)
Please save this source code
User prompt
Speed Racer Dash
Initial prompt
Crea un juego de carros
/****
* 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: 0x333333
});
/****
* Game Code
****/
// Green frog
// Orange fox
// Brown bear
// Game variables
var gameSpeed = 2;
var speedIncrement = 0.01;
var maxSpeed = 15;
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;
// 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);
// Touch controls
var isDragging = false;
var dragStartX = 0;
var dragStartLane = 0;
game.down = function (x, y, obj) {
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 () {
// Increase game speed over time
if (gameSpeed < maxSpeed) {
gameSpeed += speedIncrement;
}
// 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;
}
}
}
};
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
@@ -5,8 +5,25 @@
/****
* 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,
@@ -46,25 +63,8 @@
}
};
return self;
});
-var TrafficCar = Container.expand(function () {
- var self = Container.call(this);
- // Randomly choose car type
- var carTypes = ['trafficCar1', 'trafficCar2', 'trafficCar3'];
- var randomType = carTypes[Math.floor(Math.random() * carTypes.length)];
- var carGraphics = self.attachAsset(randomType, {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 6 + Math.random() * 4; // Random speed between 6-10
- self.lane = 0;
- self.checkedForNearMiss = false;
- self.update = function () {
- self.y += self.speed + gameSpeed;
- };
- return self;
-});
/****
* Initialize Game
****/
@@ -74,14 +74,17 @@
/****
* Game Code
****/
+// Green frog
+// Orange fox
+// Brown bear
// Game variables
var gameSpeed = 2;
var speedIncrement = 0.01;
var maxSpeed = 15;
var lanePositions = [400, 650, 900, 1150]; // X positions for 4 lanes
-var trafficCars = [];
+var animals = [];
var roadLines = [];
var lastTrafficSpawn = 0;
var minSpawnDelay = 60; // Minimum ticks between spawns
var maxSpawnDelay = 120; // Maximum ticks between spawns
@@ -154,54 +157,54 @@
var timeScore = Math.floor(LK.ticks / 10);
LK.setScore(timeScore);
scoreTxt.setText(LK.getScore());
speedTxt.setText('Speed: ' + Math.floor(gameSpeed));
- // Spawn traffic cars
+ // Spawn animals
if (LK.ticks - lastTrafficSpawn > nextSpawnDelay) {
- spawnTrafficCar();
+ 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 = trafficCars.length - 1; i >= 0; i--) {
- var car = trafficCars[i];
- // Remove cars that are off screen
- if (car.y > 2732 + 100) {
- car.destroy();
- trafficCars.splice(i, 1);
+ 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 (car.intersects(player)) {
+ if (animal.intersects(player)) {
// Game over
LK.getSound('crash').play();
LK.showGameOver();
return;
}
// Check for near miss (bonus points)
- if (!car.checkedForNearMiss && car.y > player.y - 100 && car.y < player.y + 100) {
- var distance = Math.abs(car.x - player.x);
- if (distance < 120 && distance > 80 && car.lane !== player.lane) {
+ 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();
- car.checkedForNearMiss = true;
+ animal.checkedForNearMiss = true;
}
}
}
};
-function spawnTrafficCar() {
- var car = new TrafficCar();
+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;
}
- car.lane = lane;
- car.x = lanePositions[lane];
- car.y = -100; // Start above screen
- car.speed += gameSpeed * 0.5; // Traffic speed increases with game speed
- trafficCars.push(car);
- game.addChild(car);
+ 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);
}
\ No newline at end of file