User prompt
Move upgrades to opposite side
User prompt
Change background to blue
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var farmGraphics = self.attachAsset('Farm', {' Line Number: 50
User prompt
Make farm asset an upgrade
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'self.attachAsset('Farm', {' Line Number: 50
User prompt
Change farms upgrade to farm asset
User prompt
Add new upgrade called farm that costs 500 cookies and gose up 20% every time you purchase the upgrade
User prompt
Remove one upgrade level
User prompt
Make the upgrade price go up by 20% each time you buy
User prompt
Make it so that the upgrade can. Be bought multiple times
Initial prompt
Cookie clicker
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Cookie class to represent the clickable cookie
var Cookie = Container.expand(function () {
var self = Container.call(this);
var cookieGraphics = self.attachAsset('cookie', {
anchorX: 0.5,
anchorY: 0.5
});
// Event handler for clicking the cookie
self.down = function (x, y, obj) {
// Increase the cookie count
game.cookieCount += game.cookiesPerClick;
game.updateScore();
};
});
// Upgrade class to represent purchasable upgrades
var Upgrade = Container.expand(function (name, cost, cpsIncrease) {
var self = Container.call(this);
self.name = name;
self.cost = cost;
self.cpsIncrease = cpsIncrease;
var upgradeGraphics = self.attachAsset('upgrade', {
anchorX: 0.5,
anchorY: 0.5
});
// Event handler for purchasing the upgrade
self.down = function (x, y, obj) {
if (game.cookieCount >= self.cost) {
game.cookieCount -= self.cost;
game.cookiesPerSecond += self.cpsIncrease;
game.updateScore();
// Do not destroy the upgrade after purchase
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game variables
game.cookieCount = 0;
game.cookiesPerClick = 1;
game.cookiesPerSecond = 0;
// Create and position the cookie
var cookie = new Cookie();
cookie.x = 2048 / 2;
cookie.y = 2732 / 2;
game.addChild(cookie);
// Create and position upgrades
var upgrades = [];
var upgrade1 = new Upgrade('Grandma', 100, 1);
upgrade1.x = 300;
upgrade1.y = 500;
upgrades.push(upgrade1);
game.addChild(upgrade1);
var upgrade2 = new Upgrade('Factory', 500, 5);
upgrade2.x = 300;
upgrade2.y = 700;
upgrades.push(upgrade2);
game.addChild(upgrade2);
// Create and display the score text
var scoreTxt = new Text2('Cookies: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to update the score display
game.updateScore = function () {
scoreTxt.setText('Cookies: ' + game.cookieCount);
};
// Update function to handle cookies per second
game.update = function () {
if (LK.ticks % 60 == 0) {
// Every second
game.cookieCount += game.cookiesPerSecond;
game.updateScore();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,54 +1,54 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Cookie class to represent the clickable cookie
var Cookie = Container.expand(function () {
- var self = Container.call(this);
- var cookieGraphics = self.attachAsset('cookie', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Event handler for clicking the cookie
- self.down = function (x, y, obj) {
- // Increase the cookie count
- game.cookieCount += game.cookiesPerClick;
- game.updateScore();
- };
+ var self = Container.call(this);
+ var cookieGraphics = self.attachAsset('cookie', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Event handler for clicking the cookie
+ self.down = function (x, y, obj) {
+ // Increase the cookie count
+ game.cookieCount += game.cookiesPerClick;
+ game.updateScore();
+ };
});
// Upgrade class to represent purchasable upgrades
var Upgrade = Container.expand(function (name, cost, cpsIncrease) {
- var self = Container.call(this);
- self.name = name;
- self.cost = cost;
- self.cpsIncrease = cpsIncrease;
- var upgradeGraphics = self.attachAsset('upgrade', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Event handler for purchasing the upgrade
- self.down = function (x, y, obj) {
- if (game.cookieCount >= self.cost) {
- game.cookieCount -= self.cost;
- game.cookiesPerSecond += self.cpsIncrease;
- game.updateScore();
- self.destroy(); // Remove the upgrade after purchase
- }
- };
+ var self = Container.call(this);
+ self.name = name;
+ self.cost = cost;
+ self.cpsIncrease = cpsIncrease;
+ var upgradeGraphics = self.attachAsset('upgrade', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Event handler for purchasing the upgrade
+ self.down = function (x, y, obj) {
+ if (game.cookieCount >= self.cost) {
+ game.cookieCount -= self.cost;
+ game.cookiesPerSecond += self.cpsIncrease;
+ game.updateScore();
+ // Do not destroy the upgrade after purchase
+ }
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize game variables
game.cookieCount = 0;
game.cookiesPerClick = 1;
game.cookiesPerSecond = 0;
@@ -70,21 +70,21 @@
upgrades.push(upgrade2);
game.addChild(upgrade2);
// Create and display the score text
var scoreTxt = new Text2('Cookies: 0', {
- size: 100,
- fill: 0xFFFFFF
+ size: 100,
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to update the score display
game.updateScore = function () {
- scoreTxt.setText('Cookies: ' + game.cookieCount);
+ scoreTxt.setText('Cookies: ' + game.cookieCount);
};
// Update function to handle cookies per second
game.update = function () {
- if (LK.ticks % 60 == 0) {
- // Every second
- game.cookieCount += game.cookiesPerSecond;
- game.updateScore();
- }
+ if (LK.ticks % 60 == 0) {
+ // Every second
+ game.cookieCount += game.cookiesPerSecond;
+ game.updateScore();
+ }
};
\ No newline at end of file