/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Doll = Container.expand(function () { var self = Container.call(this); var dollGraphics = self.attachAsset('doll', { anchorX: 0.5, anchorY: 0.5 }); self.isWatching = false; self.startWatching = function () { self.isWatching = true; dollGraphics.tint = 0xff0000; tween(dollGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200 }); }; self.stopWatching = function () { self.isWatching = false; dollGraphics.tint = 0xffffff; tween(dollGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200 }); }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 1.0 }); self.isMoving = false; self.lastX = 0; self.lastY = 0; self.eliminationFlash = false; self.update = function () { // Check if player is moving during red light if (gameState === 'RED_LIGHT' && !self.eliminationFlash) { var deltaX = Math.abs(self.x - self.lastX); var deltaY = Math.abs(self.y - self.lastY); if (deltaX > 1 || deltaY > 1) { self.eliminate(); return; } } self.lastX = self.x; self.lastY = self.y; }; self.eliminate = function () { self.eliminationFlash = true; LK.getSound('eliminate').play(); LK.effects.flashObject(self, 0xff0000, 500); LK.setTimeout(function () { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); }, 500); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Game state variables var gameState = 'GREEN_LIGHT'; // 'GREEN_LIGHT', 'RED_LIGHT', 'TRANSITION' var gameTimer = 60; // 60 seconds to complete var phaseTimer = 0; var currentPhase = 'green'; var greenLightDuration = 5000; // 5 seconds var redLightDuration = 3000; // 3 seconds var transitionDuration = 500; // 0.5 seconds var dragNode = null; var gameStarted = false; // Create background var bg = game.attachAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // Create finish line at top var finishLine = game.attachAsset('finishLine', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 220 }); // Create doll var doll = game.addChild(new Doll()); doll.x = 1024; doll.y = 400; // Create player var player = game.addChild(new Player()); player.x = 1024; player.y = 2500; player.lastX = player.x; player.lastY = player.y; // Create UI elements var stateText = new Text2('GREEN LIGHT', { size: 100, fill: 0x00FF00 }); stateText.anchor.set(0.5, 0.5); LK.gui.center.addChild(stateText); var timerText = new Text2('60', { size: 80, fill: 0xFFFFFF }); timerText.anchor.set(0.5, 0); LK.gui.top.addChild(timerText); var instructionText = new Text2('Drag to move during GREEN LIGHT!\nFreeze during RED LIGHT!', { size: 60, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 1); LK.gui.bottom.addChild(instructionText); // Start background music LK.playMusic('gameMusic'); // Game phase management function switchToGreenLight() { gameState = 'GREEN_LIGHT'; currentPhase = 'green'; phaseTimer = greenLightDuration; stateText.setText('GREEN LIGHT'); stateText.tint = 0x00ff00; doll.stopWatching(); LK.getSound('greenLight').play(); // Switch back to calm game music during green light LK.playMusic('gameMusic'); // Make green light phases progressively shorter if (greenLightDuration > 2500) { greenLightDuration -= 50; } } function switchToRedLight() { gameState = 'RED_LIGHT'; currentPhase = 'red'; phaseTimer = redLightDuration; stateText.setText('RED LIGHT'); stateText.tint = 0xff0000; doll.startWatching(); LK.getSound('redLight').play(); // Switch to tension music during red light LK.playMusic('tension'); // Flash screen briefly LK.effects.flashScreen(0xff0000, 200); // Make red light phases progressively longer if (redLightDuration < 4500) { redLightDuration += 25; } } // Touch controls with gradual movement var targetX = 0; var targetY = 0; var moveSpeed = 3; // Pixels per frame movement speed game.down = function (x, y, obj) { // Allow movement in both green and red light states dragNode = player; targetX = x; targetY = Math.max(250, Math.min(2500, y)); // Keep target in bounds }; game.move = function (x, y, obj) { if (dragNode) { targetX = x; targetY = Math.max(250, Math.min(2500, y)); // Keep target in bounds } }; game.up = function (x, y, obj) { dragNode = null; }; // Main game loop game.update = function () { if (!gameStarted) { gameStarted = true; switchToGreenLight(); } // Update game timer if (LK.ticks % 60 === 0) { // Every second gameTimer--; timerText.setText(gameTimer.toString()); if (gameTimer <= 0) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } } // Update phase timer phaseTimer -= 16.67; // Approximate milliseconds per frame at 60fps if (phaseTimer <= 0) { if (currentPhase === 'green') { switchToRedLight(); } else { switchToGreenLight(); } } // Handle gradual player movement if (dragNode) { var deltaX = targetX - player.x; var deltaY = targetY - player.y; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); if (distance > moveSpeed) { // Move towards target at constant speed var moveX = deltaX / distance * moveSpeed; var moveY = deltaY / distance * moveSpeed; player.x += moveX; player.y += moveY; } else { // Close enough, snap to target player.x = targetX; player.y = targetY; } } // Check win condition - track when player reaches finish line // Player anchor is at (0.5, 1.0) so we need to account for player height var playerGraphics = player.children[0]; // Get the player graphics asset var playerHeight = playerGraphics ? playerGraphics.height : 196; // Default height if not accessible var finishLineY = 220; var winThreshold = finishLineY + playerHeight * 0.5; // Allow win when player is halfway across finish line if (player.lastWinY === undefined) player.lastWinY = player.y; if (player.lastWinY > winThreshold && player.y <= winThreshold) { // Just crossed finish line var timeBonus = Math.max(0, gameTimer * 10); LK.setScore(1000 + timeBonus); LK.effects.flashScreen(0x00ff00, 1000); LK.showYouWin(); return; } player.lastWinY = player.y; // Update UI based on remaining time in phase var progress = 1 - phaseTimer / (currentPhase === 'green' ? greenLightDuration : redLightDuration); var alpha = 0.5 + 0.5 * Math.sin(progress * Math.PI * 8); // Pulsing effect stateText.alpha = alpha; };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Doll = Container.expand(function () {
var self = Container.call(this);
var dollGraphics = self.attachAsset('doll', {
anchorX: 0.5,
anchorY: 0.5
});
self.isWatching = false;
self.startWatching = function () {
self.isWatching = true;
dollGraphics.tint = 0xff0000;
tween(dollGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
};
self.stopWatching = function () {
self.isWatching = false;
dollGraphics.tint = 0xffffff;
tween(dollGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.isMoving = false;
self.lastX = 0;
self.lastY = 0;
self.eliminationFlash = false;
self.update = function () {
// Check if player is moving during red light
if (gameState === 'RED_LIGHT' && !self.eliminationFlash) {
var deltaX = Math.abs(self.x - self.lastX);
var deltaY = Math.abs(self.y - self.lastY);
if (deltaX > 1 || deltaY > 1) {
self.eliminate();
return;
}
}
self.lastX = self.x;
self.lastY = self.y;
};
self.eliminate = function () {
self.eliminationFlash = true;
LK.getSound('eliminate').play();
LK.effects.flashObject(self, 0xff0000, 500);
LK.setTimeout(function () {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}, 500);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game state variables
var gameState = 'GREEN_LIGHT'; // 'GREEN_LIGHT', 'RED_LIGHT', 'TRANSITION'
var gameTimer = 60; // 60 seconds to complete
var phaseTimer = 0;
var currentPhase = 'green';
var greenLightDuration = 5000; // 5 seconds
var redLightDuration = 3000; // 3 seconds
var transitionDuration = 500; // 0.5 seconds
var dragNode = null;
var gameStarted = false;
// Create background
var bg = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Create finish line at top
var finishLine = game.attachAsset('finishLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 220
});
// Create doll
var doll = game.addChild(new Doll());
doll.x = 1024;
doll.y = 400;
// Create player
var player = game.addChild(new Player());
player.x = 1024;
player.y = 2500;
player.lastX = player.x;
player.lastY = player.y;
// Create UI elements
var stateText = new Text2('GREEN LIGHT', {
size: 100,
fill: 0x00FF00
});
stateText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(stateText);
var timerText = new Text2('60', {
size: 80,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
var instructionText = new Text2('Drag to move during GREEN LIGHT!\nFreeze during RED LIGHT!', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
// Start background music
LK.playMusic('gameMusic');
// Game phase management
function switchToGreenLight() {
gameState = 'GREEN_LIGHT';
currentPhase = 'green';
phaseTimer = greenLightDuration;
stateText.setText('GREEN LIGHT');
stateText.tint = 0x00ff00;
doll.stopWatching();
LK.getSound('greenLight').play();
// Switch back to calm game music during green light
LK.playMusic('gameMusic');
// Make green light phases progressively shorter
if (greenLightDuration > 2500) {
greenLightDuration -= 50;
}
}
function switchToRedLight() {
gameState = 'RED_LIGHT';
currentPhase = 'red';
phaseTimer = redLightDuration;
stateText.setText('RED LIGHT');
stateText.tint = 0xff0000;
doll.startWatching();
LK.getSound('redLight').play();
// Switch to tension music during red light
LK.playMusic('tension');
// Flash screen briefly
LK.effects.flashScreen(0xff0000, 200);
// Make red light phases progressively longer
if (redLightDuration < 4500) {
redLightDuration += 25;
}
}
// Touch controls with gradual movement
var targetX = 0;
var targetY = 0;
var moveSpeed = 3; // Pixels per frame movement speed
game.down = function (x, y, obj) {
// Allow movement in both green and red light states
dragNode = player;
targetX = x;
targetY = Math.max(250, Math.min(2500, y)); // Keep target in bounds
};
game.move = function (x, y, obj) {
if (dragNode) {
targetX = x;
targetY = Math.max(250, Math.min(2500, y)); // Keep target in bounds
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game loop
game.update = function () {
if (!gameStarted) {
gameStarted = true;
switchToGreenLight();
}
// Update game timer
if (LK.ticks % 60 === 0) {
// Every second
gameTimer--;
timerText.setText(gameTimer.toString());
if (gameTimer <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Update phase timer
phaseTimer -= 16.67; // Approximate milliseconds per frame at 60fps
if (phaseTimer <= 0) {
if (currentPhase === 'green') {
switchToRedLight();
} else {
switchToGreenLight();
}
}
// Handle gradual player movement
if (dragNode) {
var deltaX = targetX - player.x;
var deltaY = targetY - player.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > moveSpeed) {
// Move towards target at constant speed
var moveX = deltaX / distance * moveSpeed;
var moveY = deltaY / distance * moveSpeed;
player.x += moveX;
player.y += moveY;
} else {
// Close enough, snap to target
player.x = targetX;
player.y = targetY;
}
}
// Check win condition - track when player reaches finish line
// Player anchor is at (0.5, 1.0) so we need to account for player height
var playerGraphics = player.children[0]; // Get the player graphics asset
var playerHeight = playerGraphics ? playerGraphics.height : 196; // Default height if not accessible
var finishLineY = 220;
var winThreshold = finishLineY + playerHeight * 0.5; // Allow win when player is halfway across finish line
if (player.lastWinY === undefined) player.lastWinY = player.y;
if (player.lastWinY > winThreshold && player.y <= winThreshold) {
// Just crossed finish line
var timeBonus = Math.max(0, gameTimer * 10);
LK.setScore(1000 + timeBonus);
LK.effects.flashScreen(0x00ff00, 1000);
LK.showYouWin();
return;
}
player.lastWinY = player.y;
// Update UI based on remaining time in phase
var progress = 1 - phaseTimer / (currentPhase === 'green' ? greenLightDuration : redLightDuration);
var alpha = 0.5 + 0.5 * Math.sin(progress * Math.PI * 8); // Pulsing effect
stateText.alpha = alpha;
};
Oyuncak kız bebek . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Sarışın kısa saçlı bir yetişkin insan. In-Game asset. 2d. High contrast. No shadows
Kum sarı. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat