/****
* Classes
****/
// Pizza class
var Pizza = Container.expand(function () {
var self = Container.call(this);
var pizzaGraphics = self.createAsset('pizza', 'Clickable pizza', 0.5, 0.5);
self.onClick = function () {
// Trigger the animation
self.animateClick();
};
self.animateClick = function () {
var originalY = self.y;
var moveDistance = 10; // Distance to move the pizza
var moveDuration = 5; // Duration of the move in frames
var currentFrame = 0;
// Function to handle the animation each frame
var animate = function animate() {
if (currentFrame < moveDuration) {
self.y = originalY - moveDistance * (currentFrame / moveDuration);
currentFrame++;
} else if (currentFrame < moveDuration * 2) {
self.y = originalY - moveDistance * (1 - (currentFrame - moveDuration) / moveDuration);
currentFrame++;
} else {
self.y = originalY; // Reset to original position
LK.removeListener('tick', animate); // Stop the animation
}
};
// Start the animation
LK.on('tick', animate);
};
});
// Score class
var Score = Container.expand(function () {
var self = Container.call(this);
var scoreText = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0);
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText(newScore.toString());
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black 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 += 1; // Increment score by $1 per click
score.updateScore(currentScore);
};
// Add event listener for pizza clicks
pizza.on('down', function (obj) {
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
@@ -1,37 +1,59 @@
-/****
+/****
* Classes
****/
// Pizza class
var Pizza = Container.expand(function () {
- var self = Container.call(this);
- var pizzaGraphics = self.createAsset('pizza', 'Clickable pizza', 0.5, 0.5);
- self.onClick = function () {
- // Placeholder for click functionality
- };
+ var self = Container.call(this);
+ var pizzaGraphics = self.createAsset('pizza', 'Clickable pizza', 0.5, 0.5);
+ self.onClick = function () {
+ // Trigger the animation
+ self.animateClick();
+ };
+ self.animateClick = function () {
+ var originalY = self.y;
+ var moveDistance = 10; // Distance to move the pizza
+ var moveDuration = 5; // Duration of the move in frames
+ var currentFrame = 0;
+ // Function to handle the animation each frame
+ var animate = function animate() {
+ if (currentFrame < moveDuration) {
+ self.y = originalY - moveDistance * (currentFrame / moveDuration);
+ currentFrame++;
+ } else if (currentFrame < moveDuration * 2) {
+ self.y = originalY - moveDistance * (1 - (currentFrame - moveDuration) / moveDuration);
+ currentFrame++;
+ } else {
+ self.y = originalY; // Reset to original position
+ LK.removeListener('tick', animate); // Stop the animation
+ }
+ };
+ // Start the animation
+ LK.on('tick', animate);
+ };
});
// Score class
var Score = Container.expand(function () {
- var self = Container.call(this);
- var scoreText = new Text2('0', {
- size: 150,
- fill: "#ffffff"
- });
- scoreText.anchor.set(0.5, 0);
- self.addChild(scoreText);
- self.updateScore = function (newScore) {
- scoreText.setText(newScore.toString());
- };
+ var self = Container.call(this);
+ var scoreText = new Text2('0', {
+ size: 150,
+ fill: "#ffffff"
+ });
+ scoreText.anchor.set(0.5, 0);
+ self.addChild(scoreText);
+ self.updateScore = function (newScore) {
+ scoreText.setText(newScore.toString());
+ };
});
-/****
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
****/
// Initialize pizza
var pizza = game.addChild(new Pizza());
@@ -44,16 +66,16 @@
// Initialize game variables
var currentScore = 0;
// Update the score when the pizza is clicked
pizza.onClick = function () {
- currentScore += 1; // Increment score by $1 per click
- score.updateScore(currentScore);
+ currentScore += 1; // Increment score by $1 per click
+ score.updateScore(currentScore);
};
// Add event listener for pizza clicks
pizza.on('down', function (obj) {
- pizza.onClick();
+ 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
+ // Game logic goes here
+ // In this simple game, the tick event is not used, but it's here for future game logic
});
\ No newline at end of file
a pepperoni pizza. In-Game asset. 2d. Blank background. High contrast.
a button saying 'upgrade'. In-Game asset. 2d. Blank background. High contrast.
a button saying 'reset'. In-Game asset. 2d. Blank background. High contrast.
a button saying 'autoclicker'. In-Game asset. 2d. Blank background. High contrast.