/**** * Classes ****/ // Class for Cooking Pot var CookingPot = Container.expand(function () { var self = Container.call(this); var potGraphics = self.attachAsset('cookingPot', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for cooking pot if needed }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for Ingredients var Ingredient = Container.expand(function () { var self = Container.call(this); var ingredientGraphics = self.attachAsset('ingredient', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for ingredients if needed }; }); // Class for Score Display var ScoreDisplay = Container.expand(function () { var self = Container.call(this); var scoreText = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); self.addChild(scoreText); self.updateScore = function (score) { scoreText.setText('Score: ' + score); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize game variables var ingredients = []; var score = 0; var cookingPot = game.addChild(new CookingPot()); var scoreDisplay = LK.gui.top.addChild(new ScoreDisplay()); // Position the cooking pot at the bottom center of the screen cookingPot.x = 2048 / 2; cookingPot.y = 2732 - 200; // Function to spawn a new ingredient function spawnIngredient() { var ingredient = new Ingredient(); ingredient.x = Math.random() * 2048; ingredient.y = 0; ingredients.push(ingredient); game.addChild(ingredient); } // Function to update the game state game.update = function () { // Move ingredients down the screen for (var i = ingredients.length - 1; i >= 0; i--) { var ingredient = ingredients[i]; ingredient.y += 5; // Move down by 5 pixels per frame // Check if ingredient intersects with the cooking pot if (ingredient.intersects(cookingPot)) { score += 10; scoreDisplay.updateScore(score); ingredient.destroy(); ingredients.splice(i, 1); } else if (ingredient.y > 2732) { // Remove ingredient if it goes off screen ingredient.destroy(); ingredients.splice(i, 1); } } // Spawn a new ingredient every 60 frames if (LK.ticks % 60 === 0) { spawnIngredient(); } };
===================================================================
--- original.js
+++ change.js
@@ -1,55 +1,55 @@
-/****
+/****
* Classes
-****/
+****/
// Class for Cooking Pot
var CookingPot = Container.expand(function () {
- var self = Container.call(this);
- var potGraphics = self.attachAsset('cookingPot', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Update logic for cooking pot if needed
- };
+ var self = Container.call(this);
+ var potGraphics = self.attachAsset('cookingPot', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Update logic for cooking pot if needed
+ };
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for Ingredients
var Ingredient = Container.expand(function () {
- var self = Container.call(this);
- var ingredientGraphics = self.attachAsset('ingredient', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Update logic for ingredients if needed
- };
+ var self = Container.call(this);
+ var ingredientGraphics = self.attachAsset('ingredient', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Update logic for ingredients if needed
+ };
});
// Class for Score Display
var ScoreDisplay = Container.expand(function () {
- var self = Container.call(this);
- var scoreText = new Text2('Score: 0', {
- size: 100,
- fill: 0xFFFFFF
- });
- scoreText.anchor.set(0.5, 0);
- self.addChild(scoreText);
- self.updateScore = function (score) {
- scoreText.setText('Score: ' + score);
- };
+ var self = Container.call(this);
+ var scoreText = new Text2('Score: 0', {
+ size: 100,
+ fill: 0xFFFFFF
+ });
+ scoreText.anchor.set(0.5, 0);
+ self.addChild(scoreText);
+ self.updateScore = function (score) {
+ scoreText.setText('Score: ' + score);
+ };
});
-/****
+/****
* 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
var ingredients = [];
var score = 0;
var cookingPot = game.addChild(new CookingPot());
@@ -58,35 +58,33 @@
cookingPot.x = 2048 / 2;
cookingPot.y = 2732 - 200;
// Function to spawn a new ingredient
function spawnIngredient() {
- var ingredient = new Ingredient();
- ingredient.x = Math.random() * 2048;
- ingredient.y = 0;
- ingredients.push(ingredient);
- game.addChild(ingredient);
+ var ingredient = new Ingredient();
+ ingredient.x = Math.random() * 2048;
+ ingredient.y = 0;
+ ingredients.push(ingredient);
+ game.addChild(ingredient);
}
// Function to update the game state
game.update = function () {
- // Move ingredients down the screen
- for (var i = ingredients.length - 1; i >= 0; i--) {
- var ingredient = ingredients[i];
- ingredient.y += 5; // Move down by 5 pixels per frame
- // Check if ingredient intersects with the cooking pot
- if (ingredient.intersects(cookingPot)) {
- score += 10;
- scoreDisplay.updateScore(score);
- ingredient.destroy();
- ingredients.splice(i, 1);
- } else if (ingredient.y > 2732) {
- // Remove ingredient if it goes off screen
- ingredient.destroy();
- ingredients.splice(i, 1);
- }
- }
- // Spawn a new ingredient every 60 frames
- if (LK.ticks % 60 === 0) {
- spawnIngredient();
- }
-};
-// Start the game
-game.start();
\ No newline at end of file
+ // Move ingredients down the screen
+ for (var i = ingredients.length - 1; i >= 0; i--) {
+ var ingredient = ingredients[i];
+ ingredient.y += 5; // Move down by 5 pixels per frame
+ // Check if ingredient intersects with the cooking pot
+ if (ingredient.intersects(cookingPot)) {
+ score += 10;
+ scoreDisplay.updateScore(score);
+ ingredient.destroy();
+ ingredients.splice(i, 1);
+ } else if (ingredient.y > 2732) {
+ // Remove ingredient if it goes off screen
+ ingredient.destroy();
+ ingredients.splice(i, 1);
+ }
+ }
+ // Spawn a new ingredient every 60 frames
+ if (LK.ticks % 60 === 0) {
+ spawnIngredient();
+ }
+};
\ No newline at end of file