/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0, currentLevel: 1 }); /**** * Classes ****/ var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('playerChar', { anchorX: 0.5, anchorY: 0.5 }); // Player state self.isDragging = false; self.startedCrossing = false; self.completedCrossing = false; self.lastX = 0; self.lastY = 0; self.update = function () { // Movement trail effect if (self.isDragging && (Math.abs(self.x - self.lastX) > 5 || Math.abs(self.y - self.lastY) > 5)) { var trail = LK.getAsset('playerChar', { anchorX: 0.5, anchorY: 0.5, x: self.x, y: self.y, alpha: 0.3, width: playerGraphics.width * 0.7, height: playerGraphics.height * 0.7 }); game.addChildAt(trail, 0); tween(trail, { alpha: 0, width: 20, height: 20 }, { duration: 400, onFinish: function onFinish() { game.removeChild(trail); trail = null; } }); self.lastX = self.x; self.lastY = self.y; } }; self.reset = function () { self.isDragging = false; self.startedCrossing = false; self.completedCrossing = false; }; return self; }); var TargetBoard = Container.expand(function () { var self = Container.call(this); var boardGraphics = self.attachAsset('targetBoard', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }); self.down = function (x, y, obj) { // Award points when target is clicked score += 10; scoreText.setText('Score: ' + score); // Visual feedback self.activate(); LK.effects.flashObject(self, 0xff0000, 500); // Play hit sound LK.getSound('hit').play(); // Show point notification var pointsNotification = new Text2('+ 10 pts!', { size: 60, fill: 0xFFFF00 }); pointsNotification.anchor.set(0.5, 0.5); pointsNotification.x = self.x; pointsNotification.y = self.y - 100; game.addChild(pointsNotification); tween(pointsNotification, { y: pointsNotification.y - 200, alpha: 0 }, { duration: 1500, onFinish: function onFinish() { game.removeChild(pointsNotification); } }); // Make target disappear and reappear in a new location tween(self.scale, { x: 0, y: 0 }, { duration: 300, onFinish: function onFinish() { // Move to a new random location self.x = 200 + Math.random() * (2048 - 400); self.y = Math.random() * 2732; // Make it reappear tween(self.scale, { x: 1, y: 1 }, { duration: 500, easing: tween.elasticOut }); } }); }; self.activate = function () { tween(boardGraphics, { alpha: 1 }, { duration: 200 }); }; self.deactivate = function () { tween(boardGraphics, { alpha: 0.8 }, { duration: 200 }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ // Game variables var player; var targetBoards = []; var startZone; var finishZone; var isDragging = false; var level = storage.currentLevel || 1; var score = 0; var highScore = storage.highScore || 0; var crossingStartTime = 0; var gameActive = true; var gameTimer = 60; // 60 second timer var timerInterval; // Timer interval reference // Text displays var scoreText; var levelText; var highScoreText; var instructionText; var timerText; // Initialize the game elements function initGame() { // Create zones startZone = game.addChild(LK.getAsset('startZone', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); finishZone = game.addChild(LK.getAsset('finishZone', { anchorX: 0, anchorY: 0, x: 2048 - 100, y: 0 })); // Create player player = game.addChild(new Player()); player.x = 50; player.y = 2732 / 2; player.lastX = player.x; player.lastY = player.y; // Set up UI setupUI(); // Generate level generateLevel(level); // Play background music LK.playMusic('gameMusic', { fade: { start: 0, end: 0.4, duration: 1000 } }); // Initialize and start the timer gameTimer = 60; timerText.setText('Time: ' + gameTimer); if (timerInterval) { LK.clearInterval(timerInterval); } timerInterval = LK.setInterval(updateTimer, 1000); } function setupUI() { // Score text scoreText = new Text2('Score: 0', { size: 50, fill: 0xFFFFFF }); scoreText.anchor.set(0, 0); LK.gui.topRight.addChild(scoreText); scoreText.x = -400; scoreText.y = 50; // Level text levelText = new Text2('Level: ' + level, { size: 50, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); LK.gui.top.addChild(levelText); levelText.y = 50; // Timer text timerText = new Text2('Time: 60', { size: 50, fill: 0xFFFFFF }); timerText.anchor.set(0, 0); LK.gui.topLeft.addChild(timerText); timerText.x = 50; timerText.y = 50; // High score text highScoreText = new Text2('High Score: ' + highScore, { size: 40, fill: 0xFFFFFF }); highScoreText.anchor.set(0, 0); LK.gui.topRight.addChild(highScoreText); highScoreText.x = -400; highScoreText.y = 110; // Instruction text instructionText = new Text2('Drag the blue square\nClick on red targets to earn points!', { size: 40, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); LK.gui.top.addChild(instructionText); instructionText.y = 150; // Hide instruction after a few seconds LK.setTimeout(function () { tween(instructionText, { alpha: 0 }, { duration: 1000 }); }, 5000); } function generateLevel(level) { // Clear previous targets clearTargets(); // Update level text levelText.setText('Level: ' + level); // Different patterns based on level var numTargets = Math.min(5 + level * 3, 40); var pattern = level % 4; switch (pattern) { case 1: generateRandomPattern(numTargets); break; case 2: generateGridPattern(numTargets); break; case 3: generatePathPattern(numTargets); break; default: generateMixedPattern(numTargets); break; } // Animate targets in animateTargetsIn(); } function clearTargets() { for (var i = 0; i < targetBoards.length; i++) { game.removeChild(targetBoards[i]); } targetBoards = []; } function generateRandomPattern(numTargets) { for (var i = 0; i < numTargets; i++) { var target = new TargetBoard(); // Keep targets away from the sides target.x = getValidRandomPosition().x; target.y = getValidRandomPosition().y; targetBoards.push(target); game.addChild(target); } } // Helper function for getting valid positions for targets function getValidRandomPosition() { var newX = 200 + Math.random() * (2048 - 400); var newY = Math.random() * 2732; return { x: newX, y: newY }; } function generateGridPattern(numTargets) { var gridSize = Math.ceil(Math.sqrt(numTargets)); var cellWidth = (2048 - 400) / gridSize; var cellHeight = 2732 / gridSize; for (var i = 0; i < gridSize; i++) { for (var j = 0; j < gridSize; j++) { if (targetBoards.length >= numTargets) { break; } // Skip some cells randomly if (Math.random() < 0.3) { continue; } var target = new TargetBoard(); target.x = 200 + i * cellWidth + cellWidth / 2; target.y = j * cellHeight + cellHeight / 2; targetBoards.push(target); game.addChild(target); } } } function generatePathPattern(numTargets) { var pathWidth = 400; var availableWidth = 2048 - 400 - pathWidth; var pathX = 200 + Math.random() * availableWidth; // Create a winding path var segments = Math.floor(numTargets / 4); var segmentHeight = 2732 / segments; for (var i = 0; i < segments; i++) { var segmentY = i * segmentHeight; var targetCount = Math.min(4, numTargets - targetBoards.length); for (var j = 0; j < targetCount; j++) { var target = new TargetBoard(); // Alternate path direction each segment if (i % 2 === 0) { target.x = pathX + j * 250; } else { target.x = 2048 - 200 - j * 250; } target.y = segmentY + segmentHeight / 2; targetBoards.push(target); game.addChild(target); } } } function generateMixedPattern(numTargets) { // Split the screen into 3 vertical sections var sectionHeight = 2732 / 3; for (var section = 0; section < 3; section++) { var targetsInSection = Math.floor(numTargets / 3); if (section === 2) { targetsInSection = numTargets - Math.floor(numTargets / 3) * 2; } for (var i = 0; i < targetsInSection; i++) { var target = new TargetBoard(); target.x = 200 + Math.random() * (2048 - 400); target.y = section * sectionHeight + Math.random() * sectionHeight; targetBoards.push(target); game.addChild(target); } } } function animateTargetsIn() { for (var i = 0; i < targetBoards.length; i++) { var target = targetBoards[i]; target.scale.x = 0; target.scale.y = 0; tween(target.scale, { x: 1, y: 1 }, { duration: 500 + i * 50, easing: tween.elasticOut }); } } function checkTargetCollisions() { var hitTarget = false; for (var i = 0; i < targetBoards.length; i++) { var target = targetBoards[i]; if (player.intersects(target)) { hitTarget = true; target.activate(); // Flash effect LK.effects.flashObject(target, 0xff0000, 500); LK.effects.flashScreen(0xff0000, 300); // Play hit sound LK.getSound('hit').play(); // Increase score when hitting red targets score += 10; scoreText.setText('Score: ' + score); // Show point notification var pointsNotification = new Text2('+ 10 pts!', { size: 60, fill: 0xFFFF00 }); pointsNotification.anchor.set(0.5, 0.5); pointsNotification.x = player.x; pointsNotification.y = player.y - 100; game.addChild(pointsNotification); tween(pointsNotification, { y: pointsNotification.y - 200, alpha: 0 }, { duration: 1500, onFinish: function onFinish() { game.removeChild(pointsNotification); } }); // Game over gameActive = false; player.isDragging = false; // Clear timer LK.clearInterval(timerInterval); // Save high score if (score > highScore) { highScore = score; storage.highScore = highScore; highScoreText.setText('High Score: ' + highScore); } // Show game over after a short delay LK.setTimeout(function () { LK.showGameOver(); }, 1000); break; } else { target.deactivate(); } } return hitTarget; } function checkZones() { // Check if player started crossing if (!player.startedCrossing && player.x > 150) { player.startedCrossing = true; crossingStartTime = Date.now(); } // Check if player reached finish zone if (player.startedCrossing && !player.completedCrossing && player.x > 2048 - 150) { player.completedCrossing = true; // Calculate time bonus var crossingTime = (Date.now() - crossingStartTime) / 1000; var timeBonus = Math.max(0, Math.floor(50 - crossingTime)); // Award points var levelPoints = level * 100; var totalPoints = levelPoints + timeBonus; score += totalPoints; // Update score text scoreText.setText('Score: ' + score); // Play success sound LK.getSound('success').play(); // Show point notification var pointsNotification = new Text2('+ ' + totalPoints + ' pts!', { size: 60, fill: 0xFFFF00 }); pointsNotification.anchor.set(0.5, 0.5); pointsNotification.x = player.x; pointsNotification.y = player.y - 100; game.addChild(pointsNotification); tween(pointsNotification, { y: pointsNotification.y - 200, alpha: 0 }, { duration: 1500, onFinish: function onFinish() { game.removeChild(pointsNotification); } }); // Level up after a delay LK.setTimeout(function () { level++; storage.currentLevel = level; generateLevel(level); // Reset player player.x = 50; player.y = 2732 / 2; player.reset(); // Reset timer gameTimer = 60; timerText.setText('Time: ' + gameTimer); timerText.style.fill = 0xFFFFFF; }, 1500); } } // Event handlers game.down = function (x, y, obj) { if (!gameActive) { return; } var dist = Math.sqrt(Math.pow(x - player.x, 2) + Math.pow(y - player.y, 2)); if (dist < 100) { player.isDragging = true; isDragging = true; } }; game.up = function (x, y, obj) { player.isDragging = false; isDragging = false; }; game.move = function (x, y, obj) { if (player.isDragging && gameActive) { player.x = x; player.y = y; // Constrain player to game area if (player.y < 40) { player.y = 40; } if (player.y > 2732 - 40) { player.y = 2732 - 40; } } }; game.update = function () { if (gameActive) { // Check for collisions checkTargetCollisions(); // Check zones checkZones(); } }; function updateTimer() { if (!gameActive) { return; } gameTimer--; timerText.setText('Time: ' + gameTimer); if (gameTimer <= 10) { // Flash timer text red when time is running low timerText.tint = gameTimer % 2 === 0 ? 0xFF0000 : 0xFFFFFF; } if (gameTimer <= 0) { // Time's up - end the game gameActive = false; player.isDragging = false; // Save high score if (score > highScore) { highScore = score; storage.highScore = highScore; highScoreText.setText('High Score: ' + highScore); } // Flash screen red LK.effects.flashScreen(0xFF0000, 500); // Show game over after a short delay LK.setTimeout(function () { LK.showGameOver(); }, 1000); // Clear the timer LK.clearInterval(timerInterval); } } // Initialize game initGame(); ;
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0,
currentLevel: 1
});
/****
* Classes
****/
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('playerChar', {
anchorX: 0.5,
anchorY: 0.5
});
// Player state
self.isDragging = false;
self.startedCrossing = false;
self.completedCrossing = false;
self.lastX = 0;
self.lastY = 0;
self.update = function () {
// Movement trail effect
if (self.isDragging && (Math.abs(self.x - self.lastX) > 5 || Math.abs(self.y - self.lastY) > 5)) {
var trail = LK.getAsset('playerChar', {
anchorX: 0.5,
anchorY: 0.5,
x: self.x,
y: self.y,
alpha: 0.3,
width: playerGraphics.width * 0.7,
height: playerGraphics.height * 0.7
});
game.addChildAt(trail, 0);
tween(trail, {
alpha: 0,
width: 20,
height: 20
}, {
duration: 400,
onFinish: function onFinish() {
game.removeChild(trail);
trail = null;
}
});
self.lastX = self.x;
self.lastY = self.y;
}
};
self.reset = function () {
self.isDragging = false;
self.startedCrossing = false;
self.completedCrossing = false;
};
return self;
});
var TargetBoard = Container.expand(function () {
var self = Container.call(this);
var boardGraphics = self.attachAsset('targetBoard', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
self.down = function (x, y, obj) {
// Award points when target is clicked
score += 10;
scoreText.setText('Score: ' + score);
// Visual feedback
self.activate();
LK.effects.flashObject(self, 0xff0000, 500);
// Play hit sound
LK.getSound('hit').play();
// Show point notification
var pointsNotification = new Text2('+ 10 pts!', {
size: 60,
fill: 0xFFFF00
});
pointsNotification.anchor.set(0.5, 0.5);
pointsNotification.x = self.x;
pointsNotification.y = self.y - 100;
game.addChild(pointsNotification);
tween(pointsNotification, {
y: pointsNotification.y - 200,
alpha: 0
}, {
duration: 1500,
onFinish: function onFinish() {
game.removeChild(pointsNotification);
}
});
// Make target disappear and reappear in a new location
tween(self.scale, {
x: 0,
y: 0
}, {
duration: 300,
onFinish: function onFinish() {
// Move to a new random location
self.x = 200 + Math.random() * (2048 - 400);
self.y = Math.random() * 2732;
// Make it reappear
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 500,
easing: tween.elasticOut
});
}
});
};
self.activate = function () {
tween(boardGraphics, {
alpha: 1
}, {
duration: 200
});
};
self.deactivate = function () {
tween(boardGraphics, {
alpha: 0.8
}, {
duration: 200
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
// Game variables
var player;
var targetBoards = [];
var startZone;
var finishZone;
var isDragging = false;
var level = storage.currentLevel || 1;
var score = 0;
var highScore = storage.highScore || 0;
var crossingStartTime = 0;
var gameActive = true;
var gameTimer = 60; // 60 second timer
var timerInterval; // Timer interval reference
// Text displays
var scoreText;
var levelText;
var highScoreText;
var instructionText;
var timerText;
// Initialize the game elements
function initGame() {
// Create zones
startZone = game.addChild(LK.getAsset('startZone', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
finishZone = game.addChild(LK.getAsset('finishZone', {
anchorX: 0,
anchorY: 0,
x: 2048 - 100,
y: 0
}));
// Create player
player = game.addChild(new Player());
player.x = 50;
player.y = 2732 / 2;
player.lastX = player.x;
player.lastY = player.y;
// Set up UI
setupUI();
// Generate level
generateLevel(level);
// Play background music
LK.playMusic('gameMusic', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
// Initialize and start the timer
gameTimer = 60;
timerText.setText('Time: ' + gameTimer);
if (timerInterval) {
LK.clearInterval(timerInterval);
}
timerInterval = LK.setInterval(updateTimer, 1000);
}
function setupUI() {
// Score text
scoreText = new Text2('Score: 0', {
size: 50,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -400;
scoreText.y = 50;
// Level text
levelText = new Text2('Level: ' + level, {
size: 50,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
levelText.y = 50;
// Timer text
timerText = new Text2('Time: 60', {
size: 50,
fill: 0xFFFFFF
});
timerText.anchor.set(0, 0);
LK.gui.topLeft.addChild(timerText);
timerText.x = 50;
timerText.y = 50;
// High score text
highScoreText = new Text2('High Score: ' + highScore, {
size: 40,
fill: 0xFFFFFF
});
highScoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(highScoreText);
highScoreText.x = -400;
highScoreText.y = 110;
// Instruction text
instructionText = new Text2('Drag the blue square\nClick on red targets to earn points!', {
size: 40,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
instructionText.y = 150;
// Hide instruction after a few seconds
LK.setTimeout(function () {
tween(instructionText, {
alpha: 0
}, {
duration: 1000
});
}, 5000);
}
function generateLevel(level) {
// Clear previous targets
clearTargets();
// Update level text
levelText.setText('Level: ' + level);
// Different patterns based on level
var numTargets = Math.min(5 + level * 3, 40);
var pattern = level % 4;
switch (pattern) {
case 1:
generateRandomPattern(numTargets);
break;
case 2:
generateGridPattern(numTargets);
break;
case 3:
generatePathPattern(numTargets);
break;
default:
generateMixedPattern(numTargets);
break;
}
// Animate targets in
animateTargetsIn();
}
function clearTargets() {
for (var i = 0; i < targetBoards.length; i++) {
game.removeChild(targetBoards[i]);
}
targetBoards = [];
}
function generateRandomPattern(numTargets) {
for (var i = 0; i < numTargets; i++) {
var target = new TargetBoard();
// Keep targets away from the sides
target.x = getValidRandomPosition().x;
target.y = getValidRandomPosition().y;
targetBoards.push(target);
game.addChild(target);
}
}
// Helper function for getting valid positions for targets
function getValidRandomPosition() {
var newX = 200 + Math.random() * (2048 - 400);
var newY = Math.random() * 2732;
return {
x: newX,
y: newY
};
}
function generateGridPattern(numTargets) {
var gridSize = Math.ceil(Math.sqrt(numTargets));
var cellWidth = (2048 - 400) / gridSize;
var cellHeight = 2732 / gridSize;
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
if (targetBoards.length >= numTargets) {
break;
}
// Skip some cells randomly
if (Math.random() < 0.3) {
continue;
}
var target = new TargetBoard();
target.x = 200 + i * cellWidth + cellWidth / 2;
target.y = j * cellHeight + cellHeight / 2;
targetBoards.push(target);
game.addChild(target);
}
}
}
function generatePathPattern(numTargets) {
var pathWidth = 400;
var availableWidth = 2048 - 400 - pathWidth;
var pathX = 200 + Math.random() * availableWidth;
// Create a winding path
var segments = Math.floor(numTargets / 4);
var segmentHeight = 2732 / segments;
for (var i = 0; i < segments; i++) {
var segmentY = i * segmentHeight;
var targetCount = Math.min(4, numTargets - targetBoards.length);
for (var j = 0; j < targetCount; j++) {
var target = new TargetBoard();
// Alternate path direction each segment
if (i % 2 === 0) {
target.x = pathX + j * 250;
} else {
target.x = 2048 - 200 - j * 250;
}
target.y = segmentY + segmentHeight / 2;
targetBoards.push(target);
game.addChild(target);
}
}
}
function generateMixedPattern(numTargets) {
// Split the screen into 3 vertical sections
var sectionHeight = 2732 / 3;
for (var section = 0; section < 3; section++) {
var targetsInSection = Math.floor(numTargets / 3);
if (section === 2) {
targetsInSection = numTargets - Math.floor(numTargets / 3) * 2;
}
for (var i = 0; i < targetsInSection; i++) {
var target = new TargetBoard();
target.x = 200 + Math.random() * (2048 - 400);
target.y = section * sectionHeight + Math.random() * sectionHeight;
targetBoards.push(target);
game.addChild(target);
}
}
}
function animateTargetsIn() {
for (var i = 0; i < targetBoards.length; i++) {
var target = targetBoards[i];
target.scale.x = 0;
target.scale.y = 0;
tween(target.scale, {
x: 1,
y: 1
}, {
duration: 500 + i * 50,
easing: tween.elasticOut
});
}
}
function checkTargetCollisions() {
var hitTarget = false;
for (var i = 0; i < targetBoards.length; i++) {
var target = targetBoards[i];
if (player.intersects(target)) {
hitTarget = true;
target.activate();
// Flash effect
LK.effects.flashObject(target, 0xff0000, 500);
LK.effects.flashScreen(0xff0000, 300);
// Play hit sound
LK.getSound('hit').play();
// Increase score when hitting red targets
score += 10;
scoreText.setText('Score: ' + score);
// Show point notification
var pointsNotification = new Text2('+ 10 pts!', {
size: 60,
fill: 0xFFFF00
});
pointsNotification.anchor.set(0.5, 0.5);
pointsNotification.x = player.x;
pointsNotification.y = player.y - 100;
game.addChild(pointsNotification);
tween(pointsNotification, {
y: pointsNotification.y - 200,
alpha: 0
}, {
duration: 1500,
onFinish: function onFinish() {
game.removeChild(pointsNotification);
}
});
// Game over
gameActive = false;
player.isDragging = false;
// Clear timer
LK.clearInterval(timerInterval);
// Save high score
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreText.setText('High Score: ' + highScore);
}
// Show game over after a short delay
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
break;
} else {
target.deactivate();
}
}
return hitTarget;
}
function checkZones() {
// Check if player started crossing
if (!player.startedCrossing && player.x > 150) {
player.startedCrossing = true;
crossingStartTime = Date.now();
}
// Check if player reached finish zone
if (player.startedCrossing && !player.completedCrossing && player.x > 2048 - 150) {
player.completedCrossing = true;
// Calculate time bonus
var crossingTime = (Date.now() - crossingStartTime) / 1000;
var timeBonus = Math.max(0, Math.floor(50 - crossingTime));
// Award points
var levelPoints = level * 100;
var totalPoints = levelPoints + timeBonus;
score += totalPoints;
// Update score text
scoreText.setText('Score: ' + score);
// Play success sound
LK.getSound('success').play();
// Show point notification
var pointsNotification = new Text2('+ ' + totalPoints + ' pts!', {
size: 60,
fill: 0xFFFF00
});
pointsNotification.anchor.set(0.5, 0.5);
pointsNotification.x = player.x;
pointsNotification.y = player.y - 100;
game.addChild(pointsNotification);
tween(pointsNotification, {
y: pointsNotification.y - 200,
alpha: 0
}, {
duration: 1500,
onFinish: function onFinish() {
game.removeChild(pointsNotification);
}
});
// Level up after a delay
LK.setTimeout(function () {
level++;
storage.currentLevel = level;
generateLevel(level);
// Reset player
player.x = 50;
player.y = 2732 / 2;
player.reset();
// Reset timer
gameTimer = 60;
timerText.setText('Time: ' + gameTimer);
timerText.style.fill = 0xFFFFFF;
}, 1500);
}
}
// Event handlers
game.down = function (x, y, obj) {
if (!gameActive) {
return;
}
var dist = Math.sqrt(Math.pow(x - player.x, 2) + Math.pow(y - player.y, 2));
if (dist < 100) {
player.isDragging = true;
isDragging = true;
}
};
game.up = function (x, y, obj) {
player.isDragging = false;
isDragging = false;
};
game.move = function (x, y, obj) {
if (player.isDragging && gameActive) {
player.x = x;
player.y = y;
// Constrain player to game area
if (player.y < 40) {
player.y = 40;
}
if (player.y > 2732 - 40) {
player.y = 2732 - 40;
}
}
};
game.update = function () {
if (gameActive) {
// Check for collisions
checkTargetCollisions();
// Check zones
checkZones();
}
};
function updateTimer() {
if (!gameActive) {
return;
}
gameTimer--;
timerText.setText('Time: ' + gameTimer);
if (gameTimer <= 10) {
// Flash timer text red when time is running low
timerText.tint = gameTimer % 2 === 0 ? 0xFF0000 : 0xFFFFFF;
}
if (gameTimer <= 0) {
// Time's up - end the game
gameActive = false;
player.isDragging = false;
// Save high score
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreText.setText('High Score: ' + highScore);
}
// Flash screen red
LK.effects.flashScreen(0xFF0000, 500);
// Show game over after a short delay
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
// Clear the timer
LK.clearInterval(timerInterval);
}
}
// Initialize game
initGame();
;