User prompt
Coloca un menú donde hay botón de "jugar" donde te lleva al juego y el botón de "skins" dónde puedes equiparte otro color. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
También que los bots se den cuenta en quedarse quietos para que no sean eliminados. Disminuye la velocidad de los bots y del jugador.
User prompt
Ahora coloca 3 bots qué también caminen hacia la meta y cuando se muevan en luz roja, será eliminado.
User prompt
Coloca también si me muevo en luz roja, estoy eliminado. Y pon un cronómetro de 1:30, si se acaba y no cruzó la meta, estoy eliminado.
User prompt
Pero que el mapa sea grande y el piso cubre todo la pantalla y la líneas también. Y que al caminar, el jugador va lento.
Code edit (1 edits merged)
Please save this source code
User prompt
Green Light Red Light Runner
Initial prompt
Es de luz verde y luz roja, con efectos visuales y líneas de inicio y llegada y piso de color verde oscuro
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var LightSystem = Container.expand(function () {
var self = Container.call(this);
var lightGraphics = self.attachAsset('lightIndicator', {
anchorX: 0.5,
anchorY: 0.5
});
self.changeToGreen = function () {
lightGraphics.tint = 0x00ff00;
LK.effects.flashScreen(0x00ff00, 300);
LK.getSound('lightChange').play();
};
self.changeToRed = function () {
lightGraphics.tint = 0xff0000;
LK.effects.flashScreen(0xff0000, 300);
LK.getSound('lightChange').play();
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 0;
self.maxSpeed = 3;
self.isMoving = false;
self.startX = 150;
self.update = function () {
if (self.isMoving && isGreenLight) {
self.x += self.speed;
}
// Keep player within bounds
if (self.x > finishX) {
self.x = finishX;
// Player wins!
LK.showYouWin();
}
};
self.reset = function () {
self.x = self.startX;
self.speed = 0;
self.isMoving = false;
LK.effects.flashObject(self, 0xff0000, 500);
LK.getSound('reset').play();
};
self.startRunning = function () {
if (isGreenLight) {
self.isMoving = true;
self.speed = self.maxSpeed;
}
};
self.stopRunning = function () {
self.isMoving = false;
self.speed = 0;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var isGreenLight = true;
var lightTimer = 0;
var greenLightDuration = 180; // 3 seconds at 60fps
var redLightDuration = 120; // 2 seconds at 60fps
var currentLightDuration = greenLightDuration;
var finishX = 1900;
var gameTimer = 0;
var gameTimeLimit = 5400; // 1:30 minutes at 60fps (90 seconds * 60)
// Create floor
var floor = game.addChild(LK.getAsset('floor', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732
}));
// Create start line
var startLine = game.addChild(LK.getAsset('startLine', {
anchorX: 0,
anchorY: 0,
x: 150,
y: 0,
width: 20,
height: 2732
}));
// Create finish line
var finishLine = game.addChild(LK.getAsset('finishLine', {
anchorX: 0,
anchorY: 0,
x: finishX,
y: 0,
width: 20,
height: 2732
}));
// Create player
var player = game.addChild(new Player());
player.x = player.startX;
player.y = 2600;
// Create light system
var lightSystem = game.addChild(new LightSystem());
lightSystem.x = 1024;
lightSystem.y = 300;
// Create instruction text
var instructionText = new Text2('TAP AND HOLD TO RUN DURING GREEN LIGHT', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 600;
game.addChild(instructionText);
// Create light status text
var lightStatusText = new Text2('GREEN LIGHT - GO!', {
size: 80,
fill: 0x00FF00
});
lightStatusText.anchor.set(0.5, 0.5);
lightStatusText.x = 1024;
lightStatusText.y = 500;
game.addChild(lightStatusText);
// Create timer display text
var timerText = new Text2('1:30', {
size: 60,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0.5);
timerText.x = 1024;
timerText.y = 200;
game.addChild(timerText);
// Touch controls
var isPressed = false;
game.down = function (x, y, obj) {
isPressed = true;
player.startRunning();
};
game.up = function (x, y, obj) {
isPressed = false;
player.stopRunning();
};
// Main game update
game.update = function () {
// Update game timer
gameTimer++;
var remainingTime = gameTimeLimit - gameTimer;
var minutes = Math.floor(remainingTime / 3600);
var seconds = Math.floor(remainingTime % 3600 / 60);
// Format timer display
var timeDisplay = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
timerText.setText(timeDisplay);
// Check if time limit reached
if (gameTimer >= gameTimeLimit) {
LK.showGameOver();
return;
}
// Update light timer
lightTimer++;
// Check if it's time to change lights
if (lightTimer >= currentLightDuration) {
lightTimer = 0;
isGreenLight = !isGreenLight;
if (isGreenLight) {
lightSystem.changeToGreen();
lightStatusText.setText('GREEN LIGHT - GO!');
lightStatusText.tint = 0x00ff00;
currentLightDuration = greenLightDuration;
// Decrease green light duration slightly for progressive difficulty
if (greenLightDuration > 60) {
greenLightDuration -= 2;
}
} else {
lightSystem.changeToRed();
lightStatusText.setText('RED LIGHT - STOP!');
lightStatusText.tint = 0xff0000;
currentLightDuration = redLightDuration;
// Decrease red light duration slightly for progressive difficulty
if (redLightDuration > 40) {
redLightDuration -= 1;
}
}
}
// Check if player is caught moving during red light
if (!isGreenLight && player.isMoving) {
// Player is eliminated for moving during red light
LK.showGameOver();
}
// Force stop player during red light
if (!isGreenLight && isPressed) {
player.stopRunning();
}
// Allow movement only during green light
if (isGreenLight && isPressed) {
player.startRunning();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -81,8 +81,10 @@
var greenLightDuration = 180; // 3 seconds at 60fps
var redLightDuration = 120; // 2 seconds at 60fps
var currentLightDuration = greenLightDuration;
var finishX = 1900;
+var gameTimer = 0;
+var gameTimeLimit = 5400; // 1:30 minutes at 60fps (90 seconds * 60)
// Create floor
var floor = game.addChild(LK.getAsset('floor', {
anchorX: 0,
anchorY: 0,
@@ -134,8 +136,17 @@
lightStatusText.anchor.set(0.5, 0.5);
lightStatusText.x = 1024;
lightStatusText.y = 500;
game.addChild(lightStatusText);
+// Create timer display text
+var timerText = new Text2('1:30', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+timerText.anchor.set(0.5, 0.5);
+timerText.x = 1024;
+timerText.y = 200;
+game.addChild(timerText);
// Touch controls
var isPressed = false;
game.down = function (x, y, obj) {
isPressed = true;
@@ -146,8 +157,21 @@
player.stopRunning();
};
// Main game update
game.update = function () {
+ // Update game timer
+ gameTimer++;
+ var remainingTime = gameTimeLimit - gameTimer;
+ var minutes = Math.floor(remainingTime / 3600);
+ var seconds = Math.floor(remainingTime % 3600 / 60);
+ // Format timer display
+ var timeDisplay = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
+ timerText.setText(timeDisplay);
+ // Check if time limit reached
+ if (gameTimer >= gameTimeLimit) {
+ LK.showGameOver();
+ return;
+ }
// Update light timer
lightTimer++;
// Check if it's time to change lights
if (lightTimer >= currentLightDuration) {
@@ -174,12 +198,10 @@
}
}
// Check if player is caught moving during red light
if (!isGreenLight && player.isMoving) {
- player.reset();
- // Reset difficulty
- greenLightDuration = 180;
- redLightDuration = 120;
+ // Player is eliminated for moving during red light
+ LK.showGameOver();
}
// Force stop player during red light
if (!isGreenLight && isPressed) {
player.stopRunning();