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");
var storage = LK.import("@upit/storage.v1", {
selectedSkin: 4886754
});
/****
* 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 MenuButton = Container.expand(function (text, color) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5
});
buttonGraphics.tint = color;
var buttonText = new Text2(text, {
size: 60,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
if (text === 'PLAY') {
startGame();
} else if (text === 'SKINS') {
showSkinsMenu();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
playerGraphics.tint = storage.selectedSkin;
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;
});
var SkinButton = Container.expand(function (color) {
var self = Container.call(this);
var skinGraphics = self.attachAsset('skinPreview', {
anchorX: 0.5,
anchorY: 0.5
});
skinGraphics.tint = color;
self.skinColor = color;
self.down = function (x, y, obj) {
storage.selectedSkin = color;
showMainMenu();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game state
var gameState = 'menu'; // 'menu', 'skins', 'playing'
var menuElements = [];
var skinElements = [];
// Game variables
// Game variables (initialized when starting game)
var isGreenLight;
var lightTimer;
var greenLightDuration;
var redLightDuration;
var currentLightDuration;
var finishX;
var gameTimer;
var gameTimeLimit;
var bots;
var floor, startLine, finishLine, player, lightSystem;
var instructionText, lightStatusText, timerText;
var isPressed;
function showMainMenu() {
gameState = 'menu';
clearGame();
clearSkins();
// Create title
var titleText = new Text2('GREEN LIGHT RED LIGHT', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 800;
game.addChild(titleText);
menuElements.push(titleText);
// Create play button
var playButton = game.addChild(new MenuButton('PLAY', 0x4CAF50));
playButton.x = 1024;
playButton.y = 1200;
menuElements.push(playButton);
// Create skins button
var skinsButton = game.addChild(new MenuButton('SKINS', 0x2196F3));
skinsButton.x = 1024;
skinsButton.y = 1400;
menuElements.push(skinsButton);
}
function showSkinsMenu() {
gameState = 'skins';
clearMenu();
// Create title
var titleText = new Text2('SELECT SKIN', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 600;
game.addChild(titleText);
skinElements.push(titleText);
// Create skin options
var skinColors = [0x4a90e2, 0xff6b6b, 0x4ecdc4, 0xffe066, 0x95e1d3, 0xa29bfe];
var startX = 1024 - skinColors.length * 150 / 2;
for (var i = 0; i < skinColors.length; i++) {
var skinButton = game.addChild(new SkinButton(skinColors[i]));
skinButton.x = startX + i * 150;
skinButton.y = 1200;
skinElements.push(skinButton);
}
// Create back button
var backButton = game.addChild(new MenuButton('BACK', 0x757575));
backButton.x = 1024;
backButton.y = 1600;
backButton.down = function (x, y, obj) {
showMainMenu();
};
skinElements.push(backButton);
}
function startGame() {
gameState = 'playing';
clearMenu();
initializeGame();
}
function clearMenu() {
for (var i = 0; i < menuElements.length; i++) {
menuElements[i].destroy();
}
menuElements = [];
}
function clearSkins() {
for (var i = 0; i < skinElements.length; i++) {
skinElements[i].destroy();
}
skinElements = [];
}
function clearGame() {
if (floor) floor.destroy();
if (startLine) startLine.destroy();
if (finishLine) finishLine.destroy();
if (player) player.destroy();
if (lightSystem) lightSystem.destroy();
if (instructionText) instructionText.destroy();
if (lightStatusText) lightStatusText.destroy();
if (timerText) timerText.destroy();
if (bots) {
for (var i = 0; i < bots.length; i++) {
bots[i].destroy();
}
}
}
function initializeGame() {
// Initialize game variables
isGreenLight = true;
lightTimer = 0;
greenLightDuration = 180;
redLightDuration = 120;
currentLightDuration = greenLightDuration;
finishX = 1900;
gameTimer = 0;
gameTimeLimit = 5400;
bots = [];
// Create floor
floor = game.addChild(LK.getAsset('floor', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732
}));
// Create start line
startLine = game.addChild(LK.getAsset('startLine', {
anchorX: 0,
anchorY: 0,
x: 150,
y: 0,
width: 20,
height: 2732
}));
// Create finish line
finishLine = game.addChild(LK.getAsset('finishLine', {
anchorX: 0,
anchorY: 0,
x: finishX,
y: 0,
width: 20,
height: 2732
}));
// Create player
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;
bot.reactionTime = Math.random() * 10 + 3;
bot.maxSpeed = 1 + Math.random() * 0.8;
bots.push(bot);
}
// Create light system
lightSystem = game.addChild(new LightSystem());
lightSystem.x = 1024;
lightSystem.y = 300;
// Create instruction text
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
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
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);
// Initialize touch controls
isPressed = false;
}
// Touch controls
game.down = function (x, y, obj) {
if (gameState === 'playing') {
isPressed = true;
if (player) player.startRunning();
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing') {
isPressed = false;
if (player) player.stopRunning();
}
};
// Start with main menu
showMainMenu();
// Main game update
game.update = function () {
if (gameState !== 'playing') return;
// 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 && player.isMoving) {
// Player is eliminated for moving during red light
LK.showGameOver();
}
// Force stop player during red light
if (!isGreenLight && isPressed && player) {
player.stopRunning();
}
// Allow movement only during green light
if (isGreenLight && isPressed && player) {
player.startRunning();
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
selectedSkin: 4886754
});
/****
* 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 MenuButton = Container.expand(function (text, color) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5
});
buttonGraphics.tint = color;
var buttonText = new Text2(text, {
size: 60,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
if (text === 'PLAY') {
startGame();
} else if (text === 'SKINS') {
showSkinsMenu();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
playerGraphics.tint = storage.selectedSkin;
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;
});
var SkinButton = Container.expand(function (color) {
var self = Container.call(this);
var skinGraphics = self.attachAsset('skinPreview', {
anchorX: 0.5,
anchorY: 0.5
});
skinGraphics.tint = color;
self.skinColor = color;
self.down = function (x, y, obj) {
storage.selectedSkin = color;
showMainMenu();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game state
var gameState = 'menu'; // 'menu', 'skins', 'playing'
var menuElements = [];
var skinElements = [];
// Game variables
// Game variables (initialized when starting game)
var isGreenLight;
var lightTimer;
var greenLightDuration;
var redLightDuration;
var currentLightDuration;
var finishX;
var gameTimer;
var gameTimeLimit;
var bots;
var floor, startLine, finishLine, player, lightSystem;
var instructionText, lightStatusText, timerText;
var isPressed;
function showMainMenu() {
gameState = 'menu';
clearGame();
clearSkins();
// Create title
var titleText = new Text2('GREEN LIGHT RED LIGHT', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 800;
game.addChild(titleText);
menuElements.push(titleText);
// Create play button
var playButton = game.addChild(new MenuButton('PLAY', 0x4CAF50));
playButton.x = 1024;
playButton.y = 1200;
menuElements.push(playButton);
// Create skins button
var skinsButton = game.addChild(new MenuButton('SKINS', 0x2196F3));
skinsButton.x = 1024;
skinsButton.y = 1400;
menuElements.push(skinsButton);
}
function showSkinsMenu() {
gameState = 'skins';
clearMenu();
// Create title
var titleText = new Text2('SELECT SKIN', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 600;
game.addChild(titleText);
skinElements.push(titleText);
// Create skin options
var skinColors = [0x4a90e2, 0xff6b6b, 0x4ecdc4, 0xffe066, 0x95e1d3, 0xa29bfe];
var startX = 1024 - skinColors.length * 150 / 2;
for (var i = 0; i < skinColors.length; i++) {
var skinButton = game.addChild(new SkinButton(skinColors[i]));
skinButton.x = startX + i * 150;
skinButton.y = 1200;
skinElements.push(skinButton);
}
// Create back button
var backButton = game.addChild(new MenuButton('BACK', 0x757575));
backButton.x = 1024;
backButton.y = 1600;
backButton.down = function (x, y, obj) {
showMainMenu();
};
skinElements.push(backButton);
}
function startGame() {
gameState = 'playing';
clearMenu();
initializeGame();
}
function clearMenu() {
for (var i = 0; i < menuElements.length; i++) {
menuElements[i].destroy();
}
menuElements = [];
}
function clearSkins() {
for (var i = 0; i < skinElements.length; i++) {
skinElements[i].destroy();
}
skinElements = [];
}
function clearGame() {
if (floor) floor.destroy();
if (startLine) startLine.destroy();
if (finishLine) finishLine.destroy();
if (player) player.destroy();
if (lightSystem) lightSystem.destroy();
if (instructionText) instructionText.destroy();
if (lightStatusText) lightStatusText.destroy();
if (timerText) timerText.destroy();
if (bots) {
for (var i = 0; i < bots.length; i++) {
bots[i].destroy();
}
}
}
function initializeGame() {
// Initialize game variables
isGreenLight = true;
lightTimer = 0;
greenLightDuration = 180;
redLightDuration = 120;
currentLightDuration = greenLightDuration;
finishX = 1900;
gameTimer = 0;
gameTimeLimit = 5400;
bots = [];
// Create floor
floor = game.addChild(LK.getAsset('floor', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732
}));
// Create start line
startLine = game.addChild(LK.getAsset('startLine', {
anchorX: 0,
anchorY: 0,
x: 150,
y: 0,
width: 20,
height: 2732
}));
// Create finish line
finishLine = game.addChild(LK.getAsset('finishLine', {
anchorX: 0,
anchorY: 0,
x: finishX,
y: 0,
width: 20,
height: 2732
}));
// Create player
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;
bot.reactionTime = Math.random() * 10 + 3;
bot.maxSpeed = 1 + Math.random() * 0.8;
bots.push(bot);
}
// Create light system
lightSystem = game.addChild(new LightSystem());
lightSystem.x = 1024;
lightSystem.y = 300;
// Create instruction text
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
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
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);
// Initialize touch controls
isPressed = false;
}
// Touch controls
game.down = function (x, y, obj) {
if (gameState === 'playing') {
isPressed = true;
if (player) player.startRunning();
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing') {
isPressed = false;
if (player) player.stopRunning();
}
};
// Start with main menu
showMainMenu();
// Main game update
game.update = function () {
if (gameState !== 'playing') return;
// 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 && player.isMoving) {
// Player is eliminated for moving during red light
LK.showGameOver();
}
// Force stop player during red light
if (!isGreenLight && isPressed && player) {
player.stopRunning();
}
// Allow movement only during green light
if (isGreenLight && isPressed && player) {
player.startRunning();
}
};