/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Rod = Container.expand(function () { var self = Container.call(this); var rodGraphics = self.attachAsset('rod', { anchorX: 0, anchorY: 0.5 }); self.rotationSpeed = 0.015; self.update = function () { self.rotation += self.rotationSpeed; }; return self; }); var TargetZone = Container.expand(function () { var self = Container.call(this); var zoneGraphics = self.attachAsset('targetZone', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ var centerX = 2048 / 2; var centerY = 2732 / 2; var targetAngle = Math.PI / 2; // Target at 90 degrees (top) var angleThreshold = 0.25; // Tolerance for hitting target (increased for easier gameplay) var gameActive = true; var lastHitState = false; // Create pivot point var pivot = LK.getAsset('pivot', { anchorX: 0.5, anchorY: 0.5, x: centerX, y: centerY }); game.addChild(pivot); // Create spinning rod var rod = new Rod(); rod.x = centerX; rod.y = centerY; game.addChild(rod); // Create target zone var targetZone = new TargetZone(); targetZone.x = centerX; targetZone.y = centerY - 200; game.addChild(targetZone); // Create score display var scoreTxt = new Text2('0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create instructions var instructionTxt = new Text2('TAP WHEN ROD HITS GREEN ZONE', { size: 60, fill: 0x27AE60 }); instructionTxt.anchor.set(0.5, 1); instructionTxt.y = -50; LK.gui.bottom.addChild(instructionTxt); function normalizeAngle(angle) { while (angle < 0) angle += Math.PI * 2; while (angle >= Math.PI * 2) angle -= Math.PI * 2; return angle; } function isInTargetZone() { var currentAngle = normalizeAngle(rod.rotation); var targetAngleNorm = normalizeAngle(targetAngle); var diff = Math.abs(currentAngle - targetAngleNorm); if (diff > Math.PI) { diff = Math.PI * 2 - diff; } return diff <= angleThreshold; } function handleHit() { if (!gameActive) return; if (isInTargetZone()) { // Successful hit LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Increase speed slightly rod.rotationSpeed += 0.002; // Visual feedback LK.effects.flashObject(targetZone, 0x00ff00, 300); // Play hit sound LK.getSound('hit').play(); lastHitState = true; } else { // Miss - game over gameActive = false; // Visual feedback LK.effects.flashScreen(0xff0000, 1000); // Play miss sound LK.getSound('miss').play(); // Show game over LK.showGameOver(); } } game.down = function (x, y, obj) { if (gameActive) { handleHit(); } }; game.update = function () { if (!gameActive) return; // Update target zone color based on rod position var inZone = isInTargetZone(); if (inZone && !lastHitState) { targetZone.alpha = 1.0; } else if (!inZone) { targetZone.alpha = 0.7; lastHitState = false; } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Rod = Container.expand(function () {
var self = Container.call(this);
var rodGraphics = self.attachAsset('rod', {
anchorX: 0,
anchorY: 0.5
});
self.rotationSpeed = 0.015;
self.update = function () {
self.rotation += self.rotationSpeed;
};
return self;
});
var TargetZone = Container.expand(function () {
var self = Container.call(this);
var zoneGraphics = self.attachAsset('targetZone', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var centerX = 2048 / 2;
var centerY = 2732 / 2;
var targetAngle = Math.PI / 2; // Target at 90 degrees (top)
var angleThreshold = 0.25; // Tolerance for hitting target (increased for easier gameplay)
var gameActive = true;
var lastHitState = false;
// Create pivot point
var pivot = LK.getAsset('pivot', {
anchorX: 0.5,
anchorY: 0.5,
x: centerX,
y: centerY
});
game.addChild(pivot);
// Create spinning rod
var rod = new Rod();
rod.x = centerX;
rod.y = centerY;
game.addChild(rod);
// Create target zone
var targetZone = new TargetZone();
targetZone.x = centerX;
targetZone.y = centerY - 200;
game.addChild(targetZone);
// Create score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create instructions
var instructionTxt = new Text2('TAP WHEN ROD HITS GREEN ZONE', {
size: 60,
fill: 0x27AE60
});
instructionTxt.anchor.set(0.5, 1);
instructionTxt.y = -50;
LK.gui.bottom.addChild(instructionTxt);
function normalizeAngle(angle) {
while (angle < 0) angle += Math.PI * 2;
while (angle >= Math.PI * 2) angle -= Math.PI * 2;
return angle;
}
function isInTargetZone() {
var currentAngle = normalizeAngle(rod.rotation);
var targetAngleNorm = normalizeAngle(targetAngle);
var diff = Math.abs(currentAngle - targetAngleNorm);
if (diff > Math.PI) {
diff = Math.PI * 2 - diff;
}
return diff <= angleThreshold;
}
function handleHit() {
if (!gameActive) return;
if (isInTargetZone()) {
// Successful hit
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Increase speed slightly
rod.rotationSpeed += 0.002;
// Visual feedback
LK.effects.flashObject(targetZone, 0x00ff00, 300);
// Play hit sound
LK.getSound('hit').play();
lastHitState = true;
} else {
// Miss - game over
gameActive = false;
// Visual feedback
LK.effects.flashScreen(0xff0000, 1000);
// Play miss sound
LK.getSound('miss').play();
// Show game over
LK.showGameOver();
}
}
game.down = function (x, y, obj) {
if (gameActive) {
handleHit();
}
};
game.update = function () {
if (!gameActive) return;
// Update target zone color based on rod position
var inZone = isInTargetZone();
if (inZone && !lastHitState) {
targetZone.alpha = 1.0;
} else if (!inZone) {
targetZone.alpha = 0.7;
lastHitState = false;
}
};