User prompt
Please fix the bug: 'Uncaught TypeError: LK.setGameOverScore is not a function' in or related to this line: 'LK.setGameOverScore(score);' Line Number: 276
User prompt
The score should be displayed on the losing or winning screen at the end of the game.
User prompt
Score should be displayed at the end of the game
User prompt
add score
User prompt
add background asset
User prompt
Let it be the background of the game asset
User prompt
Let it be the background of the game
User prompt
choose video type
User prompt
Let's have a better game
Code edit (1 edits merged)
Please save this source code
User prompt
YouTuber Simulator: Viral Star
Initial prompt
YouTuber Simulator game
/****
* 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: 0x000000
});
/****
* Game Code
****/
// Add a black background asset to visually cover the game background
var bgAsset = LK.getAsset('energyBarBG', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
scaleX: GAME_WIDTH / 600,
scaleY: GAME_HEIGHT / 60
});
game.addChild(bgAsset);
// --- 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 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 ---
// 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 ---
// Move background asset to back (if not already at index 0)
if (game.children[0] !== bgAsset) {
game.removeChild(bgAsset);
game.addChildAt(bgAsset, 0);
}
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() {
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;
energy -= energyPerTap;
if (energy < 0) energy = 0;
// Win check
if (subscribers >= SUB_GOAL) {
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
LK.showGameOver();
return;
}
}
updateUI();
};
// --- INITIALIZE UI ---
updateUI(); ===================================================================
--- original.js
+++ change.js
@@ -108,8 +108,18 @@
/****
* Game Code
****/
+// Add a black background asset to visually cover the game background
+var bgAsset = LK.getAsset('energyBarBG', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0,
+ scaleX: GAME_WIDTH / 600,
+ scaleY: GAME_HEIGHT / 60
+});
+game.addChild(bgAsset);
// --- GAME CONSTANTS ---
// Video Button (big tap area)
// Energy Bar BG
// Energy Bar FG
@@ -198,8 +208,13 @@
viewsTxt.anchor.set(0.5, 0);
viewsTxt.x = GAME_WIDTH / 2;
viewsTxt.y = 600;
// --- ADD TO GAME ---
+// Move background asset to back (if not already at index 0)
+if (game.children[0] !== bgAsset) {
+ game.removeChild(bgAsset);
+ game.addChildAt(bgAsset, 0);
+}
game.addChild(subIcon);
game.addChild(subTxt);
game.addChild(timerIcon);
game.addChild(timerTxt);