User prompt
Migrate to the latest version of LK
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'checkForUpgrade')' in or related to this line: 'game.cookieUpgradeManager.checkForUpgrade();' Line Number: 149
User prompt
make the game a high level non simple game
User prompt
prestige upgrades should have higher multipliers than the normal ones
User prompt
make the prestige button a little more lower
User prompt
make prestige button a little lower
User prompt
move the prestige button to the middle right
User prompt
Implement error handling for potential issues, such as asset loading failures or unexpected events.
User prompt
Implement error handling for potential issues, such as asset loading failures or unexpected events.
User prompt
Fix Bug: 'Uncaught ReferenceError: Tutorial is not defined' in or related to this line: 'var tutorialScreen = new Tutorial();' Line Number: 304
User prompt
not the entire screen just a pop-up tutorial section
User prompt
Fix Bug: 'Uncaught LK.Game can only be initialized once' in or related to this line: 'var tutorialScreen = new LK.Game({' Line Number: 299
User prompt
add a tutorial screen in the start which shows most of the features and how to use them and what they require
User prompt
make prestige cost 10000000
User prompt
Add a prestige system that allows players to reset their progress for 10 new upgrades that are randomly generated with random names so it keeps going forever
User prompt
Add more upgrades and features to make the game more engaging.
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'setText')' in or related to this line: 'game.scoreText.setText(game.score.toString());' Line Number: 147
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'setText')' in or related to this line: 'game.scoreText.setText(game.score.toString());' Line Number: 200
User prompt
Consider refactoring some parts of the code into separate functions for better readability.
User prompt
Add comments to explain the purpose of the code blocks and functions.
User prompt
Instead of displaying 1.1 on the scoreboard, simply show 1. As 1.1 continues to be repeated in the background, the score will gradually rise to 2.
User prompt
multipliers are too high
User prompt
When clicking at the bottom of the screen, the upgrades that are currently not visible should be displayed. Similarly, clicking near the top of the screen should initiate a scroll-up action using correct sources.
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'global')' in or related to this line: 'self.startY = obj.event.data.global.y;' Line Number: 20
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'some')' in or related to this line: 'if (game.score >= upgrade.cost && !game.availableUpgrades.some(function (u) {' Line Number: 243
===================================================================
--- original.js
+++ change.js
@@ -1,119 +1,7 @@
/****
* Classes
-****/
-// Check every 5 seconds
-var GoldenCookie = Container.expand(function () {
- var self = Container.call(this);
- var goldenCookieGraphic = self.attachAsset('cookieGold', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- if (!goldenCookieGraphic) {
- console.error('Failed to load golden cookie asset.');
- }
- self.interactive = true;
- self.buttonMode = true;
- self.on('down', function () {
- game.incrementScore(1000); // Bonus score for clicking the golden cookie
- LK.effects.flashObject(self, 0xffd700, 300);
- self.destroy();
- });
- self.spawn = function () {
- self.x = Math.random() * (2048 - goldenCookieGraphic.width) + goldenCookieGraphic.width / 2;
- self.y = Math.random() * (2732 - goldenCookieGraphic.height) + goldenCookieGraphic.height / 2;
- game.addChild(self);
- };
-});
-// ScrollingContainer class: Manages a container that can scroll vertically to display upgrades.
-// It keeps track of the upgrades added to it and handles the scrolling logic.
-var ScrollingContainer = Container.expand(function () {
- var self = Container.call(this);
- self.interactive = true; // Makes the container respond to touch events.
- self.upgrades = []; // Array to store upgrade elements.
- self.startY = 0; // Starting Y position for touch events.
- self.currentScrollY = 0; // Current Y scroll position.
- self.maxScrollY = 0; // Maximum Y scroll position (top limit).
- self.minScrollY = 0; // Minimum Y scroll position (bottom limit).
- self.on('down', function (obj) {
- if (!obj.event.data) {
- console.error('Touch event data is missing.');
- return;
- }
- self.startY = obj.event.data.global.y;
- });
- self.on('move', function (obj) {
- if (!obj.event.data || !obj.event.data.global) {
- console.error('Touch event data is missing or incomplete.');
- return;
- }
- var newY = obj.event.data.global.y;
- var deltaY = newY - self.startY;
- self.startY = newY;
- self.currentScrollY += deltaY;
- self.currentScrollY = Math.min(self.currentScrollY, self.minScrollY);
- self.currentScrollY = Math.max(self.currentScrollY, self.maxScrollY);
- self.upgrades.forEach(function (upgrade) {
- upgrade.y += deltaY;
- });
- });
- self.addUpgrade = function (upgrade) {
- self.upgrades.push(upgrade);
- self.addChild(upgrade);
- self.maxScrollY = Math.min(self.maxScrollY, -upgrade.y + 200);
- self.minScrollY = 0;
- };
- self.scroll = function (direction) {
- var scrollAmount = 300 * direction;
- self.currentScrollY += scrollAmount;
- self.currentScrollY = Math.min(self.currentScrollY, self.minScrollY);
- self.currentScrollY = Math.max(self.currentScrollY, self.maxScrollY);
- self.upgrades.forEach(function (upgrade) {
- upgrade.y -= scrollAmount;
- });
- };
-});
-// Cursor class: Represents the cursor upgrade that generates cookies per second.
-// It manages its own cost, production rate, and the amount purchased.
-var Cursor = Container.expand(function (initialCost, cps) {
- var self = Container.call(this);
- self.cost = initialCost; // Initial cost to purchase a cursor.
- self.cps = cps; // Cookies per second generated by each cursor.
- self.amount = 0; // Number of cursors purchased.
- self.purchase = function () {
- if (game.score >= self.cost) {
- game.score -= self.cost;
- self.amount++;
- self.cost = Math.ceil(self.cost * 1.20); // Increase cost by 20% for the next purchase
- game.scoreDisplay.scoreText.setText(game.score.toString());
- // Update the display for the number of Cursors and the next cost
- self.cursorText.setText('Cursors: ' + self.amount + ' - Next Cost: ' + self.cost + ' Cookies');
- // Visual feedback for Cursor purchase
- LK.effects.flashObject(self.cursorText, 0x00ff00, 100);
- }
- };
- self.generateCookies = function () {
- // Generate cookies from Cursors every second
- var cookiesPerSecond = self.amount * self.cps;
- LK.setInterval(function () {
- game.incrementScore(cookiesPerSecond);
- }, 1000);
- };
- // Start generating cookies when a Cursor is created
- self.generateCookies();
- // Display the number of Cursors and the next cost
- self.cursorText = new Text2('Cursors: ' + self.amount + ' - Next Cost: ' + self.cost + ' Cookies', {
- size: 50,
- fill: "#ffffff",
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.cursorText.x = -self.width / 2;
- self.addChild(self.cursorText);
- self.interactive = true;
- self.buttonMode = true;
- self.on('down', self.purchase);
-});
+****/
// ClickableCookie class: Represents the main cookie that players can click/tap to earn cookies.
// It handles the click events and visual feedback for clicking.
var ClickableCookie = Container.expand(function () {
var self = Container.call(this);
@@ -168,54 +56,74 @@
self.currentUpgradeIndex++;
}
};
});
-// Upgrade class: Represents an upgrade that players can purchase to increase their cookie click multiplier.
-// It tracks the upgrade's name, cost, multiplier effect, and the level purchased.
-var Upgrade = Container.expand(function (name, cost, multiplier) {
+// Cursor class: Represents the cursor upgrade that generates cookies per second.
+// It manages its own cost, production rate, and the amount purchased.
+var Cursor = Container.expand(function (initialCost, cps) {
var self = Container.call(this);
- self.name = name; // Name of the upgrade.
- self.cost = cost; // Cost to purchase the upgrade.
- self.multiplier = multiplier; // Multiplier effect of the upgrade.
- self.level = 0; // Level of the upgrade purchased.
- // Display the upgrade information
- self.upgradeText = new Text2(self.name + ': Cost ' + self.cost + ' - Multiplier: ' + self.multiplier, {
- size: 40,
+ self.cost = initialCost; // Initial cost to purchase a cursor.
+ self.cps = cps; // Cookies per second generated by each cursor.
+ self.amount = 0; // Number of cursors purchased.
+ self.purchase = function () {
+ if (game.score >= self.cost) {
+ game.score -= self.cost;
+ self.amount++;
+ self.cost = Math.ceil(self.cost * 1.20); // Increase cost by 20% for the next purchase
+ game.scoreDisplay.scoreText.setText(game.score.toString());
+ // Update the display for the number of Cursors and the next cost
+ self.cursorText.setText('Cursors: ' + self.amount + ' - Next Cost: ' + self.cost + ' Cookies');
+ // Visual feedback for Cursor purchase
+ LK.effects.flashObject(self.cursorText, 0x00ff00, 100);
+ }
+ };
+ self.generateCookies = function () {
+ // Generate cookies from Cursors every second
+ var cookiesPerSecond = self.amount * self.cps;
+ LK.setInterval(function () {
+ game.incrementScore(cookiesPerSecond);
+ }, 1000);
+ };
+ // Start generating cookies when a Cursor is created
+ self.generateCookies();
+ // Display the number of Cursors and the next cost
+ self.cursorText = new Text2('Cursors: ' + self.amount + ' - Next Cost: ' + self.cost + ' Cookies', {
+ size: 50,
fill: "#ffffff",
anchorX: 0.5,
anchorY: 0.5
});
- self.upgradeText.x = -self.width / 2;
- self.addChild(self.upgradeText);
+ self.cursorText.x = -self.width / 2;
+ self.addChild(self.cursorText);
self.interactive = true;
self.buttonMode = true;
- self.on('down', function () {
- if (game.score >= self.cost) {
- game.score -= self.cost;
- game.cookie.setMultiplier(game.cookie.clickMultiplier * self.multiplier);
- self.level++;
- self.cost = Math.ceil(self.cost * 1.20); // Increase cost by 20% for the next level
- game.scoreDisplay.scoreText.setText(game.score.toString());
- // Update the display for the upgrade level and the next cost
- self.upgradeText.setText(self.name + ': Cost ' + self.cost + ' - Multiplier: ' + self.multiplier + ' - Level: ' + self.level);
- // Visual feedback for upgrade purchase
- LK.effects.flashObject(self.upgradeText, 0x00ff00, 100);
- }
+ self.on('down', function (x, y, obj) {
+ obj.event = obj;
+ self.purchase(obj);
});
});
-var ScoreDisplay = Container.expand(function (initialScore) {
+// Check every 5 seconds
+var GoldenCookie = Container.expand(function () {
var self = Container.call(this);
- self.scoreText = new Text2(initialScore.toString(), {
- size: 150,
- fill: "#ffffff",
+ var goldenCookieGraphic = self.attachAsset('cookieGold', {
anchorX: 0.5,
- anchorY: 0
+ anchorY: 0.5
});
- self.updateScore = function (newScore) {
- self.scoreText.setText(newScore.toString());
+ if (!goldenCookieGraphic) {
+ console.error('Failed to load golden cookie asset.');
+ }
+ self.interactive = true;
+ self.buttonMode = true;
+ self.on('down', function () {
+ game.incrementScore(1000); // Bonus score for clicking the golden cookie
+ LK.effects.flashObject(self, 0xffd700, 300);
+ self.destroy();
+ });
+ self.spawn = function () {
+ self.x = Math.random() * (2048 - goldenCookieGraphic.width) + goldenCookieGraphic.width / 2;
+ self.y = Math.random() * (2732 - goldenCookieGraphic.height) + goldenCookieGraphic.height / 2;
+ game.addChild(self);
};
- self.addChild(self.scoreText);
- LK.gui.top.addChild(self);
});
var PrestigeButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphic = self.attachAsset('arrow', {
@@ -267,20 +175,115 @@
});
game.scoreDisplay.updateScore(game.score);
};
});
+var ScoreDisplay = Container.expand(function (initialScore) {
+ var self = Container.call(this);
+ self.scoreText = new Text2(initialScore.toString(), {
+ size: 150,
+ fill: "#ffffff",
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ self.updateScore = function (newScore) {
+ self.scoreText.setText(newScore.toString());
+ };
+ self.addChild(self.scoreText);
+ LK.gui.top.addChild(self);
+});
+// ScrollingContainer class: Manages a container that can scroll vertically to display upgrades.
+// It keeps track of the upgrades added to it and handles the scrolling logic.
+var ScrollingContainer = Container.expand(function () {
+ var self = Container.call(this);
+ self.interactive = true; // Makes the container respond to touch events.
+ self.upgrades = []; // Array to store upgrade elements.
+ self.startY = 0; // Starting Y position for touch events.
+ self.currentScrollY = 0; // Current Y scroll position.
+ self.maxScrollY = 0; // Maximum Y scroll position (top limit).
+ self.minScrollY = 0; // Minimum Y scroll position (bottom limit).
+ self.on('down', function (x, y, obj) {
+ if (!obj.data) {
+ console.error('Touch event data is missing.');
+ return;
+ }
+ self.startY = obj.data.global.y;
+ });
+ self.on('move', function (x, y, obj) {
+ if (!obj.data || !obj.data.global) {
+ console.error('Touch event data is missing or incomplete.');
+ return;
+ }
+ var newY = obj.data.global.y;
+ var deltaY = newY - self.startY;
+ self.startY = newY;
+ self.currentScrollY += deltaY;
+ self.currentScrollY = Math.min(self.currentScrollY, self.minScrollY);
+ self.currentScrollY = Math.max(self.currentScrollY, self.maxScrollY);
+ self.upgrades.forEach(function (upgrade) {
+ upgrade.y += deltaY;
+ });
+ });
+ self.addUpgrade = function (upgrade) {
+ self.upgrades.push(upgrade);
+ self.addChild(upgrade);
+ self.maxScrollY = Math.min(self.maxScrollY, -upgrade.y + 200);
+ self.minScrollY = 0;
+ };
+ self.scroll = function (direction) {
+ var scrollAmount = 300 * direction;
+ self.currentScrollY += scrollAmount;
+ self.currentScrollY = Math.min(self.currentScrollY, self.minScrollY);
+ self.currentScrollY = Math.max(self.currentScrollY, self.maxScrollY);
+ self.upgrades.forEach(function (upgrade) {
+ upgrade.y -= scrollAmount;
+ });
+ };
+});
+// Upgrade class: Represents an upgrade that players can purchase to increase their cookie click multiplier.
+// It tracks the upgrade's name, cost, multiplier effect, and the level purchased.
+var Upgrade = Container.expand(function (name, cost, multiplier) {
+ var self = Container.call(this);
+ self.name = name; // Name of the upgrade.
+ self.cost = cost; // Cost to purchase the upgrade.
+ self.multiplier = multiplier; // Multiplier effect of the upgrade.
+ self.level = 0; // Level of the upgrade purchased.
+ // Display the upgrade information
+ self.upgradeText = new Text2(self.name + ': Cost ' + self.cost + ' - Multiplier: ' + self.multiplier, {
+ size: 40,
+ fill: "#ffffff",
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.upgradeText.x = -self.width / 2;
+ self.addChild(self.upgradeText);
+ self.interactive = true;
+ self.buttonMode = true;
+ self.on('down', function () {
+ if (game.score >= self.cost) {
+ game.score -= self.cost;
+ game.cookie.setMultiplier(game.cookie.clickMultiplier * self.multiplier);
+ self.level++;
+ self.cost = Math.ceil(self.cost * 1.20); // Increase cost by 20% for the next level
+ game.scoreDisplay.scoreText.setText(game.score.toString());
+ // Update the display for the upgrade level and the next cost
+ self.upgradeText.setText(self.name + ': Cost ' + self.cost + ' - Multiplier: ' + self.multiplier + ' - Level: ' + self.level);
+ // Visual feedback for upgrade purchase
+ LK.effects.flashObject(self.upgradeText, 0x00ff00, 100);
+ }
+ });
+});
/****
* Initialize Game
-****/
+****/
// Initialize the score display with a score of 0
var game = new LK.Game({
backgroundColor: 0x476cd0
});
/****
* Game Code
-****/
+****/
game.prestigeManager = game.addChild(new PrestigeManager());
game.cookieUpgradeManager = game.addChild(new CookieUpgradeManager());
game.prestigeButton = game.addChild(new PrestigeButton());
LK.setInterval(function () {
@@ -400,10 +403,10 @@
}
});
}
game.unlockUpgrades = unlockUpgrades;
-game.on('down', function (obj) {
- var pos = obj.event.getLocalPosition(game);
+game.on('down', function (x, y, obj) {
+ var pos = game.toLocal(obj.global);
if (pos.y > 2732 - 300) {
game.upgradeContainer.scroll(-1);
} else if (pos.y < 300) {
game.upgradeContainer.scroll(1);