/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { money: 0, floors: 1, floorLevels: [1], lastTimestamp: "undefined" }); /**** * Classes ****/ var Cloud = Container.expand(function () { var self = Container.call(this); var cloudGraphic = self.attachAsset('clouds', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7 }); // Randomize cloud appearance self.scaleX = 0.5 + Math.random() * 1.5; self.scaleY = 0.5 + Math.random(); self.alpha = 0.5 + Math.random() * 0.5; // Set random position self.x = Math.random() * 2048; self.y = Math.random() * 1000; // Clouds appear in upper portion of screen // Set random speed self.speed = 0.2 + Math.random() * 0.3; self.update = function () { // Move cloud horizontally self.x += self.speed; // If cloud moves off screen, reset to other side if (self.x > 2048 + 300) { self.x = -300; self.y = Math.random() * 1000; } }; return self; }); var Floor = Container.expand(function (floorNumber, level) { var self = Container.call(this); self.floorNumber = floorNumber; self.level = level || 1; // Calculate position based on floor number (ground floor is 0) self.floorHeight = 350; self.baseY = 2732 - 400; // Base Y position for ground floor // Calculate income based on floor number and level self.calculateIncome = function () { // Higher floors generate more income, multiplied by level var baseIncome = (self.floorNumber + 1) * 2; return baseIncome * self.level; }; // Calculate upgrade cost self.getUpgradeCost = function () { // Costs increase with floor number and current level return Math.floor(25 * (self.floorNumber + 1) * Math.pow(1.5, self.level)); }; // Floor visuals var floorBackground = self.attachAsset('buildingFloor', { anchorX: 0.5, anchorY: 0.5 }); // Core area var floorCore = self.attachAsset('buildingCore', { anchorX: 0.5, anchorY: 0.5, y: -25 }); // Floor number text self.floorText = new Text2('Floor ' + (floorNumber + 1), { size: 80, fill: 0xFFFFFF }); self.floorText.anchor.set(0.5, 0.5); self.floorText.y = -80; self.addChild(self.floorText); // Level text self.levelText = new Text2('Level ' + self.level, { size: 60, fill: 0xFFFF00 }); self.levelText.anchor.set(0.5, 0.5); self.levelText.y = 0; self.addChild(self.levelText); // Income text self.incomeText = new Text2('$' + self.calculateIncome() + '/sec', { size: 50, fill: 0x00FF00 }); self.incomeText.anchor.set(0.5, 0.5); self.incomeText.y = 60; self.addChild(self.incomeText); // Upgrade button self.upgradeButton = self.attachAsset('upgradeButton', { anchorX: 0.5, anchorY: 0.5, x: 600, y: 0 }); // Upgrade cost text self.upgradeCostText = new Text2('$' + self.getUpgradeCost(), { size: 40, fill: 0xFFFFFF }); self.upgradeCostText.anchor.set(0.5, 0.5); self.upgradeButton.addChild(self.upgradeCostText); // Upgrade button event self.upgradeButton.interactive = true; self.upgradeButton.down = function () { if (money >= self.getUpgradeCost()) { money -= self.getUpgradeCost(); self.level++; storage.floorLevels[self.floorNumber] = self.level; // Update UI self.levelText.setText('Level ' + self.level); self.incomeText.setText('$' + self.calculateIncome() + '/sec'); if (self.level < 10) { self.upgradeCostText.setText('$' + self.getUpgradeCost()); } else { self.upgradeCostText.setText('MAX'); } // Play upgrade sound LK.getSound('upgrade').play(); // Visual effect for upgrade tween(self, { scaleX: 1.1, scaleY: 1.1 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); // Update game state updateGameState(); } }; // Update method self.updateUI = function () { self.incomeText.setText('$' + self.calculateIncome() + '/sec'); if (self.level < 10) { self.upgradeCostText.setText('$' + self.getUpgradeCost()); } else { self.upgradeCostText.setText('MAX'); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Function to reset game progress function resetGameProgress() { money = 0; floors = 1; floorLevels = [1]; cameraOffsetY = 0; floorObjects.forEach(function (floor) { return floor.destroy(); }); floorObjects = []; floorContainer.removeChildren(); initializeFloors(); updateBuildButtonCost(); moneyText.setText('$0'); } // Initialize game var restartButton = LK.getAsset('restartButton', { anchorX: 0.5, anchorY: 0.5 }); restartButton.x = 2048 - 150; restartButton.y = 100; game.addChild(restartButton); var restartButtonText = new Text2('RESTART', { size: 60, fill: 0xFFFFFF }); restartButtonText.anchor.set(0.5, 0.5); restartButton.addChild(restartButtonText); restartButton.interactive = true; restartButton.down = function () { resetGameProgress(); }; // Add clouds for background var money = storage.money; var floors = storage.floors; var floorLevels = storage.floorLevels; var lastTimestamp = storage.lastTimestamp; var baseY = 2732 - 400; // Base Y position for ground floor var floorHeight = 350; var cameraOffsetY = 0; var floorContainer = new Container(); var floorObjects = []; var clouds = []; var canScrollUp = false; // UI elements var moneyText = new Text2('$' + money.toFixed(0), { size: 100, fill: 0xFFDD00 }); moneyText.anchor.set(0.5, 0); LK.gui.top.addChild(moneyText); var buildButton = LK.getAsset('buildButton', { anchorX: 0.5, anchorY: 0.5 }); buildButton.x = 2048 / 2; buildButton.y = 2732 - 100; game.addChild(buildButton); var buildButtonText = new Text2('BUILD NEW FLOOR', { size: 60, fill: 0xFFFFFF }); buildButtonText.anchor.set(0.5, 0.5); buildButton.addChild(buildButtonText); var buildCostText = new Text2('', { size: 40, fill: 0xFFFFFF }); buildCostText.anchor.set(0.5, 0.5); buildCostText.y = 50; buildButton.addChild(buildCostText); // Add clouds for background for (var i = 0; i < 10; i++) { var cloud = new Cloud(); clouds.push(cloud); game.addChild(cloud); } // Add floor container to game game.addChild(floorContainer); // Initialize floors from storage function initializeFloors() { for (var i = 0; i < floors; i++) { var floor = new Floor(i, floorLevels[i]); floor.x = 2048 / 2; floor.y = baseY - i * floorHeight + cameraOffsetY; floorObjects.push(floor); floorContainer.addChild(floor); } // Calculate if camera should scroll up updateCameraPosition(); updateBuildButtonCost(); } // Calculate the cost of building a new floor function getNewFloorCost() { return Math.floor(100 * Math.pow(1.8, floors)); } // Update build button cost function updateBuildButtonCost() { var cost = getNewFloorCost(); buildCostText.setText('$' + cost); // Check if all existing floors are at max level var allMaxed = true; for (var i = 0; i < floorLevels.length; i++) { if (floorLevels[i] < 10) { allMaxed = false; break; } } // Disable button if not all floors are maxed if (!allMaxed) { buildButton.alpha = 0.5; buildButtonText.setText('MAX ALL FLOORS FIRST'); } else { buildButton.alpha = 1; buildButtonText.setText('BUILD NEW FLOOR'); } } // Update camera position based on highest floor function updateCameraPosition() { if (floors > 5) { // Calculate how much we need to scroll up var targetOffsetY = (floors - 5) * floorHeight; // Only set to scroll if not already scrolling if (cameraOffsetY !== targetOffsetY) { canScrollUp = true; // Animate the camera movement tween(game, { cameraOffsetY: targetOffsetY }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { canScrollUp = false; updateFloorPositions(); } }); } } } // Update floor positions based on camera offset function updateFloorPositions() { for (var i = 0; i < floorObjects.length; i++) { var floor = floorObjects[i]; tween(floor, { y: baseY - i * floorHeight + cameraOffsetY }, { duration: 800, easing: tween.easeInOut }); } } // Build new floor function buildNewFloor() { // Check if all existing floors are at max level var allMaxed = true; for (var i = 0; i < floorLevels.length; i++) { if (floorLevels[i] < 10) { allMaxed = false; break; } } if (!allMaxed) { return; // Cannot build new floor until all are maxed } var cost = getNewFloorCost(); if (money >= cost) { money -= cost; floors++; floorLevels.push(1); // Create and add new floor var newFloor = new Floor(floors - 1, 1); newFloor.x = 2048 / 2; newFloor.y = baseY - (floors - 1) * floorHeight + cameraOffsetY; // Start with scale effect newFloor.scaleX = 0; newFloor.scaleY = 0; tween(newFloor, { scaleX: 1, scaleY: 1 }, { duration: 500, easing: tween.easeOut }); floorObjects.push(newFloor); floorContainer.addChild(newFloor); // Play building sound LK.getSound('build').play(); // Update camera position updateCameraPosition(); // Update game state updateGameState(); } } // Calculate income per second function calculateTotalIncome() { var totalIncome = 0; for (var i = 0; i < floors; i++) { // Higher floors with higher levels produce more income var baseIncome = (i + 1) * 2; totalIncome += baseIncome * floorLevels[i]; } return totalIncome; } // Update game state in storage function updateGameState() { updateBuildButtonCost(); } // Calculate offline progress function calculateOfflineProgress() {} // Handle build button click buildButton.interactive = true; buildButton.down = function () { buildNewFloor(); }; // Scroll game with touch/mouse var dragStartY = 0; var initialOffsetY = 0; var isDragging = false; game.down = function (x, y) { if (floors > 5) { // Only allow scrolling if there are enough floors isDragging = true; dragStartY = y; initialOffsetY = cameraOffsetY; } }; game.move = function (x, y) { if (isDragging && floors > 5) { var deltaY = dragStartY - y; var newOffsetY = initialOffsetY + deltaY; // Limit scrolling range var maxScroll = (floors - 5) * floorHeight; newOffsetY = Math.max(0, Math.min(maxScroll, newOffsetY)); cameraOffsetY = newOffsetY; updateFloorPositions(); } }; game.up = function () { isDragging = false; }; // Initialize game function initGame() { resetGameProgress(); calculateOfflineProgress(); LK.playMusic('bgMusic'); } // Run initialization initGame(); // Game update loop var lastTickTime = Date.now(); game.update = function () { // Update clouds for (var i = 0; i < clouds.length; i++) { clouds[i].update(); } // Calculate time since last tick for proper income calculation var currentTime = Date.now(); var deltaTime = (currentTime - lastTickTime) / 1000; // Convert to seconds lastTickTime = currentTime; // Add income money += calculateTotalIncome() * deltaTime; // Update money display with formatted number moneyText.setText('$' + Math.floor(money).toLocaleString()); // Flash build button if affordable if (money >= getNewFloorCost()) { if (LK.ticks % 60 < 30) { buildButton.alpha = 1; } else { buildButton.alpha = 0.8; } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
money: 0,
floors: 1,
floorLevels: [1],
lastTimestamp: "undefined"
});
/****
* Classes
****/
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphic = self.attachAsset('clouds', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
// Randomize cloud appearance
self.scaleX = 0.5 + Math.random() * 1.5;
self.scaleY = 0.5 + Math.random();
self.alpha = 0.5 + Math.random() * 0.5;
// Set random position
self.x = Math.random() * 2048;
self.y = Math.random() * 1000; // Clouds appear in upper portion of screen
// Set random speed
self.speed = 0.2 + Math.random() * 0.3;
self.update = function () {
// Move cloud horizontally
self.x += self.speed;
// If cloud moves off screen, reset to other side
if (self.x > 2048 + 300) {
self.x = -300;
self.y = Math.random() * 1000;
}
};
return self;
});
var Floor = Container.expand(function (floorNumber, level) {
var self = Container.call(this);
self.floorNumber = floorNumber;
self.level = level || 1;
// Calculate position based on floor number (ground floor is 0)
self.floorHeight = 350;
self.baseY = 2732 - 400; // Base Y position for ground floor
// Calculate income based on floor number and level
self.calculateIncome = function () {
// Higher floors generate more income, multiplied by level
var baseIncome = (self.floorNumber + 1) * 2;
return baseIncome * self.level;
};
// Calculate upgrade cost
self.getUpgradeCost = function () {
// Costs increase with floor number and current level
return Math.floor(25 * (self.floorNumber + 1) * Math.pow(1.5, self.level));
};
// Floor visuals
var floorBackground = self.attachAsset('buildingFloor', {
anchorX: 0.5,
anchorY: 0.5
});
// Core area
var floorCore = self.attachAsset('buildingCore', {
anchorX: 0.5,
anchorY: 0.5,
y: -25
});
// Floor number text
self.floorText = new Text2('Floor ' + (floorNumber + 1), {
size: 80,
fill: 0xFFFFFF
});
self.floorText.anchor.set(0.5, 0.5);
self.floorText.y = -80;
self.addChild(self.floorText);
// Level text
self.levelText = new Text2('Level ' + self.level, {
size: 60,
fill: 0xFFFF00
});
self.levelText.anchor.set(0.5, 0.5);
self.levelText.y = 0;
self.addChild(self.levelText);
// Income text
self.incomeText = new Text2('$' + self.calculateIncome() + '/sec', {
size: 50,
fill: 0x00FF00
});
self.incomeText.anchor.set(0.5, 0.5);
self.incomeText.y = 60;
self.addChild(self.incomeText);
// Upgrade button
self.upgradeButton = self.attachAsset('upgradeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: 0
});
// Upgrade cost text
self.upgradeCostText = new Text2('$' + self.getUpgradeCost(), {
size: 40,
fill: 0xFFFFFF
});
self.upgradeCostText.anchor.set(0.5, 0.5);
self.upgradeButton.addChild(self.upgradeCostText);
// Upgrade button event
self.upgradeButton.interactive = true;
self.upgradeButton.down = function () {
if (money >= self.getUpgradeCost()) {
money -= self.getUpgradeCost();
self.level++;
storage.floorLevels[self.floorNumber] = self.level;
// Update UI
self.levelText.setText('Level ' + self.level);
self.incomeText.setText('$' + self.calculateIncome() + '/sec');
if (self.level < 10) {
self.upgradeCostText.setText('$' + self.getUpgradeCost());
} else {
self.upgradeCostText.setText('MAX');
}
// Play upgrade sound
LK.getSound('upgrade').play();
// Visual effect for upgrade
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
// Update game state
updateGameState();
}
};
// Update method
self.updateUI = function () {
self.incomeText.setText('$' + self.calculateIncome() + '/sec');
if (self.level < 10) {
self.upgradeCostText.setText('$' + self.getUpgradeCost());
} else {
self.upgradeCostText.setText('MAX');
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Function to reset game progress
function resetGameProgress() {
money = 0;
floors = 1;
floorLevels = [1];
cameraOffsetY = 0;
floorObjects.forEach(function (floor) {
return floor.destroy();
});
floorObjects = [];
floorContainer.removeChildren();
initializeFloors();
updateBuildButtonCost();
moneyText.setText('$0');
}
// Initialize game
var restartButton = LK.getAsset('restartButton', {
anchorX: 0.5,
anchorY: 0.5
});
restartButton.x = 2048 - 150;
restartButton.y = 100;
game.addChild(restartButton);
var restartButtonText = new Text2('RESTART', {
size: 60,
fill: 0xFFFFFF
});
restartButtonText.anchor.set(0.5, 0.5);
restartButton.addChild(restartButtonText);
restartButton.interactive = true;
restartButton.down = function () {
resetGameProgress();
};
// Add clouds for background
var money = storage.money;
var floors = storage.floors;
var floorLevels = storage.floorLevels;
var lastTimestamp = storage.lastTimestamp;
var baseY = 2732 - 400; // Base Y position for ground floor
var floorHeight = 350;
var cameraOffsetY = 0;
var floorContainer = new Container();
var floorObjects = [];
var clouds = [];
var canScrollUp = false;
// UI elements
var moneyText = new Text2('$' + money.toFixed(0), {
size: 100,
fill: 0xFFDD00
});
moneyText.anchor.set(0.5, 0);
LK.gui.top.addChild(moneyText);
var buildButton = LK.getAsset('buildButton', {
anchorX: 0.5,
anchorY: 0.5
});
buildButton.x = 2048 / 2;
buildButton.y = 2732 - 100;
game.addChild(buildButton);
var buildButtonText = new Text2('BUILD NEW FLOOR', {
size: 60,
fill: 0xFFFFFF
});
buildButtonText.anchor.set(0.5, 0.5);
buildButton.addChild(buildButtonText);
var buildCostText = new Text2('', {
size: 40,
fill: 0xFFFFFF
});
buildCostText.anchor.set(0.5, 0.5);
buildCostText.y = 50;
buildButton.addChild(buildCostText);
// Add clouds for background
for (var i = 0; i < 10; i++) {
var cloud = new Cloud();
clouds.push(cloud);
game.addChild(cloud);
}
// Add floor container to game
game.addChild(floorContainer);
// Initialize floors from storage
function initializeFloors() {
for (var i = 0; i < floors; i++) {
var floor = new Floor(i, floorLevels[i]);
floor.x = 2048 / 2;
floor.y = baseY - i * floorHeight + cameraOffsetY;
floorObjects.push(floor);
floorContainer.addChild(floor);
}
// Calculate if camera should scroll up
updateCameraPosition();
updateBuildButtonCost();
}
// Calculate the cost of building a new floor
function getNewFloorCost() {
return Math.floor(100 * Math.pow(1.8, floors));
}
// Update build button cost
function updateBuildButtonCost() {
var cost = getNewFloorCost();
buildCostText.setText('$' + cost);
// Check if all existing floors are at max level
var allMaxed = true;
for (var i = 0; i < floorLevels.length; i++) {
if (floorLevels[i] < 10) {
allMaxed = false;
break;
}
}
// Disable button if not all floors are maxed
if (!allMaxed) {
buildButton.alpha = 0.5;
buildButtonText.setText('MAX ALL FLOORS FIRST');
} else {
buildButton.alpha = 1;
buildButtonText.setText('BUILD NEW FLOOR');
}
}
// Update camera position based on highest floor
function updateCameraPosition() {
if (floors > 5) {
// Calculate how much we need to scroll up
var targetOffsetY = (floors - 5) * floorHeight;
// Only set to scroll if not already scrolling
if (cameraOffsetY !== targetOffsetY) {
canScrollUp = true;
// Animate the camera movement
tween(game, {
cameraOffsetY: targetOffsetY
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
canScrollUp = false;
updateFloorPositions();
}
});
}
}
}
// Update floor positions based on camera offset
function updateFloorPositions() {
for (var i = 0; i < floorObjects.length; i++) {
var floor = floorObjects[i];
tween(floor, {
y: baseY - i * floorHeight + cameraOffsetY
}, {
duration: 800,
easing: tween.easeInOut
});
}
}
// Build new floor
function buildNewFloor() {
// Check if all existing floors are at max level
var allMaxed = true;
for (var i = 0; i < floorLevels.length; i++) {
if (floorLevels[i] < 10) {
allMaxed = false;
break;
}
}
if (!allMaxed) {
return; // Cannot build new floor until all are maxed
}
var cost = getNewFloorCost();
if (money >= cost) {
money -= cost;
floors++;
floorLevels.push(1);
// Create and add new floor
var newFloor = new Floor(floors - 1, 1);
newFloor.x = 2048 / 2;
newFloor.y = baseY - (floors - 1) * floorHeight + cameraOffsetY;
// Start with scale effect
newFloor.scaleX = 0;
newFloor.scaleY = 0;
tween(newFloor, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeOut
});
floorObjects.push(newFloor);
floorContainer.addChild(newFloor);
// Play building sound
LK.getSound('build').play();
// Update camera position
updateCameraPosition();
// Update game state
updateGameState();
}
}
// Calculate income per second
function calculateTotalIncome() {
var totalIncome = 0;
for (var i = 0; i < floors; i++) {
// Higher floors with higher levels produce more income
var baseIncome = (i + 1) * 2;
totalIncome += baseIncome * floorLevels[i];
}
return totalIncome;
}
// Update game state in storage
function updateGameState() {
updateBuildButtonCost();
}
// Calculate offline progress
function calculateOfflineProgress() {}
// Handle build button click
buildButton.interactive = true;
buildButton.down = function () {
buildNewFloor();
};
// Scroll game with touch/mouse
var dragStartY = 0;
var initialOffsetY = 0;
var isDragging = false;
game.down = function (x, y) {
if (floors > 5) {
// Only allow scrolling if there are enough floors
isDragging = true;
dragStartY = y;
initialOffsetY = cameraOffsetY;
}
};
game.move = function (x, y) {
if (isDragging && floors > 5) {
var deltaY = dragStartY - y;
var newOffsetY = initialOffsetY + deltaY;
// Limit scrolling range
var maxScroll = (floors - 5) * floorHeight;
newOffsetY = Math.max(0, Math.min(maxScroll, newOffsetY));
cameraOffsetY = newOffsetY;
updateFloorPositions();
}
};
game.up = function () {
isDragging = false;
};
// Initialize game
function initGame() {
resetGameProgress();
calculateOfflineProgress();
LK.playMusic('bgMusic');
}
// Run initialization
initGame();
// Game update loop
var lastTickTime = Date.now();
game.update = function () {
// Update clouds
for (var i = 0; i < clouds.length; i++) {
clouds[i].update();
}
// Calculate time since last tick for proper income calculation
var currentTime = Date.now();
var deltaTime = (currentTime - lastTickTime) / 1000; // Convert to seconds
lastTickTime = currentTime;
// Add income
money += calculateTotalIncome() * deltaTime;
// Update money display with formatted number
moneyText.setText('$' + Math.floor(money).toLocaleString());
// Flash build button if affordable
if (money >= getNewFloorCost()) {
if (LK.ticks % 60 < 30) {
buildButton.alpha = 1;
} else {
buildButton.alpha = 0.8;
}
}
};