/**** * Classes ****/ // AutoClicker class var AutoClicker = Container.expand(function () { var self = Container.call(this); self.startAutoClicking = function () { LK.setInterval(function () { if (self.autoClickerCount > 0) { pizza.onClick(); // Simulate a pizza click } }, 1000 / self.autoClickerCount); // Click once per second per auto clicker }; var autoClickerGraphics = self.attachAsset('autoClicker', { anchorX: 0.5, anchorY: 0.5 }); self.cost = 100; // Initial cost of the auto clicker self.autoClickerCount = 0; self.onClick = function () { LK.getSound('clickSound').play(); if (currentScore >= self.cost) { currentScore -= self.cost; // Deduct the cost from the current score score.updateScore(currentScore); // Update the score display self.autoClickerCount += 1; // Increase the number of auto clickers self.startAutoClicking(); // Start auto clicking self.cost *= 3; // Triple the cost for the next auto clicker autoClickerText.setText('Auto Clicker: $' + self.cost); // Update the auto clicker text } else { LK.getSound('errorSound').play(); } }; var autoClickerText = new Text2('Auto Clicker: $' + self.cost, { size: 100, fill: 0xFFFFFF }); autoClickerText.anchor.set(0.5, 0); self.addChild(autoClickerText); }); // Pizza class var Pizza = Container.expand(function () { var self = Container.call(this); var pizzaGraphics = self.attachAsset('pizza', { anchorX: 0.5, anchorY: 0.5 }); self.onClick = function () { LK.getSound('pizza').play(); var originalScale = self.scale.x; var scaleDown = 0.9; var scaleDuration = 5; // Duration of the scale animation in frames var currentFrame = 0; // Function to handle the scale animation each frame var animateScale = function animateScale() { if (currentFrame < scaleDuration) { // Scale down self.scale.x = self.scale.y = originalScale - (originalScale - scaleDown) * (currentFrame / scaleDuration); } else if (currentFrame < scaleDuration * 2) { // Scale up self.scale.x = self.scale.y = scaleDown + (originalScale - scaleDown) * ((currentFrame - scaleDuration) / scaleDuration); } else { // Reset to original scale self.scale.x = self.scale.y = originalScale; LK.removeListener('tick', animateScale); // Stop the scale animation } currentFrame++; }; // Start the scale animation LK.on('tick', animateScale); }; }); // ResetButton class var ResetButton = Container.expand(function () { var self = Container.call(this); var resetButtonGraphics = self.attachAsset('resetButton', { anchorX: 0.5, anchorY: 0.5 }); var resetButtonText = new Text2('Reset Game', { size: 100, fill: 0xFFFFFF }); resetButtonText.anchor.set(0.5, 0); self.addChild(resetButtonText); self.on('down', function () { // Flash screen red for 1 second (1000ms) to show game reset LK.effects.flashScreen(0xff0000, 1000); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state. }); }); // Score class var Score = Container.expand(function () { var self = Container.call(this); var scoreText = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText('$' + newScore.toString()); }; }); // Upgrade class var Upgrade = Container.expand(function () { var self = Container.call(this); var upgradeGraphics = self.attachAsset('upgrade', { anchorX: 0.5, anchorY: 0.5 }); self.cost = 10; // Initial cost of the upgrade self.multiplier = 1; // Score multiplier self.updateCost = function () { self.cost *= 2; // Double the cost for the next upgrade }; self.increaseMultiplier = function () { self.multiplier += 1; // Increase the multiplier by 1 }; var upgradeText = new Text2('Upgrade: $' + self.cost, { size: 100, fill: 0xFFFFFF }); upgradeText.anchor.set(0.5, 0); self.addChild(upgradeText); self.updateUpgradeText = function () { upgradeText.setText('Upgrade: $' + self.cost); }; self.onClick = function () { LK.getSound('clickSound').play(); if (currentScore >= self.cost) { currentScore -= self.cost; // Deduct the cost from the current score score.updateScore(currentScore); // Update the score display self.updateCost(); // Update the cost for the next upgrade self.increaseMultiplier(); // Increase the score multiplier self.updateUpgradeText(); // Update the upgrade text } else { LK.getSound('errorSound').play(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xADD8E6 // Init game with light blue background }); /**** * Game Code ****/ // Initialize pizza var pizza = game.addChild(new Pizza()); pizza.x = 2048 / 2; pizza.y = 2732 / 2; // Initialize score var score = game.addChild(new Score()); score.x = 2048 / 2; score.y = 100; // Position score at the top center // Initialize game variables var currentScore = 0; // Update the score when the pizza is clicked pizza.onClick = function () { currentScore += upgrade.multiplier; // Increment score by the upgrade multiplier per click score.updateScore(currentScore); }; // Initialize upgrade var upgrade = game.addChild(new Upgrade()); upgrade.x = 2048 / 2 - 300; upgrade.y = 2732 - 300; // Position upgrade button at the bottom center // Initialize auto clicker var autoClicker = game.addChild(new AutoClicker()); autoClicker.x = upgrade.x + upgrade.width + 200; // Position auto clicker button with increased distance to the right of the upgrade button autoClicker.y = upgrade.y; // Add event listener for auto clicker clicks autoClicker.on('down', function (x, y, obj) { autoClicker.onClick(); }); // Add event listener for upgrade clicks // Initialize reset button var resetButton = game.addChild(new ResetButton()); resetButton.x = 2048 - resetButton.width / 2; resetButton.y = resetButton.height / 2 + 100; // Position reset button at the top right corner upgrade.on('down', function (x, y, obj) { upgrade.onClick(); }); pizza.on('down', function (x, y, obj) { LK.getSound('pizza').play(); pizza.onClick(); }); // Main game tick event LK.on('tick', function () { // Game logic goes here // In this simple game, the tick event is not used, but it's here for future game logic });
===================================================================
--- original.js
+++ change.js
@@ -101,24 +101,8 @@
self.updateScore = function (newScore) {
scoreText.setText('$' + newScore.toString());
};
});
-// Star class
-var Star = Container.expand(function () {
- var self = Container.call(this);
- var starGraphics = self.attachAsset('star', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = Math.random() * 5 + 2; // Random speed between 2 and 7
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732) {
- self.y = -starGraphics.height;
- self.x = Math.random() * 2048;
- }
- };
-});
// Upgrade class
var Upgrade = Container.expand(function () {
var self = Container.call(this);
var upgradeGraphics = self.attachAsset('upgrade', {
@@ -165,23 +149,8 @@
/****
* Game Code
****/
-// Initialize stars
-var stars = [];
-for (var i = 0; i < 5; i++) {
- var star = new Star();
- star.x = Math.random() * 2048;
- star.y = Math.random() * 2732;
- stars.push(star);
- game.addChild(star);
-}
-// Update stars every tick
-game.update = function () {
- for (var i = 0; i < stars.length; i++) {
- stars[i].update();
- }
-};
// Initialize pizza
var pizza = game.addChild(new Pizza());
pizza.x = 2048 / 2;
pizza.y = 2732 / 2;