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 Bot = Container.expand(function () {
var self = Container.call(this);
var botGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
// Make bots different colors
botGraphics.tint = 0xff6b6b; // Red tint for bots
self.speed = 0;
self.maxSpeed = 1.5; // Much slower speed
self.isMoving = false;
self.startX = 150;
self.reactionTime = Math.random() * 15 + 5; // Faster reaction time between 5-20 frames
self.reactionTimer = 0;
self.isEliminated = false;
self.lastGreenLight = isGreenLight;
self.update = function () {
if (self.isEliminated) return;
// Track light state changes
var currentGreenLight = isGreenLight;
if (self.lastGreenLight !== currentGreenLight) {
// Light changed, reset reaction timer
self.reactionTimer = 0;
}
self.lastGreenLight = currentGreenLight;
// Update reaction timer
self.reactionTimer++;
// Bot behavior during green light - more cautious start
if (isGreenLight && self.reactionTimer >= self.reactionTime) {
if (!self.isMoving) {
self.startRunning();
}
}
// Bot behavior during red light - immediate stop with safety margin
if (!isGreenLight) {
if (self.isMoving) {
self.stopRunning(); // Stop immediately when red light starts
}
}
// Move if should be moving
if (self.isMoving && isGreenLight) {
self.x += self.speed;
}
// Check if bot got caught moving during red light
if (!isGreenLight && self.isMoving) {
self.eliminate();
return;
}
// Keep bot within bounds
if (self.x > finishX) {
self.x = finishX;
}
};
self.startRunning = function () {
if (isGreenLight && !self.isEliminated) {
self.isMoving = true;
self.speed = self.maxSpeed;
}
};
self.stopRunning = function () {
self.isMoving = false;
self.speed = 0;
};
self.eliminate = function () {
self.isEliminated = true;
self.isMoving = false;
self.speed = 0;
LK.effects.flashObject(self, 0xff0000, 500);
// Make eliminated bot semi-transparent
botGraphics.alpha = 0.3;
};
return self;
});
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 = 2; // Reduced from 3 to 2
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)
var bots = [];
// 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 3 bots
for (var i = 0; i < 3; i++) {
var bot = game.addChild(new Bot());
bot.x = bot.startX;
bot.y = 2600 - (i + 1) * 150; // Position bots at different heights
bot.reactionTime = Math.random() * 10 + 3; // Faster reaction times 3-13 frames
bot.maxSpeed = 1 + Math.random() * 0.8; // Slower speeds between 1-1.8
bots.push(bot);
}
// 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
@@ -14,12 +14,12 @@
});
// Make bots different colors
botGraphics.tint = 0xff6b6b; // Red tint for bots
self.speed = 0;
- self.maxSpeed = 2.5; // Slightly slower than player
+ self.maxSpeed = 1.5; // Much slower speed
self.isMoving = false;
self.startX = 150;
- self.reactionTime = Math.random() * 20 + 10; // Random reaction time between 10-30 frames
+ self.reactionTime = Math.random() * 15 + 5; // Faster reaction time between 5-20 frames
self.reactionTimer = 0;
self.isEliminated = false;
self.lastGreenLight = isGreenLight;
self.update = function () {
@@ -32,18 +32,18 @@
}
self.lastGreenLight = currentGreenLight;
// Update reaction timer
self.reactionTimer++;
- // Bot behavior during green light
+ // Bot behavior during green light - more cautious start
if (isGreenLight && self.reactionTimer >= self.reactionTime) {
if (!self.isMoving) {
self.startRunning();
}
}
- // Bot behavior during red light
- if (!isGreenLight && self.reactionTimer >= self.reactionTime) {
+ // Bot behavior during red light - immediate stop with safety margin
+ if (!isGreenLight) {
if (self.isMoving) {
- self.stopRunning();
+ self.stopRunning(); // Stop immediately when red light starts
}
}
// Move if should be moving
if (self.isMoving && isGreenLight) {
@@ -103,9 +103,9 @@
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 0;
- self.maxSpeed = 3;
+ self.maxSpeed = 2; // Reduced from 3 to 2
self.isMoving = false;
self.startX = 150;
self.update = function () {
if (self.isMoving && isGreenLight) {
@@ -193,10 +193,10 @@
for (var i = 0; i < 3; i++) {
var bot = game.addChild(new Bot());
bot.x = bot.startX;
bot.y = 2600 - (i + 1) * 150; // Position bots at different heights
- bot.reactionTime = Math.random() * 25 + 5; // Different reaction times
- bot.maxSpeed = 2 + Math.random() * 1; // Different speeds between 2-3
+ bot.reactionTime = Math.random() * 10 + 3; // Faster reaction times 3-13 frames
+ bot.maxSpeed = 1 + Math.random() * 0.8; // Slower speeds between 1-1.8
bots.push(bot);
}
// Create light system
var lightSystem = game.addChild(new LightSystem());