/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Orb = Container.expand(function () {
var self = Container.call(this);
// Create and attach the orb asset
var orbGraphics = self.attachAsset('orb', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize variables for animation and state
self.originalScale = 1;
self.isAnimating = false;
// Handle tap/click on the orb
self.down = function (x, y, obj) {
if (self.isAnimating) {
return;
}
// Play tap sound
LK.getSound('tap').play();
// Increment score with upgrade multiplier
LK.setScore(LK.getScore() + shop.upgradeIncrement);
// Update score display
scoreTxt.setText(Math.floor(LK.getScore()));
// Animate the orb (shrink and grow)
self.isAnimating = true;
tween(orbGraphics, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 25,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(orbGraphics, {
scaleX: self.originalScale,
scaleY: self.originalScale
}, {
duration: 50,
easing: tween.elasticOut,
onFinish: function onFinish() {
self.isAnimating = false;
}
});
}
});
};
return self;
});
var Rebirth = Container.expand(function () {
var self = Container.call(this);
self.rebirthCost = 1000;
self.rebirthLevel = 0;
var rebirthText = new Text2('Rebirth: ' + self.rebirthCost + ' points', {
size: 60,
fill: 0xFFFFFF
});
rebirthText.anchor.set(0.5, 0);
rebirthText.y = 700;
self.addChild(rebirthText);
self.down = function (x, y, obj) {
if (LK.getScore() >= self.rebirthCost) {
LK.setScore(0);
self.rebirthLevel++;
shop.upgradeIncrement *= 2; // Double the upgrade increment
self.rebirthCost *= 4;
rebirthText.setText('Rebirth: ' + Math.floor(self.rebirthCost) + ' points');
scoreTxt.setText(LK.getScore());
}
};
return self;
});
var Shop = Container.expand(function () {
var self = Container.call(this);
self.upgradeCost = 10;
self.upgradeLevel = 1;
self.upgradeIncrement = 1;
var shopText = new Text2('Upgrade: ' + self.upgradeCost + ' points', {
size: 60,
fill: 0xFFFFFF
});
shopText.anchor.set(0.5, 0);
shopText.y = 500;
self.addChild(shopText);
self.down = function (x, y, obj) {
if (LK.getScore() >= self.upgradeCost) {
LK.setScore(LK.getScore() - self.upgradeCost);
self.upgradeLevel++;
if (self.upgradeLevel % 3 === 0) {
self.upgradeIncrement *= 2; // Double the increment every third upgrade
} else if (self.upgradeLevel % 2 === 0) {
self.upgradeIncrement += 2; // Increase increment by 2 every second upgrade
} else {
self.upgradeIncrement++;
}
self.upgradeCost *= 4;
shopText.setText('Upgrade: ' + Math.floor(self.upgradeCost) + ' points');
scoreTxt.setText(LK.getScore());
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Set the background color to black for the minimalist aesthetic
game.setBackgroundColor(0x000000);
// Set up score display
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.setText('0');
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create high score display
var highScoreTxt = new Text2('High Score: 0', {
size: 60,
fill: 0xAAAAAA
});
highScoreTxt.setText('High Score: ' + storage.highScore);
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.y = 170;
LK.gui.top.addChild(highScoreTxt);
// Create tap instruction text
var instructionTxt = new Text2('Tap the orb as fast as you can!', {
size: 80,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.y = 350;
LK.gui.top.addChild(instructionTxt);
// Create and position the orb in the center of the screen
var orb = new Orb();
orb.x = 2048 / 2;
orb.y = 2732 / 2;
game.addChild(orb);
// Create and position the shop below the orb
var shop = new Shop();
shop.x = 2048 / 2;
shop.y = 2732 / 2 + 300;
game.addChild(shop);
// Create and position the rebirth below the shop
var rebirth = new Rebirth();
rebirth.x = 2048 / 2;
rebirth.y = 2732 / 2 + 500;
game.addChild(rebirth);
// Timer variables
var gameStarted = false;
var gameTimer = null;
// Function to start the game
function startGame() {
// Reset score
LK.setScore(0);
scoreTxt.setText('0');
// Hide instruction
instructionTxt.alpha = 0;
// Start game timer
gameStarted = true;
if (gameTimer) {
LK.clearInterval(gameTimer);
}
// Play background music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 0.5,
duration: 1000
}
});
}
// Function to end the game
function endGame() {
gameStarted = false;
LK.clearInterval(gameTimer);
// Update high score if needed
if (LK.getScore() > storage.highScore) {
storage.highScore = LK.getScore();
highScoreTxt.setText('High Score: ' + Math.floor(storage.highScore));
// Animate the high score text
tween(highScoreTxt, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(highScoreTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.elasticOut
});
}
});
}
// Fade out music
LK.playMusic('bgmusic', {
fade: {
start: 0.5,
end: 0,
duration: 800
}
});
// Show game over
LK.showGameOver();
}
// Check if the game should start when the player taps anywhere
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
}
};
// Update function called every frame
game.update = function () {
// Add visual feedback - subtle pulsing of the orb when not tapped
if (!orb.isAnimating && gameStarted) {
var pulseScale = 1 + 0.05 * Math.sin(LK.ticks / 20);
orb.scale.set(pulseScale);
}
};
// Start with the instruction visible
instructionTxt.alpha = 1; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Orb = Container.expand(function () {
var self = Container.call(this);
// Create and attach the orb asset
var orbGraphics = self.attachAsset('orb', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize variables for animation and state
self.originalScale = 1;
self.isAnimating = false;
// Handle tap/click on the orb
self.down = function (x, y, obj) {
if (self.isAnimating) {
return;
}
// Play tap sound
LK.getSound('tap').play();
// Increment score with upgrade multiplier
LK.setScore(LK.getScore() + shop.upgradeIncrement);
// Update score display
scoreTxt.setText(Math.floor(LK.getScore()));
// Animate the orb (shrink and grow)
self.isAnimating = true;
tween(orbGraphics, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 25,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(orbGraphics, {
scaleX: self.originalScale,
scaleY: self.originalScale
}, {
duration: 50,
easing: tween.elasticOut,
onFinish: function onFinish() {
self.isAnimating = false;
}
});
}
});
};
return self;
});
var Rebirth = Container.expand(function () {
var self = Container.call(this);
self.rebirthCost = 1000;
self.rebirthLevel = 0;
var rebirthText = new Text2('Rebirth: ' + self.rebirthCost + ' points', {
size: 60,
fill: 0xFFFFFF
});
rebirthText.anchor.set(0.5, 0);
rebirthText.y = 700;
self.addChild(rebirthText);
self.down = function (x, y, obj) {
if (LK.getScore() >= self.rebirthCost) {
LK.setScore(0);
self.rebirthLevel++;
shop.upgradeIncrement *= 2; // Double the upgrade increment
self.rebirthCost *= 4;
rebirthText.setText('Rebirth: ' + Math.floor(self.rebirthCost) + ' points');
scoreTxt.setText(LK.getScore());
}
};
return self;
});
var Shop = Container.expand(function () {
var self = Container.call(this);
self.upgradeCost = 10;
self.upgradeLevel = 1;
self.upgradeIncrement = 1;
var shopText = new Text2('Upgrade: ' + self.upgradeCost + ' points', {
size: 60,
fill: 0xFFFFFF
});
shopText.anchor.set(0.5, 0);
shopText.y = 500;
self.addChild(shopText);
self.down = function (x, y, obj) {
if (LK.getScore() >= self.upgradeCost) {
LK.setScore(LK.getScore() - self.upgradeCost);
self.upgradeLevel++;
if (self.upgradeLevel % 3 === 0) {
self.upgradeIncrement *= 2; // Double the increment every third upgrade
} else if (self.upgradeLevel % 2 === 0) {
self.upgradeIncrement += 2; // Increase increment by 2 every second upgrade
} else {
self.upgradeIncrement++;
}
self.upgradeCost *= 4;
shopText.setText('Upgrade: ' + Math.floor(self.upgradeCost) + ' points');
scoreTxt.setText(LK.getScore());
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Set the background color to black for the minimalist aesthetic
game.setBackgroundColor(0x000000);
// Set up score display
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.setText('0');
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create high score display
var highScoreTxt = new Text2('High Score: 0', {
size: 60,
fill: 0xAAAAAA
});
highScoreTxt.setText('High Score: ' + storage.highScore);
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.y = 170;
LK.gui.top.addChild(highScoreTxt);
// Create tap instruction text
var instructionTxt = new Text2('Tap the orb as fast as you can!', {
size: 80,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.y = 350;
LK.gui.top.addChild(instructionTxt);
// Create and position the orb in the center of the screen
var orb = new Orb();
orb.x = 2048 / 2;
orb.y = 2732 / 2;
game.addChild(orb);
// Create and position the shop below the orb
var shop = new Shop();
shop.x = 2048 / 2;
shop.y = 2732 / 2 + 300;
game.addChild(shop);
// Create and position the rebirth below the shop
var rebirth = new Rebirth();
rebirth.x = 2048 / 2;
rebirth.y = 2732 / 2 + 500;
game.addChild(rebirth);
// Timer variables
var gameStarted = false;
var gameTimer = null;
// Function to start the game
function startGame() {
// Reset score
LK.setScore(0);
scoreTxt.setText('0');
// Hide instruction
instructionTxt.alpha = 0;
// Start game timer
gameStarted = true;
if (gameTimer) {
LK.clearInterval(gameTimer);
}
// Play background music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 0.5,
duration: 1000
}
});
}
// Function to end the game
function endGame() {
gameStarted = false;
LK.clearInterval(gameTimer);
// Update high score if needed
if (LK.getScore() > storage.highScore) {
storage.highScore = LK.getScore();
highScoreTxt.setText('High Score: ' + Math.floor(storage.highScore));
// Animate the high score text
tween(highScoreTxt, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(highScoreTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.elasticOut
});
}
});
}
// Fade out music
LK.playMusic('bgmusic', {
fade: {
start: 0.5,
end: 0,
duration: 800
}
});
// Show game over
LK.showGameOver();
}
// Check if the game should start when the player taps anywhere
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
}
};
// Update function called every frame
game.update = function () {
// Add visual feedback - subtle pulsing of the orb when not tapped
if (!orb.isAnimating && gameStarted) {
var pulseScale = 1 + 0.05 * Math.sin(LK.ticks / 20);
orb.scale.set(pulseScale);
}
};
// Start with the instruction visible
instructionTxt.alpha = 1;