/**** * Classes ****/ // Assets will be automatically created based on usage in the code. // RedDot class for the target dots var RedDot = Container.expand(function () { var self = Container.call(this); var dotGraphics = self.attachAsset('redDot', { anchorX: 0.5, anchorY: 0.5, width: 100, height: 100, color: 0xff0000, shape: 'ellipse' }); self.isHit = false; self.on('down', function () { if (!self.isHit) { self.isHit = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); self.destroy(); } }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); LK.gui.top.addChild(scoreTxt); var redDots = []; function spawnRedDot() { var newRedDot = new RedDot(); // Random position within the game area, accounting for dot size to avoid clipping newRedDot.x = Math.random() * (2048 - 100) + 50; // 50 to 1998 newRedDot.y = Math.random() * (2732 - 100) + 50; // 50 to 2682 redDots.push(newRedDot); game.addChild(newRedDot); } // Spawn a red dot every 5 seconds var spawnTimer = LK.setInterval(spawnRedDot, 5000); LK.on('tick', function () { // Update game elements if needed }); // Reset game state on game over LK.on('gameOver', function () { // Clear all red dots redDots.forEach(function (dot) { dot.destroy(); }); redDots = []; // Reset score LK.setScore(0); scoreTxt.setText(LK.getScore()); // Restart the spawn timer LK.clearInterval(spawnTimer); spawnTimer = LK.setInterval(spawnRedDot, 5000); });
/****
* Classes
****/
// Assets will be automatically created based on usage in the code.
// RedDot class for the target dots
var RedDot = Container.expand(function () {
var self = Container.call(this);
var dotGraphics = self.attachAsset('redDot', {
anchorX: 0.5,
anchorY: 0.5,
width: 100,
height: 100,
color: 0xff0000,
shape: 'ellipse'
});
self.isHit = false;
self.on('down', function () {
if (!self.isHit) {
self.isHit = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
self.destroy();
}
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
var redDots = [];
function spawnRedDot() {
var newRedDot = new RedDot();
// Random position within the game area, accounting for dot size to avoid clipping
newRedDot.x = Math.random() * (2048 - 100) + 50; // 50 to 1998
newRedDot.y = Math.random() * (2732 - 100) + 50; // 50 to 2682
redDots.push(newRedDot);
game.addChild(newRedDot);
}
// Spawn a red dot every 5 seconds
var spawnTimer = LK.setInterval(spawnRedDot, 5000);
LK.on('tick', function () {
// Update game elements if needed
});
// Reset game state on game over
LK.on('gameOver', function () {
// Clear all red dots
redDots.forEach(function (dot) {
dot.destroy();
});
redDots = [];
// Reset score
LK.setScore(0);
scoreTxt.setText(LK.getScore());
// Restart the spawn timer
LK.clearInterval(spawnTimer);
spawnTimer = LK.setInterval(spawnRedDot, 5000);
});