User prompt
Please fix the bug: 'Uncaught ReferenceError: upgradesTab is not defined' in or related to this line: 'upgradesTab.addChild(upgrade);' Line Number: 276
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 245
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 245
User prompt
Do a review of the code for errors.
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 245
User prompt
Fix Bug: 'upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 245
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 245
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 245
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 245
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 245
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.addChild(upgrade);' Line Number: 244
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'removeChildren')' in this line: 'upgradesTab.removeChildren();' Line Number: 164
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'Upgrades')' in this line: 'var upgradesTab = self.tabs['Upgrades'];' Line Number: 162
User prompt
When an upgrade is purchased, we need to re-process the upgrades and then redraw the first 5 unpurchased upgrades in the list on the upgrades tab
User prompt
The first purchased=false upgrade should always be displayed in the same place. It should iterate through the list of all upgrades and render the first 5 available ones from the full list. If one is not available, keep searching for an available one before moving to the next loop.
User prompt
When displaying the upgrades on the upgrades tab, always display the first five upgrades with purchased=false
User prompt
Fix Bug: 'TypeError: self.parent.updateAvailableUpgrades is not a function' in this line: 'self.parent.updateAvailableUpgrades();' Line Number: 58
User prompt
Once an upgrade is purchased, it should be removed from the list of available upgrades. The list should show the next 5 non-purchased upgrades.
User prompt
Fix Bug: 'Uncaught ReferenceError: upgradesTab is not defined' in this line: 'upgradesTab.removeChildren();' Line Number: 2
User prompt
Fix Bug: 'ReferenceError: updateAvailableUpgrades is not defined' in this line: 'updateAvailableUpgrades();' Line Number: 58
User prompt
Once an upgrade is purchased, it should be removed from the list of available upgrades. The list should show the next 5 non-purchased upgrades.
User prompt
The grid isn't working well. Let's change the grid to just be a list of the next 5 available upgrades as 5 different buttons, all centered and in a vertical stack
User prompt
We shouldn't be sliding the upgrades upward when buying one
User prompt
The grid is now no longer centered in the window
User prompt
When rendering the grid of upgrades, only show non-purchased ones.
/**** * Classes ****/ var Cloud = Container.expand(function () { var self = Container.call(this); self.visible = true; var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); cloudGraphics.alpha = 1; self.spawnRate = 1; self.clickValue = 1; self.bounceSpeed = 0.02; self.bounceHeight = 15; self.bounceOffset = 0; self.swayWidth = 300; self.swaySpeed = .003; self.update = function () { self.bounceOffset += self.bounceSpeed; self.y = 2732 / 2 + Math.sin(self.bounceOffset) * self.bounceHeight; self.x = 1024 + Math.sin(LK.ticks * self.swaySpeed) * self.swayWidth; }; self.spawnSnowflake = function () { var snowflake = new Snowflake(); var cloudWidth = cloudGraphics.width; snowflake.x = this.x + (Math.random() - 0.5) * 800; snowflake.y = self.y + cloudGraphics.height / 2 + Math.sin(self.bounceOffset) * self.bounceHeight; snowflake.rotation = Math.random() * Math.PI * 2; return snowflake; }; }); var Snowflake = Container.expand(function () { var self = Container.call(this); var snowflakeGraphics = self.attachAsset('snowflake', { anchorX: 0.5, anchorY: 0.5 }); self.rotationSpeed = (Math.random() - 0.5) * 0.02; self.swayMagnitude = Math.random() * 10; self.swaySpeed = (Math.random() - 0.5) * 0.03; self.sizeFactor = Math.random() * 0.75 + 0.25; self.scale.set(self.sizeFactor); self.swayMagnitude = self.sizeFactor * 5; self.swayOffset = Math.random() * Math.PI * 2; self.update = function () { self.y += 0.5 + Math.random(); self.rotation += self.rotationSpeed; self.x += Math.sin(LK.ticks * self.swaySpeed * 2 + self.swayOffset) * (self.swayMagnitude * 0.25); }; self.collect = function () { var gameInstance = self.parent; gameInstance.setScore(Math.round(gameInstance.getScore() + 1)); scoreTxt.setText(gameInstance.getScore().toString()); self.destroy(); }; }); var TabButton = Container.expand(function (label, onClick) { var self = Container.call(this); var buttonGraphics = self.attachAsset('tabButton', { anchorY: 0.5 }); buttonGraphics.tint = 0x777777; var buttonText = new Text2(label, { size: 50, fill: '#ffffff', anchor: { x: 0.5, y: 0.5 }, align: 'center' }); self.addChild(buttonText); self.on('down', function () { onClick(); }); }); var TabSystem = Container.expand(function () { var self = Container.call(this); self.tabs = {}; self.currentTab = ''; self.addTab = function (name, content) { self.tabs[name] = content; content.visible = false; self.addChild(content); }; self.switchTab = function (name) { if (self.tabs[self.currentTab]) { self.tabs[self.currentTab].visible = false; self.tabs[self.currentTab].children.forEach(function (child) { child.visible = false; }); } self.currentTab = name; self.tabs[name].visible = true; self.tabs[name].children.forEach(function (child) { child.visible = true; if (child instanceof TabButton) { child.children[0].tint = 0xFFFFFF; } }); Object.values(self.tabs).forEach(function (content) { if (content !== self.tabs[name]) { content.children.forEach(function (child) { if (child instanceof TabButton) { child.children[0].tint = 0x777777; } }); } }); }; }); var Upgrade = Container.expand(function (cost, effectType, effectMode, effectValue, available) { var self = Container.call(this); self.available = available || false; var upgradeGraphics = self.attachAsset('upgrade', { anchorX: 0.5, anchorY: 0.5 }); var costText = new Text2('Cost: ' + (cost < 10000 ? Math.round(cost) : cost.toPrecision(2)), { size: 35, fill: '#ffffff', anchor: { x: 0.5, y: 0.5 } }); costText.y = -35; costText.x = -costText.width / 2; self.addChild(costText); var effectDescription = effectType === 'click' ? 'Per Click: ' : 'Per Second: '; effectDescription += effectMode === 'add' ? '+' : 'x'; effectDescription += effectValue !== undefined ? effectValue.toString() : '0'; var effectText = new Text2(effectDescription, { size: 35, fill: '#ffffff', anchor: { x: 0.5, y: 0.5 } }); effectText.y = 35; effectText.x = -effectText.width / 2; self.addChild(effectText); self.cost = cost; self.effectType = effectType; self.effectMode = effectMode; self.effectValue = effectValue; self.purchased = false; self.on('down', function () { var gameInstance = self.parent.parent.parent; if (!self.purchased && gameInstance.getScore() >= self.cost) { gameInstance.setScore(gameInstance.getScore() - self.cost); if (self.effectType === 'click') { if (self.effectMode === 'add') { cloud.clickValue += self.effectValue; } else { cloud.clickValue *= self.effectValue; } } else { if (self.effectMode === 'add') { self.parent.parent.parent.setScorePerSec(self.parent.parent.parent.getScorePerSec() + self.effectValue); } else if (self.effectMode === 'add') { self.parent.parent.parent.setScorePerSec(self.parent.parent.parent.getScorePerSec() + self.effectValue); } } self.purchased = true; self.visible = false; gameInstance.redrawUpgrades(); } }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.tabs = {}; game.upgradesTab = new Container(); game.redrawUpgrades = function () { game.upgradesTab.removeChildren(); var displayedUpgrades = 0; upgradesConfig.forEach(function (config, index) { if (!config.purchased && displayedUpgrades < 5) { var upgrade = new Upgrade(config.cost, config.effectType, config.effectMode, config.effectValue, true); game.game.game.game.upgradesTab.addChild(upgrade); upgrade.x = startX + index % columns * (upgradeWidth + upgradeSpacing); upgrade.y = startY + Math.floor(index / columns) * (upgradeHeight + upgradePadding); displayedUpgrades++; } }); }; game._score = 0; game._scorePerSec = 0; game.getScore = function () { return game._score; }; game.setScore = function (value) { game._score = value; }; game.getScorePerSec = function () { return game._scorePerSec; }; game.setScorePerSec = function (value) { game._scorePerSec = value; }; game.setBackgroundColor(0x000000); var tabSystem = new TabSystem(); game.upgradesTab = new Container(); var upgradesConfig = [{ cost: 10, effectType: 'perSecond', effectMode: 'add', effectValue: 1 }, { cost: 25, effectType: 'perSecond', effectMode: 'multiply', effectValue: 2 }, { cost: 100, effectType: 'perSecond', effectMode: 'multiply', effectValue: 2 }, { cost: 500, effectType: 'perSecond', effectMode: 'multiply', effectValue: 2 }, { cost: 1000, effectType: 'perSecond', effectMode: 'multiply', effectValue: 2 }, { cost: 2500, effectType: 'perSecond', effectMode: 'multiply', effectValue: 2 }, { cost: 10000, effectType: 'perSecond', effectMode: 'multiply', effectValue: 2 }, { cost: 20000, effectType: 'perSecond', effectMode: 'multiply', effectValue: 2 }]; var columns = 3; var upgradeWidth = 400; var upgradeHeight = 200; var upgradeSpacing = 200; var upgradePadding = 200; var startX = (2048 - (columns * upgradeWidth + (columns - 1) * upgradeSpacing)) / 2; var startY = 800; var displayedUpgrades = 0; upgradesConfig.forEach(function (config, index) { if (!config.purchased && displayedUpgrades < 5) { var upgrade = new Upgrade(config.cost, config.effectType, config.effectMode, config.effectValue, true); game.upgradesTab.addChild(upgrade); upgrade.x = startX + displayedUpgrades % columns * (upgradeWidth + upgradeSpacing); upgrade.y = startY + Math.floor(displayedUpgrades / columns) * (upgradeHeight + upgradePadding); displayedUpgrades++; } }); var scoreTxt; function initializeScoreText() { scoreTxt = new Text2('', { size: 150, fill: '#ffffff', anchor: { x: 0.5, y: 0.5 } }); scoreTxt.x = -scoreTxt.width / 2; LK.gui.top.addChild(scoreTxt); scoreTxt.y = LK.gui.top.height / 2; } initializeScoreText(); var cloudTabButton = new TabButton('Cloud', function () { tabSystem.switchTab('Cloud'); }); var upgradesTabButton = new TabButton('Upgrades', function () { tabSystem.switchTab('Upgrades'); }); cloudTabButton.x = -cloudTabButton.width; cloudTabButton.y = scoreTxt.y + scoreTxt.height + 50; upgradesTabButton.x = 10; upgradesTabButton.y = cloudTabButton.y; LK.gui.top.addChild(cloudTabButton); LK.gui.top.addChild(upgradesTabButton); game.addChild(tabSystem); var snowflakes = []; var cloudTab = new Container(); var cloud = cloudTab.addChild(new Cloud()); cloud.x = 2048 / 2; cloud.y = 2732 / 2; tabSystem.addTab('Upgrades', upgradesTab); tabSystem.addTab('Cloud', cloudTab); tabSystem.switchTab('Cloud'); cloud.on('down', function (obj) { for (var i = 0; i < cloud.spawnRate; i++) { var snowflake = cloud.spawnSnowflake(); snowflakes.push(snowflake); game.addChild(snowflake); } game.setScore(game.getScore() + cloud.clickValue); console.log('Score per click:', cloud.clickValue); }); var tickCount = 0; LK.on('tick', function () { console.log('Current score:', game.getScore(), 'Score per second:', game.getScorePerSec(), 'Score per tick:', game.getScorePerSec() / 60, 'New score after tick:', game.getScore() + game.getScorePerSec() / 60); game.setScore(game.getScore() + game.getScorePerSec() / 60); tickCount++; cloud.update(); for (var i = snowflakes.length - 1; i >= 0; i--) { snowflakes[i].update(); if (snowflakes[i].y > 2732 + snowflakes[i].height) { snowflakes[i].destroy(); snowflakes.splice(i, 1); } } });
===================================================================
--- original.js
+++ change.js
@@ -1,64 +1,66 @@
-var Upgrade = Container.expand(function (cost, effectType, effectMode, effectValue, available) {
+/****
+* Classes
+****/
+var Cloud = Container.expand(function () {
var self = Container.call(this);
- self.available = available || false;
- var upgradeGraphics = self.createAsset('upgrade', 'Upgrade Graphics', .5, .5);
- var costText = new Text2('Cost: ' + (cost < 10000 ? Math.round(cost) : cost.toPrecision(2)), {
- size: 35,
- fill: '#ffffff',
- anchor: {
- x: 0.5,
- y: 0.5
- }
+ self.visible = true;
+ var cloudGraphics = self.attachAsset('cloud', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- costText.y = -35;
- costText.x = -costText.width / 2;
- self.addChild(costText);
- var effectDescription = effectType === 'click' ? 'Per Click: ' : 'Per Second: ';
- effectDescription += effectMode === 'add' ? '+' : 'x';
- effectDescription += effectValue !== undefined ? effectValue.toString() : '0';
- var effectText = new Text2(effectDescription, {
- size: 35,
- fill: '#ffffff',
- anchor: {
- x: 0.5,
- y: 0.5
- }
+ cloudGraphics.alpha = 1;
+ self.spawnRate = 1;
+ self.clickValue = 1;
+ self.bounceSpeed = 0.02;
+ self.bounceHeight = 15;
+ self.bounceOffset = 0;
+ self.swayWidth = 300;
+ self.swaySpeed = .003;
+ self.update = function () {
+ self.bounceOffset += self.bounceSpeed;
+ self.y = 2732 / 2 + Math.sin(self.bounceOffset) * self.bounceHeight;
+ self.x = 1024 + Math.sin(LK.ticks * self.swaySpeed) * self.swayWidth;
+ };
+ self.spawnSnowflake = function () {
+ var snowflake = new Snowflake();
+ var cloudWidth = cloudGraphics.width;
+ snowflake.x = this.x + (Math.random() - 0.5) * 800;
+ snowflake.y = self.y + cloudGraphics.height / 2 + Math.sin(self.bounceOffset) * self.bounceHeight;
+ snowflake.rotation = Math.random() * Math.PI * 2;
+ return snowflake;
+ };
+});
+var Snowflake = Container.expand(function () {
+ var self = Container.call(this);
+ var snowflakeGraphics = self.attachAsset('snowflake', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- effectText.y = 35;
- effectText.x = -effectText.width / 2;
- self.addChild(effectText);
- self.cost = cost;
- self.effectType = effectType;
- self.effectMode = effectMode;
- self.effectValue = effectValue;
- self.purchased = false;
- self.on('down', function () {
- var gameInstance = self.parent.parent.parent;
- if (!self.purchased && gameInstance.getScore() >= self.cost) {
- gameInstance.setScore(gameInstance.getScore() - self.cost);
- if (self.effectType === 'click') {
- if (self.effectMode === 'add') {
- cloud.clickValue += self.effectValue;
- } else {
- cloud.clickValue *= self.effectValue;
- }
- } else {
- if (self.effectMode === 'add') {
- self.parent.parent.parent.setScorePerSec(self.parent.parent.parent.getScorePerSec() + self.effectValue);
- } else if (self.effectMode === 'add') {
- self.parent.parent.parent.setScorePerSec(self.parent.parent.parent.getScorePerSec() + self.effectValue);
- }
- }
- self.purchased = true;
- self.visible = false;
- gameInstance.redrawUpgrades();
- }
- });
+ self.rotationSpeed = (Math.random() - 0.5) * 0.02;
+ self.swayMagnitude = Math.random() * 10;
+ self.swaySpeed = (Math.random() - 0.5) * 0.03;
+ self.sizeFactor = Math.random() * 0.75 + 0.25;
+ self.scale.set(self.sizeFactor);
+ self.swayMagnitude = self.sizeFactor * 5;
+ self.swayOffset = Math.random() * Math.PI * 2;
+ self.update = function () {
+ self.y += 0.5 + Math.random();
+ self.rotation += self.rotationSpeed;
+ self.x += Math.sin(LK.ticks * self.swaySpeed * 2 + self.swayOffset) * (self.swayMagnitude * 0.25);
+ };
+ self.collect = function () {
+ var gameInstance = self.parent;
+ gameInstance.setScore(Math.round(gameInstance.getScore() + 1));
+ scoreTxt.setText(gameInstance.getScore().toString());
+ self.destroy();
+ };
});
var TabButton = Container.expand(function (label, onClick) {
var self = Container.call(this);
- var buttonGraphics = self.createAsset('tabButton', 'Tab Button Graphics', 0, 0.5);
+ var buttonGraphics = self.attachAsset('tabButton', {
+ anchorY: 0.5
+ });
buttonGraphics.tint = 0x777777;
var buttonText = new Text2(label, {
size: 50,
fill: '#ffffff',
@@ -107,204 +109,224 @@
}
});
};
});
-var Snowflake = Container.expand(function () {
+var Upgrade = Container.expand(function (cost, effectType, effectMode, effectValue, available) {
var self = Container.call(this);
- var snowflakeGraphics = self.createAsset('snowflake', 'Snowflake Graphics', .5, .5);
- self.rotationSpeed = (Math.random() - 0.5) * 0.02;
- self.swayMagnitude = Math.random() * 10;
- self.swaySpeed = (Math.random() - 0.5) * 0.03;
- self.sizeFactor = Math.random() * 0.75 + 0.25;
- self.scale.set(self.sizeFactor);
- self.swayMagnitude = self.sizeFactor * 5;
- self.swayOffset = Math.random() * Math.PI * 2;
- self.update = function () {
- self.y += 0.5 + Math.random();
- self.rotation += self.rotationSpeed;
- self.x += Math.sin(LK.ticks * self.swaySpeed * 2 + self.swayOffset) * (self.swayMagnitude * 0.25);
- };
- self.collect = function () {
- var gameInstance = self.parent;
- gameInstance.setScore(Math.round(gameInstance.getScore() + 1));
- scoreTxt.setText(gameInstance.getScore().toString());
- self.destroy();
- };
+ self.available = available || false;
+ var upgradeGraphics = self.attachAsset('upgrade', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var costText = new Text2('Cost: ' + (cost < 10000 ? Math.round(cost) : cost.toPrecision(2)), {
+ size: 35,
+ fill: '#ffffff',
+ anchor: {
+ x: 0.5,
+ y: 0.5
+ }
+ });
+ costText.y = -35;
+ costText.x = -costText.width / 2;
+ self.addChild(costText);
+ var effectDescription = effectType === 'click' ? 'Per Click: ' : 'Per Second: ';
+ effectDescription += effectMode === 'add' ? '+' : 'x';
+ effectDescription += effectValue !== undefined ? effectValue.toString() : '0';
+ var effectText = new Text2(effectDescription, {
+ size: 35,
+ fill: '#ffffff',
+ anchor: {
+ x: 0.5,
+ y: 0.5
+ }
+ });
+ effectText.y = 35;
+ effectText.x = -effectText.width / 2;
+ self.addChild(effectText);
+ self.cost = cost;
+ self.effectType = effectType;
+ self.effectMode = effectMode;
+ self.effectValue = effectValue;
+ self.purchased = false;
+ self.on('down', function () {
+ var gameInstance = self.parent.parent.parent;
+ if (!self.purchased && gameInstance.getScore() >= self.cost) {
+ gameInstance.setScore(gameInstance.getScore() - self.cost);
+ if (self.effectType === 'click') {
+ if (self.effectMode === 'add') {
+ cloud.clickValue += self.effectValue;
+ } else {
+ cloud.clickValue *= self.effectValue;
+ }
+ } else {
+ if (self.effectMode === 'add') {
+ self.parent.parent.parent.setScorePerSec(self.parent.parent.parent.getScorePerSec() + self.effectValue);
+ } else if (self.effectMode === 'add') {
+ self.parent.parent.parent.setScorePerSec(self.parent.parent.parent.getScorePerSec() + self.effectValue);
+ }
+ }
+ self.purchased = true;
+ self.visible = false;
+ gameInstance.redrawUpgrades();
+ }
+ });
});
-var Cloud = Container.expand(function () {
- var self = Container.call(this);
- self.visible = true;
- var cloudGraphics = self.createAsset('cloud', 'Cloud Graphics', .5, .5);
- cloudGraphics.alpha = 1;
- self.spawnRate = 1;
- self.clickValue = 1;
- self.bounceSpeed = 0.02;
- self.bounceHeight = 15;
- self.bounceOffset = 0;
- self.swayWidth = 300;
- self.swaySpeed = .003;
- self.update = function () {
- self.bounceOffset += self.bounceSpeed;
- self.y = 2732 / 2 + Math.sin(self.bounceOffset) * self.bounceHeight;
- self.x = 1024 + Math.sin(LK.ticks * self.swaySpeed) * self.swayWidth;
- };
- self.spawnSnowflake = function () {
- var snowflake = new Snowflake();
- var cloudWidth = cloudGraphics.width;
- snowflake.x = this.x + (Math.random() - 0.5) * 800;
- snowflake.y = self.y + cloudGraphics.height / 2 + Math.sin(self.bounceOffset) * self.bounceHeight;
- snowflake.rotation = Math.random() * Math.PI * 2;
- return snowflake;
- };
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
});
-var Game = Container.expand(function () {
- var self = Container.call(this);
- self.tabs = {};
- self.upgradesTab = new Container();
- self.redrawUpgrades = function () {
- self.upgradesTab.removeChildren();
- var displayedUpgrades = 0;
- upgradesConfig.forEach(function (config, index) {
- if (!config.purchased && displayedUpgrades < 5) {
- var upgrade = new Upgrade(config.cost, config.effectType, config.effectMode, config.effectValue, true);
- self.self.self.self.upgradesTab.addChild(upgrade);
- upgrade.x = startX + index % columns * (upgradeWidth + upgradeSpacing);
- upgrade.y = startY + Math.floor(index / columns) * (upgradeHeight + upgradePadding);
- displayedUpgrades++;
- }
- });
- };
- self._score = 0;
- self._scorePerSec = 0;
- self.getScore = function () {
- return self._score;
- };
- self.setScore = function (value) {
- self._score = value;
- };
- self.getScorePerSec = function () {
- return self._scorePerSec;
- };
- self.setScorePerSec = function (value) {
- self._scorePerSec = value;
- };
- LK.stageContainer.setBackgroundColor(0x000000);
- var tabSystem = new TabSystem();
- self.upgradesTab = new Container();
- var upgradesConfig = [{
- cost: 10,
- effectType: 'perSecond',
- effectMode: 'add',
- effectValue: 1
- }, {
- cost: 25,
- effectType: 'perSecond',
- effectMode: 'multiply',
- effectValue: 2
- }, {
- cost: 100,
- effectType: 'perSecond',
- effectMode: 'multiply',
- effectValue: 2
- }, {
- cost: 500,
- effectType: 'perSecond',
- effectMode: 'multiply',
- effectValue: 2
- }, {
- cost: 1000,
- effectType: 'perSecond',
- effectMode: 'multiply',
- effectValue: 2
- }, {
- cost: 2500,
- effectType: 'perSecond',
- effectMode: 'multiply',
- effectValue: 2
- }, {
- cost: 10000,
- effectType: 'perSecond',
- effectMode: 'multiply',
- effectValue: 2
- }, {
- cost: 20000,
- effectType: 'perSecond',
- effectMode: 'multiply',
- effectValue: 2
- }];
- var columns = 3;
- var upgradeWidth = 400;
- var upgradeHeight = 200;
- var upgradeSpacing = 200;
- var upgradePadding = 200;
- var startX = (2048 - (columns * upgradeWidth + (columns - 1) * upgradeSpacing)) / 2;
- var startY = 800;
+
+/****
+* Game Code
+****/
+game.tabs = {};
+game.upgradesTab = new Container();
+game.redrawUpgrades = function () {
+ game.upgradesTab.removeChildren();
var displayedUpgrades = 0;
upgradesConfig.forEach(function (config, index) {
if (!config.purchased && displayedUpgrades < 5) {
var upgrade = new Upgrade(config.cost, config.effectType, config.effectMode, config.effectValue, true);
- upgradesTab.addChild(upgrade);
- upgrade.x = startX + displayedUpgrades % columns * (upgradeWidth + upgradeSpacing);
- upgrade.y = startY + Math.floor(displayedUpgrades / columns) * (upgradeHeight + upgradePadding);
+ game.game.game.game.upgradesTab.addChild(upgrade);
+ upgrade.x = startX + index % columns * (upgradeWidth + upgradeSpacing);
+ upgrade.y = startY + Math.floor(index / columns) * (upgradeHeight + upgradePadding);
displayedUpgrades++;
}
});
- var scoreTxt;
- function initializeScoreText() {
- scoreTxt = new Text2('', {
- size: 150,
- fill: '#ffffff',
- anchor: {
- x: 0.5,
- y: 0.5
- }
- });
- scoreTxt.x = -scoreTxt.width / 2;
- LK.gui.topCenter.addChild(scoreTxt);
- scoreTxt.y = LK.gui.topCenter.height / 2;
+};
+game._score = 0;
+game._scorePerSec = 0;
+game.getScore = function () {
+ return game._score;
+};
+game.setScore = function (value) {
+ game._score = value;
+};
+game.getScorePerSec = function () {
+ return game._scorePerSec;
+};
+game.setScorePerSec = function (value) {
+ game._scorePerSec = value;
+};
+game.setBackgroundColor(0x000000);
+var tabSystem = new TabSystem();
+game.upgradesTab = new Container();
+var upgradesConfig = [{
+ cost: 10,
+ effectType: 'perSecond',
+ effectMode: 'add',
+ effectValue: 1
+}, {
+ cost: 25,
+ effectType: 'perSecond',
+ effectMode: 'multiply',
+ effectValue: 2
+}, {
+ cost: 100,
+ effectType: 'perSecond',
+ effectMode: 'multiply',
+ effectValue: 2
+}, {
+ cost: 500,
+ effectType: 'perSecond',
+ effectMode: 'multiply',
+ effectValue: 2
+}, {
+ cost: 1000,
+ effectType: 'perSecond',
+ effectMode: 'multiply',
+ effectValue: 2
+}, {
+ cost: 2500,
+ effectType: 'perSecond',
+ effectMode: 'multiply',
+ effectValue: 2
+}, {
+ cost: 10000,
+ effectType: 'perSecond',
+ effectMode: 'multiply',
+ effectValue: 2
+}, {
+ cost: 20000,
+ effectType: 'perSecond',
+ effectMode: 'multiply',
+ effectValue: 2
+}];
+var columns = 3;
+var upgradeWidth = 400;
+var upgradeHeight = 200;
+var upgradeSpacing = 200;
+var upgradePadding = 200;
+var startX = (2048 - (columns * upgradeWidth + (columns - 1) * upgradeSpacing)) / 2;
+var startY = 800;
+var displayedUpgrades = 0;
+upgradesConfig.forEach(function (config, index) {
+ if (!config.purchased && displayedUpgrades < 5) {
+ var upgrade = new Upgrade(config.cost, config.effectType, config.effectMode, config.effectValue, true);
+ game.upgradesTab.addChild(upgrade);
+ upgrade.x = startX + displayedUpgrades % columns * (upgradeWidth + upgradeSpacing);
+ upgrade.y = startY + Math.floor(displayedUpgrades / columns) * (upgradeHeight + upgradePadding);
+ displayedUpgrades++;
}
- initializeScoreText();
- var cloudTabButton = new TabButton('Cloud', function () {
- tabSystem.switchTab('Cloud');
- });
- var upgradesTabButton = new TabButton('Upgrades', function () {
- tabSystem.switchTab('Upgrades');
- });
- cloudTabButton.x = -cloudTabButton.width;
- cloudTabButton.y = scoreTxt.y + scoreTxt.height + 50;
- upgradesTabButton.x = 10;
- upgradesTabButton.y = cloudTabButton.y;
- LK.gui.topCenter.addChild(cloudTabButton);
- LK.gui.topCenter.addChild(upgradesTabButton);
- self.addChild(tabSystem);
- var snowflakes = [];
- var cloudTab = new Container();
- var cloud = cloudTab.addChild(new Cloud());
- cloud.x = 2048 / 2;
- cloud.y = 2732 / 2;
- tabSystem.addTab('Upgrades', upgradesTab);
- tabSystem.addTab('Cloud', cloudTab);
- tabSystem.switchTab('Cloud');
- cloud.on('down', function (obj) {
- for (var i = 0; i < cloud.spawnRate; i++) {
- var snowflake = cloud.spawnSnowflake();
- snowflakes.push(snowflake);
- self.addChild(snowflake);
+});
+var scoreTxt;
+function initializeScoreText() {
+ scoreTxt = new Text2('', {
+ size: 150,
+ fill: '#ffffff',
+ anchor: {
+ x: 0.5,
+ y: 0.5
}
- self.setScore(self.getScore() + cloud.clickValue);
- console.log('Score per click:', cloud.clickValue);
});
- var tickCount = 0;
- LK.on('tick', function () {
- console.log('Current score:', self.getScore(), 'Score per second:', self.getScorePerSec(), 'Score per tick:', self.getScorePerSec() / 60, 'New score after tick:', self.getScore() + self.getScorePerSec() / 60);
- self.setScore(self.getScore() + self.getScorePerSec() / 60);
- tickCount++;
- cloud.update();
- for (var i = snowflakes.length - 1; i >= 0; i--) {
- snowflakes[i].update();
- if (snowflakes[i].y > 2732 + snowflakes[i].height) {
- snowflakes[i].destroy();
- snowflakes.splice(i, 1);
- }
- }
- });
+ scoreTxt.x = -scoreTxt.width / 2;
+ LK.gui.top.addChild(scoreTxt);
+ scoreTxt.y = LK.gui.top.height / 2;
+}
+initializeScoreText();
+var cloudTabButton = new TabButton('Cloud', function () {
+ tabSystem.switchTab('Cloud');
});
+var upgradesTabButton = new TabButton('Upgrades', function () {
+ tabSystem.switchTab('Upgrades');
+});
+cloudTabButton.x = -cloudTabButton.width;
+cloudTabButton.y = scoreTxt.y + scoreTxt.height + 50;
+upgradesTabButton.x = 10;
+upgradesTabButton.y = cloudTabButton.y;
+LK.gui.top.addChild(cloudTabButton);
+LK.gui.top.addChild(upgradesTabButton);
+game.addChild(tabSystem);
+var snowflakes = [];
+var cloudTab = new Container();
+var cloud = cloudTab.addChild(new Cloud());
+cloud.x = 2048 / 2;
+cloud.y = 2732 / 2;
+tabSystem.addTab('Upgrades', upgradesTab);
+tabSystem.addTab('Cloud', cloudTab);
+tabSystem.switchTab('Cloud');
+cloud.on('down', function (obj) {
+ for (var i = 0; i < cloud.spawnRate; i++) {
+ var snowflake = cloud.spawnSnowflake();
+ snowflakes.push(snowflake);
+ game.addChild(snowflake);
+ }
+ game.setScore(game.getScore() + cloud.clickValue);
+ console.log('Score per click:', cloud.clickValue);
+});
+var tickCount = 0;
+LK.on('tick', function () {
+ console.log('Current score:', game.getScore(), 'Score per second:', game.getScorePerSec(), 'Score per tick:', game.getScorePerSec() / 60, 'New score after tick:', game.getScore() + game.getScorePerSec() / 60);
+ game.setScore(game.getScore() + game.getScorePerSec() / 60);
+ tickCount++;
+ cloud.update();
+ for (var i = snowflakes.length - 1; i >= 0; i--) {
+ snowflakes[i].update();
+ if (snowflakes[i].y > 2732 + snowflakes[i].height) {
+ snowflakes[i].destroy();
+ snowflakes.splice(i, 1);
+ }
+ }
+});
\ No newline at end of file