/****
* Classes
****/
var Cursor = Container.expand(function (initialCost, cps) {
var self = Container.call(this);
self.cost = initialCost;
self.cps = cps; // cookies per second
self.amount = 0;
self.purchase = function () {
if (game.score >= self.cost) {
game.score -= self.cost;
self.amount++;
self.cost = Math.ceil(self.cost * 1.15); // Increase cost by 15% for the next purchase
game.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);
});
var ClickableCookie = Container.expand(function () {
var self = Container.call(this);
var cookieGraphic = self.attachAsset('cookie', {
anchorX: 0.5,
anchorY: 0.5
});
self.interactive = true;
self.buttonMode = true;
self.clickMultiplier = 2;
self.on('down', function () {
game.incrementScore(self.clickMultiplier);
// Visual feedback for cookie click
LK.effects.flashObject(self, 0xffff00, 100);
self.scaleX = 1.1;
self.scaleY = 1.1;
LK.setTimeout(function () {
self.scaleX = 1;
self.scaleY = 1;
}, 100);
// Sound functionality is not available
});
self.setMultiplier = function (multiplier) {
self.clickMultiplier = multiplier;
};
});
var Upgrade = Container.expand(function (name, cost, multiplier) {
var self = Container.call(this);
self.name = name;
self.cost = cost;
self.multiplier = multiplier;
self.level = 0;
// Display the upgrade information
self.upgradeText = new Text2(self.name + ': Cost ' + self.cost + ' - Multiplier: ' + self.multiplier, {
size: 50,
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.15); // Increase cost by 15% for the next level
game.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
****/
var game = new LK.Game({
backgroundColor: 0x476cd0
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
}));
game.score = 0;
game.cursor = game.addChild(new Cursor(10, 2)); // Initial cost: 10, Initial cookies per second: 2
game.cursor.x = 2048 / 2 - 150;
game.cursor.y = 2732 / 2 - 300;
game.cookie = game.addChild(new ClickableCookie());
game.cookie.x = 2048 / 2;
game.cookie.y = 2732 / 2;
game.scoreText = new Text2('0', {
size: 150,
fill: "#ffffff",
anchorX: 0.5,
anchorY: 0
});
LK.gui.top.addChild(game.scoreText);
game.incrementScore = function (amount) {
amount = amount || 1;
game.score += amount;
game.scoreText.setText(game.score.toString());
game.unlockUpgrades();
};
var upgrades = [{}, {
name: 'Sprinkle Spritzer',
cost: 10,
multiplier: 2,
level: 0
}, {
name: 'Choco-Mixer',
cost: 50,
multiplier: 5,
level: 0
}, {
name: 'Caramelizer',
cost: 100,
multiplier: 10,
level: 0
}, {
name: 'Jelly Jamboree',
cost: 200,
multiplier: 20,
level: 0
}, {
name: 'Muffin Master',
cost: 500,
multiplier: 50,
level: 0
}, {
name: 'Cookie Treehouse',
cost: 1000,
multiplier: 100,
level: 0
}, {
name: 'Quantum Doughinator',
cost: 2000,
multiplier: 200,
level: 0
}, {
name: 'Galactic Ovenlord',
cost: 5000,
multiplier: 500,
level: 0
}];
game.availableUpgrades = [];
game.unlockUpgrades = function () {
upgrades.forEach(function (upgrade, index) {
if (game.score >= upgrade.cost / 2 && !game.availableUpgrades.some(function (u) {
return u.name === upgrade.name;
})) {
var upgradeInstance = new Upgrade(upgrade.name, upgrade.cost, upgrade.multiplier);
game.availableUpgrades.push(upgradeInstance);
upgradeInstance.x = 150;
upgradeInstance.y = 2732 / 2 + 150 * game.availableUpgrades.length;
game.addChild(upgradeInstance);
}
});
};
game.unlockUpgrades();