/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Energy Bar var EnergyBar = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('energyBarBG', { anchorX: 0, anchorY: 0.5 }); var fg = self.attachAsset('energyBarFG', { anchorX: 0, anchorY: 0.5, x: 5, y: 0 }); self.fg = fg; self.set = function (percent) { if (percent < 0) percent = 0; if (percent > 1) percent = 1; fg.scaleX = percent; }; return self; }); // Rest Button var RestButton = Container.expand(function () { var self = Container.call(this); var btn = self.attachAsset('restBtn', { anchorX: 0.5, anchorY: 0.5 }); var txt = new Text2('REST', { size: 50, fill: "#fff" }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = 0; self.addChild(txt); return self; }); // Upgrade Button var UpgradeButton = Container.expand(function () { var self = Container.call(this); var btn = self.attachAsset('upgradeBtn', { anchorX: 0.5, anchorY: 0.5 }); var txt = new Text2('UPGRADE', { size: 50, fill: "#fff" }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = 0; self.addChild(txt); return self; }); // Video Button (Tap to create video) var VideoButton = Container.expand(function () { var self = Container.call(this); var btn = self.attachAsset('videoBtn', { anchorX: 0.5, anchorY: 0.5 }); // Text label var txt = new Text2('CREATE VIDEO', { size: 70, fill: "#fff" }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = 0; self.addChild(txt); // Animate on tap self.flash = function () { tween(self, { scaleX: 1.1, scaleY: 1.1 }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 80, easing: tween.easeIn }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181818 }); /**** * Game Code ****/ // --- GAME CONSTANTS --- // Video Button (big tap area) // Energy Bar BG // Energy Bar FG // Upgrade Button // Rest Button // Subscriber Icon // Timer Icon var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; var SUB_GOAL = 10000; // Win at 10,000 subscribers var GAME_TIME = 60; // seconds // --- GAME STATE --- var subscribers = 0; var views = 0; var score = 0; // New: score variable var energy = 1; // 0-1 var maxEnergy = 1; var energyPerTap = 0.08; var energyRegen = 0.12; // per rest tap var videoBaseSubs = 10; var videoBaseViews = 100; var upgradeLevel = 1; var upgradeCost = 100; var upgradeSubsBonus = 1.5; var upgradeViewsBonus = 1.5; var timeLeft = GAME_TIME; var isResting = false; var lastTick = 0; // --- UI ELEMENTS --- // Score display var scoreTxt = new Text2('Score: 0', { size: 90, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); scoreTxt.x = GAME_WIDTH / 2; scoreTxt.y = 40; // Subscribers display var subIcon = LK.getAsset('subIcon', { anchorX: 0, anchorY: 0.5, x: 120, y: 120 }); var subTxt = new Text2('0', { size: 90, fill: "#fff" }); subTxt.anchor.set(0, 0.5); subTxt.x = 220; subTxt.y = 120; // Timer display var timerIcon = LK.getAsset('timerIcon', { anchorX: 0, anchorY: 0.5, x: 120, y: 250 }); var timerTxt = new Text2('60', { size: 90, fill: "#fff" }); timerTxt.anchor.set(0, 0.5); timerTxt.x = 220; timerTxt.y = 250; // Energy bar var energyBar = new EnergyBar(); energyBar.x = (GAME_WIDTH - 600) / 2; energyBar.y = 400; // Video Button var videoBtn = new VideoButton(); videoBtn.x = GAME_WIDTH / 2; videoBtn.y = 800; // Upgrade Button var upgradeBtn = new UpgradeButton(); upgradeBtn.x = GAME_WIDTH / 2 + 350; upgradeBtn.y = 1200; // Rest Button var restBtn = new RestButton(); restBtn.x = GAME_WIDTH / 2 - 350; restBtn.y = 1200; // Upgrade cost text var upgradeCostTxt = new Text2('Cost: 100 views', { size: 40, fill: "#222" }); upgradeCostTxt.anchor.set(0.5, 0); upgradeCostTxt.x = upgradeBtn.x; upgradeCostTxt.y = upgradeBtn.y + 90; // Views display var viewsTxt = new Text2('Views: 0', { size: 60, fill: "#fff" }); viewsTxt.anchor.set(0.5, 0); viewsTxt.x = GAME_WIDTH / 2; viewsTxt.y = 600; // --- ADD TO GAME --- // Add background first so it's behind everything var bg = LK.getAsset('bg', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.addChild(bg); game.addChild(scoreTxt); game.addChild(subIcon); game.addChild(subTxt); game.addChild(timerIcon); game.addChild(timerTxt); game.addChild(energyBar); game.addChild(videoBtn); game.addChild(upgradeBtn); game.addChild(restBtn); game.addChild(upgradeCostTxt); game.addChild(viewsTxt); // --- GUI (for win/lose overlays, not used for main UI) --- // --- GAME LOGIC --- // Update all UI function updateUI() { scoreTxt.setText('Score: ' + score); subTxt.setText(subscribers + ''); timerTxt.setText(Math.ceil(timeLeft) + ''); energyBar.set(energy); viewsTxt.setText('Views: ' + views); upgradeCostTxt.setText('Cost: ' + upgradeCost + ' views'); } // Handle video creation tap videoBtn.down = function (x, y, obj) { if (energy < energyPerTap || isResting) return; // Animate videoBtn.flash(); // Calculate gain var subGain = Math.floor(videoBaseSubs * Math.pow(upgradeSubsBonus, upgradeLevel - 1)); var viewGain = Math.floor(videoBaseViews * Math.pow(upgradeViewsBonus, upgradeLevel - 1)); subscribers += subGain; views += viewGain; score += subGain; // Increase score by gained subscribers energy -= energyPerTap; if (energy < 0) energy = 0; // Win check if (subscribers >= SUB_GOAL) { // Set score for end screen using LK.setScore, which LK will use for overlays LK.setScore(score); LK.showYouWin(); return; } updateUI(); }; // Handle upgrade tap upgradeBtn.down = function (x, y, obj) { if (views >= upgradeCost) { views -= upgradeCost; upgradeLevel += 1; upgradeCost = Math.floor(upgradeCost * 2.2); updateUI(); // Animate tween(upgradeBtn, { scaleX: 1.12, scaleY: 1.12 }, { duration: 90, onFinish: function onFinish() { tween(upgradeBtn, { scaleX: 1, scaleY: 1 }, { duration: 90 }); } }); } }; // Handle rest tap restBtn.down = function (x, y, obj) { if (energy >= 1) return; isResting = true; // Animate tween(restBtn, { scaleX: 1.12, scaleY: 1.12 }, { duration: 90, onFinish: function onFinish() { tween(restBtn, { scaleX: 1, scaleY: 1 }, { duration: 90 }); } }); // Regen energy energy += energyRegen; if (energy > 1) energy = 1; updateUI(); // Resting disables video tap for a short time LK.setTimeout(function () { isResting = false; }, 300); }; // --- GAME TIMER --- game.update = function () { // Timer if (timeLeft > 0) { var now = LK.ticks / 60; if (lastTick === 0) lastTick = now; var dt = now - lastTick; lastTick = now; timeLeft -= dt; if (timeLeft <= 0) { timeLeft = 0; // Lose // Set score for end screen using LK.setScore, which LK will use for overlays LK.setScore(score); LK.showGameOver(); return; } } updateUI(); }; // --- INITIALIZE UI --- updateUI();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Energy Bar
var EnergyBar = Container.expand(function () {
var self = Container.call(this);
var bg = self.attachAsset('energyBarBG', {
anchorX: 0,
anchorY: 0.5
});
var fg = self.attachAsset('energyBarFG', {
anchorX: 0,
anchorY: 0.5,
x: 5,
y: 0
});
self.fg = fg;
self.set = function (percent) {
if (percent < 0) percent = 0;
if (percent > 1) percent = 1;
fg.scaleX = percent;
};
return self;
});
// Rest Button
var RestButton = Container.expand(function () {
var self = Container.call(this);
var btn = self.attachAsset('restBtn', {
anchorX: 0.5,
anchorY: 0.5
});
var txt = new Text2('REST', {
size: 50,
fill: "#fff"
});
txt.anchor.set(0.5, 0.5);
txt.x = 0;
txt.y = 0;
self.addChild(txt);
return self;
});
// Upgrade Button
var UpgradeButton = Container.expand(function () {
var self = Container.call(this);
var btn = self.attachAsset('upgradeBtn', {
anchorX: 0.5,
anchorY: 0.5
});
var txt = new Text2('UPGRADE', {
size: 50,
fill: "#fff"
});
txt.anchor.set(0.5, 0.5);
txt.x = 0;
txt.y = 0;
self.addChild(txt);
return self;
});
// Video Button (Tap to create video)
var VideoButton = Container.expand(function () {
var self = Container.call(this);
var btn = self.attachAsset('videoBtn', {
anchorX: 0.5,
anchorY: 0.5
});
// Text label
var txt = new Text2('CREATE VIDEO', {
size: 70,
fill: "#fff"
});
txt.anchor.set(0.5, 0.5);
txt.x = 0;
txt.y = 0;
self.addChild(txt);
// Animate on tap
self.flash = function () {
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 80,
easing: tween.easeIn
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// --- GAME CONSTANTS ---
// Video Button (big tap area)
// Energy Bar BG
// Energy Bar FG
// Upgrade Button
// Rest Button
// Subscriber Icon
// Timer Icon
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
var SUB_GOAL = 10000; // Win at 10,000 subscribers
var GAME_TIME = 60; // seconds
// --- GAME STATE ---
var subscribers = 0;
var views = 0;
var score = 0; // New: score variable
var energy = 1; // 0-1
var maxEnergy = 1;
var energyPerTap = 0.08;
var energyRegen = 0.12; // per rest tap
var videoBaseSubs = 10;
var videoBaseViews = 100;
var upgradeLevel = 1;
var upgradeCost = 100;
var upgradeSubsBonus = 1.5;
var upgradeViewsBonus = 1.5;
var timeLeft = GAME_TIME;
var isResting = false;
var lastTick = 0;
// --- UI ELEMENTS ---
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 90,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.x = GAME_WIDTH / 2;
scoreTxt.y = 40;
// Subscribers display
var subIcon = LK.getAsset('subIcon', {
anchorX: 0,
anchorY: 0.5,
x: 120,
y: 120
});
var subTxt = new Text2('0', {
size: 90,
fill: "#fff"
});
subTxt.anchor.set(0, 0.5);
subTxt.x = 220;
subTxt.y = 120;
// Timer display
var timerIcon = LK.getAsset('timerIcon', {
anchorX: 0,
anchorY: 0.5,
x: 120,
y: 250
});
var timerTxt = new Text2('60', {
size: 90,
fill: "#fff"
});
timerTxt.anchor.set(0, 0.5);
timerTxt.x = 220;
timerTxt.y = 250;
// Energy bar
var energyBar = new EnergyBar();
energyBar.x = (GAME_WIDTH - 600) / 2;
energyBar.y = 400;
// Video Button
var videoBtn = new VideoButton();
videoBtn.x = GAME_WIDTH / 2;
videoBtn.y = 800;
// Upgrade Button
var upgradeBtn = new UpgradeButton();
upgradeBtn.x = GAME_WIDTH / 2 + 350;
upgradeBtn.y = 1200;
// Rest Button
var restBtn = new RestButton();
restBtn.x = GAME_WIDTH / 2 - 350;
restBtn.y = 1200;
// Upgrade cost text
var upgradeCostTxt = new Text2('Cost: 100 views', {
size: 40,
fill: "#222"
});
upgradeCostTxt.anchor.set(0.5, 0);
upgradeCostTxt.x = upgradeBtn.x;
upgradeCostTxt.y = upgradeBtn.y + 90;
// Views display
var viewsTxt = new Text2('Views: 0', {
size: 60,
fill: "#fff"
});
viewsTxt.anchor.set(0.5, 0);
viewsTxt.x = GAME_WIDTH / 2;
viewsTxt.y = 600;
// --- ADD TO GAME ---
// Add background first so it's behind everything
var bg = LK.getAsset('bg', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(bg);
game.addChild(scoreTxt);
game.addChild(subIcon);
game.addChild(subTxt);
game.addChild(timerIcon);
game.addChild(timerTxt);
game.addChild(energyBar);
game.addChild(videoBtn);
game.addChild(upgradeBtn);
game.addChild(restBtn);
game.addChild(upgradeCostTxt);
game.addChild(viewsTxt);
// --- GUI (for win/lose overlays, not used for main UI) ---
// --- GAME LOGIC ---
// Update all UI
function updateUI() {
scoreTxt.setText('Score: ' + score);
subTxt.setText(subscribers + '');
timerTxt.setText(Math.ceil(timeLeft) + '');
energyBar.set(energy);
viewsTxt.setText('Views: ' + views);
upgradeCostTxt.setText('Cost: ' + upgradeCost + ' views');
}
// Handle video creation tap
videoBtn.down = function (x, y, obj) {
if (energy < energyPerTap || isResting) return;
// Animate
videoBtn.flash();
// Calculate gain
var subGain = Math.floor(videoBaseSubs * Math.pow(upgradeSubsBonus, upgradeLevel - 1));
var viewGain = Math.floor(videoBaseViews * Math.pow(upgradeViewsBonus, upgradeLevel - 1));
subscribers += subGain;
views += viewGain;
score += subGain; // Increase score by gained subscribers
energy -= energyPerTap;
if (energy < 0) energy = 0;
// Win check
if (subscribers >= SUB_GOAL) {
// Set score for end screen using LK.setScore, which LK will use for overlays
LK.setScore(score);
LK.showYouWin();
return;
}
updateUI();
};
// Handle upgrade tap
upgradeBtn.down = function (x, y, obj) {
if (views >= upgradeCost) {
views -= upgradeCost;
upgradeLevel += 1;
upgradeCost = Math.floor(upgradeCost * 2.2);
updateUI();
// Animate
tween(upgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 90,
onFinish: function onFinish() {
tween(upgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 90
});
}
});
}
};
// Handle rest tap
restBtn.down = function (x, y, obj) {
if (energy >= 1) return;
isResting = true;
// Animate
tween(restBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 90,
onFinish: function onFinish() {
tween(restBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 90
});
}
});
// Regen energy
energy += energyRegen;
if (energy > 1) energy = 1;
updateUI();
// Resting disables video tap for a short time
LK.setTimeout(function () {
isResting = false;
}, 300);
};
// --- GAME TIMER ---
game.update = function () {
// Timer
if (timeLeft > 0) {
var now = LK.ticks / 60;
if (lastTick === 0) lastTick = now;
var dt = now - lastTick;
lastTick = now;
timeLeft -= dt;
if (timeLeft <= 0) {
timeLeft = 0;
// Lose
// Set score for end screen using LK.setScore, which LK will use for overlays
LK.setScore(score);
LK.showGameOver();
return;
}
}
updateUI();
};
// --- INITIALIZE UI ---
updateUI();