/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Target = Container.expand(function () { var self = Container.call(this); var targetGraphics = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5 }); // Target lifespan is 1.5 seconds self.lifespan = 1500; self.spawnTime = Date.now(); self.isActive = true; // Visual feedback on spawn targetGraphics.alpha = 0; tween(targetGraphics, { alpha: 1 }, { duration: 200 }); // Auto-destroy after 2 seconds self.destroyTimer = LK.setTimeout(function () { if (self.isActive) { self.fadeOut(); } }, self.lifespan); self.fadeOut = function () { if (!self.isActive) return; self.isActive = false; tween(targetGraphics, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.destroy(); // Remove from targets array for (var i = targets.length - 1; i >= 0; i--) { if (targets[i] === self) { targets.splice(i, 1); break; } } // Spawn new target immediately when one disappears spawnTarget(); } }); }; // Handle tap self.down = function (x, y, obj) { if (!self.isActive) return; // Score point LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Play sound LK.getSound('pop').play(); // Visual feedback tween(targetGraphics, { scaleX: 1.3, scaleY: 1.3 }, { duration: 100, easing: tween.easeOut }); // Remove target self.isActive = false; LK.clearTimeout(self.destroyTimer); tween(targetGraphics, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 200, onFinish: function onFinish() { self.destroy(); // Remove from targets array for (var i = targets.length - 1; i >= 0; i--) { if (targets[i] === self) { targets.splice(i, 1); break; } } // Spawn new target immediately when tapped spawnTarget(); } }); }; self.update = function () { if (!self.isActive) return; // Fade out effect as time runs out var timeLeft = self.lifespan - (Date.now() - self.spawnTime); if (timeLeft < 500) { var fadeRatio = timeLeft / 500; targetGraphics.alpha = Math.max(0.3, fadeRatio); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2E3440 }); /**** * Game Code ****/ // Add background var background = game.attachAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // Game variables var targets = []; var spawnTimer = 0; var baseSpawnRate = 120; // Spawn every 2 seconds at 60fps var minSpawnRate = 30; // Minimum spawn interval (0.5 seconds) var spawnRateDecrease = 2; // How much to decrease spawn rate over time // Get high score from storage var highScore = storage.highScore || 0; // Score display var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Position score text slightly down from top scoreTxt.y = 50; // High score display var highScoreTxt = new Text2('Best: ' + highScore, { size: 80, fill: 0xFFD700 }); highScoreTxt.anchor.set(1, 0); LK.gui.topRight.addChild(highScoreTxt); highScoreTxt.x = -20; highScoreTxt.y = 50; // Instructions text var instructionTxt = new Text2('Tap the circles before they disappear!', { size: 60, fill: 0xFFFFFF }); instructionTxt.anchor.set(0.5, 0.5); instructionTxt.x = 2048 / 2; instructionTxt.y = 2732 - 200; game.addChild(instructionTxt); // Fade out instructions after a few seconds LK.setTimeout(function () { tween(instructionTxt, { alpha: 0 }, { duration: 1000 }); }, 3000); function spawnTarget() { // Only spawn if no targets exist (one at a time) if (targets.length > 0) return; var target = new Target(); // Random position within safe bounds var margin = 100; target.x = margin + Math.random() * (2048 - 2 * margin); target.y = margin + Math.random() * (2732 - 2 * margin); targets.push(target); game.addChild(target); } // Spawn the first target spawnTarget(); game.update = function () { // Update score display scoreTxt.setText(LK.getScore()); // Check and update high score var currentScore = LK.getScore(); if (currentScore > highScore) { highScore = currentScore; storage.highScore = highScore; highScoreTxt.setText('Best: ' + highScore); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
// Target lifespan is 1.5 seconds
self.lifespan = 1500;
self.spawnTime = Date.now();
self.isActive = true;
// Visual feedback on spawn
targetGraphics.alpha = 0;
tween(targetGraphics, {
alpha: 1
}, {
duration: 200
});
// Auto-destroy after 2 seconds
self.destroyTimer = LK.setTimeout(function () {
if (self.isActive) {
self.fadeOut();
}
}, self.lifespan);
self.fadeOut = function () {
if (!self.isActive) return;
self.isActive = false;
tween(targetGraphics, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
// Remove from targets array
for (var i = targets.length - 1; i >= 0; i--) {
if (targets[i] === self) {
targets.splice(i, 1);
break;
}
}
// Spawn new target immediately when one disappears
spawnTarget();
}
});
};
// Handle tap
self.down = function (x, y, obj) {
if (!self.isActive) return;
// Score point
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Play sound
LK.getSound('pop').play();
// Visual feedback
tween(targetGraphics, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 100,
easing: tween.easeOut
});
// Remove target
self.isActive = false;
LK.clearTimeout(self.destroyTimer);
tween(targetGraphics, {
alpha: 0,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 200,
onFinish: function onFinish() {
self.destroy();
// Remove from targets array
for (var i = targets.length - 1; i >= 0; i--) {
if (targets[i] === self) {
targets.splice(i, 1);
break;
}
}
// Spawn new target immediately when tapped
spawnTarget();
}
});
};
self.update = function () {
if (!self.isActive) return;
// Fade out effect as time runs out
var timeLeft = self.lifespan - (Date.now() - self.spawnTime);
if (timeLeft < 500) {
var fadeRatio = timeLeft / 500;
targetGraphics.alpha = Math.max(0.3, fadeRatio);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2E3440
});
/****
* Game Code
****/
// Add background
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Game variables
var targets = [];
var spawnTimer = 0;
var baseSpawnRate = 120; // Spawn every 2 seconds at 60fps
var minSpawnRate = 30; // Minimum spawn interval (0.5 seconds)
var spawnRateDecrease = 2; // How much to decrease spawn rate over time
// Get high score from storage
var highScore = storage.highScore || 0;
// Score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Position score text slightly down from top
scoreTxt.y = 50;
// High score display
var highScoreTxt = new Text2('Best: ' + highScore, {
size: 80,
fill: 0xFFD700
});
highScoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(highScoreTxt);
highScoreTxt.x = -20;
highScoreTxt.y = 50;
// Instructions text
var instructionTxt = new Text2('Tap the circles before they disappear!', {
size: 60,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 0.5);
instructionTxt.x = 2048 / 2;
instructionTxt.y = 2732 - 200;
game.addChild(instructionTxt);
// Fade out instructions after a few seconds
LK.setTimeout(function () {
tween(instructionTxt, {
alpha: 0
}, {
duration: 1000
});
}, 3000);
function spawnTarget() {
// Only spawn if no targets exist (one at a time)
if (targets.length > 0) return;
var target = new Target();
// Random position within safe bounds
var margin = 100;
target.x = margin + Math.random() * (2048 - 2 * margin);
target.y = margin + Math.random() * (2732 - 2 * margin);
targets.push(target);
game.addChild(target);
}
// Spawn the first target
spawnTarget();
game.update = function () {
// Update score display
scoreTxt.setText(LK.getScore());
// Check and update high score
var currentScore = LK.getScore();
if (currentScore > highScore) {
highScore = currentScore;
storage.highScore = highScore;
highScoreTxt.setText('Best: ' + highScore);
}
};