Code edit (1 edits merged)
Please save this source code
User prompt
Startup Tycoon: Office Empire
Initial prompt
/**** * Assets ****/ LK.init.shape('companyLogo', {width:180, height:180, color:0x2d8cf0, shape:'ellipse'}) LK.init.shape('competitor', {width:120, height:120, color:0xe74c3c, shape:'box'}) LK.init.shape('employee', {width:80, height:80, color:0xf5a623, shape:'ellipse'}) LK.init.shape('event', {width:120, height:120, color:0x8e44ad, shape:'ellipse'}) LK.init.shape('money', {width:100, height:60, color:0x27ae60, shape:'box'}) LK.init.shape('office', {width:220, height:120, color:0x6c7a89, shape:'box'}) LK.init.shape('upgrade', {width:100, height:100, color:0xf1c40f, shape:'box'}) /**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Employee class var Employee = Container.expand(function () { var self = Container.call(this); var empArt = self.attachAsset('employee', { anchorX: 0.5, anchorY: 0.5 }); return self; }); // Event popup class var EventPopup = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('event', { anchorX: 0.5, anchorY: 0.5 }); self.text = new Text2('', { size: 60, fill: '#fff', align: 'center', wordWrap: true, wordWrapWidth: 400 }); self.text.anchor.set(0.5, 0.5); self.text.x = 0; self.text.y = 0; self.addChild(self.text); return self; }); // Office class var Office = Container.expand(function () { var self = Container.call(this); var officeArt = self.attachAsset('office', { anchorX: 0.5, anchorY: 0.5 }); return self; }); // Upgrade class var Upgrade = Container.expand(function () { var self = Container.call(this); var upgArt = self.attachAsset('upgrade', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xf4f6fa }); /**** * Game Code ****/ // Company logo (ellipse), office (box), employee (ellipse), money (box), competitor (box), upgrade (box), event (ellipse) // --- Game State --- var START_MONEY = 5000; var START_EMPLOYEES = 1; var START_OFFICES = 1; var ROUND_DURATION = 1200; // ms per round var MAX_ROUNDS = 30; var money = START_MONEY; var employees = START_EMPLOYEES; var offices = START_OFFICES; var upgrades = 0; var round = 1; var competitorProgress = 0; // 0-100 var bankrupt = false; var milestoneReached = false; var eventActive = false; var eventTimeout = null; var lastAction = null; // --- UI Elements --- var logo = LK.getAsset('companyLogo', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 260 }); game.addChild(logo); var officeNodes = []; var employeeNodes = []; var upgradeNodes = []; var moneyTxt = new Text2('', { size: 90, fill: '#27ae60' }); moneyTxt.anchor.set(0.5, 0); LK.gui.top.addChild(moneyTxt); var roundTxt = new Text2('', { size: 60, fill: '#34495e' }); roundTxt.anchor.set(0.5, 0); LK.gui.top.addChild(roundTxt); var competitorBar = LK.getAsset('competitor', { anchorX: 0, anchorY: 0.5, x: 200, y: 400, width: 0, height: 60 }); game.addChild(competitorBar); var competitorLabel = new Text2('Competitor', { size: 48, fill: '#e74c3c' }); competitorLabel.anchor.set(0, 0.5); competitorLabel.x = 200; competitorLabel.y = 340; game.addChild(competitorLabel); var milestoneTxt = new Text2('', { size: 80, fill: '#2980b9' }); milestoneTxt.anchor.set(0.5, 0.5); milestoneTxt.x = 1024; milestoneTxt.y = 600; game.addChild(milestoneTxt); // --- Action Buttons --- var actionBtns = []; var actionNames = [{ id: 'hire', label: 'Hire Employee', desc: '+1 Employee\nCost: $1000', cost: 1000 }, { id: 'expand', label: 'Expand Office', desc: '+1 Office\nCost: $2000', cost: 2000 }, { id: 'market', label: 'Marketing', desc: 'Boost Revenue\nCost: $1500', cost: 1500 }, { id: 'upgrade', label: 'Upgrade', desc: 'Increase Efficiency\nCost: $2500', cost: 2500 }, { id: 'skip', label: 'Skip', desc: 'No Action\nNo Cost', cost: 0 }]; // --- Event Popup --- var eventPopup = new EventPopup(); eventPopup.x = 1024; eventPopup.y = 1366; eventPopup.visible = false; game.addChild(eventPopup); // --- Helper Functions --- function updateUI() { moneyTxt.setText('$' + money); moneyTxt.x = LK.gui.width / 2; moneyTxt.y = 20; roundTxt.setText('Round ' + round + '/' + MAX_ROUNDS); roundTxt.x = LK.gui.width / 2; roundTxt.y = 120; milestoneTxt.setText(milestoneReached ? 'You are a Market Leader!' : ''); milestoneTxt.visible = milestoneReached; // Update competitor bar competitorBar.width = Math.floor(800 * (competitorProgress / 100)); // Offices for (var i = 0; i < officeNodes.length; ++i) { officeNodes[i].visible = false; } for (var i = 0; i < offices; ++i) { if (!officeNodes[i]) { var o = new Office(); o.x = 400 + i * 220; o.y = 900; officeNodes[i] = o; game.addChild(o); } officeNodes[i].visible = true; } // Employees for (var i = 0; i < employeeNodes.length; ++i) { employeeNodes[i].visible = false; } for (var i = 0; i < employees; ++i) { if (!employeeNodes[i]) { var e = new Employee(); e.x = 400 + i % 6 * 120; e.y = 1100 + Math.floor(i / 6) * 120; employeeNodes[i] = e; game.addChild(e); } employeeNodes[i].visible = true; } // Upgrades for (var i = 0; i < upgradeNodes.length; ++i) { upgradeNodes[i].visible = false; } for (var i = 0; i < upgrades; ++i) { if (!upgradeNodes[i]) { var u = new Upgrade(); u.x = 1800; u.y = 900 + i * 120; upgradeNodes[i] = u; game.addChild(u); } upgradeNodes[i].visible = true; } } // --- Action Button Creation --- function createActionButtons() { // Remove old for (var i = 0; i < actionBtns.length; ++i) { if (actionBtns[i].parent) { actionBtns[i].parent.removeChild(actionBtns[i]); } } actionBtns = []; // Create new for (var i = 0; i < actionNames.length; ++i) { var btn = LK.getAsset('money', { anchorX: 0.5, anchorY: 0.5, x: 500 + i * 310, y: 2200, width: 300, height: 220 }); var txt = new Text2(actionNames[i].label, { size: 54, fill: '#fff' }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = -30; btn.addChild(txt); var desc = new Text2(actionNames[i].desc, { size: 36, fill: '#fff' }); desc.anchor.set(0.5, 0.5); desc.x = 0; desc.y = 60; btn.addChild(desc); btn.actionId = actionNames[i].id; btn.actionIdx = i; btn.interactive = true; btn.down = function (x, y, obj) { if (eventActive || bankrupt || milestoneReached) { return; } handleAction(this.actionId); }; game.addChild(btn); actionBtns.push(btn); } } // --- Event System --- var eventList = [{ text: 'Tech Breakthrough!\n+1 Upgrade, +$2000', effect: function effect() { upgrades += 1; money += 2000; } }, { text: 'Market Crash!\nLose $3000', effect: function effect() { money -= 3000; } }, { text: 'Competitor Launches New Product!\nCompetitor gains ground.', effect: function effect() { competitorProgress += 20; } }, { text: 'Viral Marketing!\n+2 Employees', effect: function effect() { employees += 2; } }, { text: 'Office Fire!\nLose 1 Office', effect: function effect() { if (offices > 1) { offices -= 1; } } }, { text: 'Angel Investor!\n+$5000', effect: function effect() { money += 5000; } }, { text: 'Employee Strike!\nLose 2 Employees', effect: function effect() { employees = Math.max(1, employees - 2); } }, { text: 'Tax Refund!\n+$1500', effect: function effect() { money += 1500; } }, { text: 'Bad Press!\nCompetitor gains ground.', effect: function effect() { competitorProgress += 15; } }, { text: 'Product Recall!\nLose $2000', effect: function effect() { money -= 2000; } }]; function maybeTriggerEvent() { if (eventActive) { return; } // 30% chance of event if (Math.random() < 0.3) { var idx = Math.floor(Math.random() * eventList.length); var ev = eventList[idx]; eventActive = true; eventPopup.text.setText(ev.text); eventPopup.visible = true; tween(eventPopup, { alpha: 1 }, { duration: 200 }); eventTimeout = LK.setTimeout(function () { ev.effect(); eventPopup.visible = false; eventActive = false; updateUI(); checkGameEnd(); }, 1200); } } // --- Game Logic --- function handleAction(actionId) { if (bankrupt || milestoneReached) { return; } lastAction = actionId; switch (actionId) { case 'hire': if (money >= 1000) { money -= 1000; employees += 1; } break; case 'expand': if (money >= 2000) { money -= 2000; offices += 1; } break; case 'market': if (money >= 1500) { money -= 1500; // Marketing: next round revenue boost marketingBoost = 1.5; } break; case 'upgrade': if (money >= 2500) { money -= 2500; upgrades += 1; } break; case 'skip': // No action break; } updateUI(); nextRound(); } var marketingBoost = 1.0; function nextRound() { // Revenue calculation var baseRevenue = 800 * employees * offices; var upgradeBonus = 1 + 0.2 * upgrades; var revenue = Math.floor(baseRevenue * upgradeBonus * marketingBoost); marketingBoost = 1.0; // Expenses var expenses = 600 * employees + 400 * offices + 200 * upgrades; // Net var net = revenue - expenses; money += net; // Competitor progress var compInc = 5 + Math.max(0, 10 - offices - upgrades); competitorProgress += compInc; if (competitorProgress > 100) { competitorProgress = 100; } // Round advance round += 1; updateUI(); checkGameEnd(); maybeTriggerEvent(); } function checkGameEnd() { if (money < 0) { bankrupt = true; LK.effects.flashScreen(0xe74c3c, 1200); LK.showGameOver(); return; } if (competitorProgress >= 100) { bankrupt = true; LK.effects.flashScreen(0xe74c3c, 1200); LK.showGameOver(); return; } if (offices >= 5 && employees >= 10 && upgrades >= 3 && money >= 20000) { milestoneReached = true; LK.effects.flashScreen(0x27ae60, 1200); LK.showYouWin(); return; } if (round > MAX_ROUNDS) { if (money >= 15000) { milestoneReached = true; LK.effects.flashScreen(0x27ae60, 1200); LK.showYouWin(); } else { bankrupt = true; LK.effects.flashScreen(0xe74c3c, 1200); LK.showGameOver(); } return; } } // --- Game Start --- function resetGame() { money = START_MONEY; employees = START_EMPLOYEES; offices = START_OFFICES; upgrades = 0; round = 1; competitorProgress = 0; bankrupt = false; milestoneReached = false; eventActive = false; lastAction = null; marketingBoost = 1.0; updateUI(); createActionButtons(); } resetGame(); // --- Game Update Loop --- game.update = function () { // No per-frame logic needed for MVP }; // --- Touch Handling (for event popup) --- eventPopup.down = function (x, y, obj) { if (!eventActive) { return; } if (eventTimeout) { LK.clearTimeout(eventTimeout); eventTimeout = null; } eventPopup.visible = false; eventActive = false; updateUI(); checkGameEnd(); }; // --- Prevent UI in top left 100x100 --- logo.x = 1024; logo.y = 260; // --- End of File ---
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
}); /****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});