/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var FoodItem = Container.expand(function (foodType) { var self = Container.call(this); self.foodType = foodType; self.isGoodFood = foodType !== 'tomato'; var foodGraphics = self.attachAsset(foodType, { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { if (self.isGoodFood) { // Good food - Buzzy says yup and gets happy LK.getSound('yup').play(); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Happy animation for Buzzy tween(buzzy, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200 }); tween(buzzy, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200 }); // Food eaten animation tween(self, { alpha: 0, scaleX: 0.5, scaleY: 0.5 }, { duration: 300, onFinish: function onFinish() { self.destroy(); removeFoodFromArray(self); } }); } else { // Bad food - Buzzy cries LK.getSound('cry').play(); // Sad animation for Buzzy tween(buzzy, { tint: 0xff6666 }, { duration: 300 }); tween(buzzy, { tint: 0xffb84d }, { duration: 300 }); // Remove tomato tween(self, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.destroy(); removeFoodFromArray(self); } }); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ var buzzy; var foodItems = []; var scoreTxt; var foodTypes = ['carrot', 'cheese', 'egg', 'orange', 'banana', 'tomato']; var spawnTimer = 0; var spawnInterval = 120; // Spawn food every 2 seconds at 60fps // Create Buzzy character buzzy = game.addChild(LK.getAsset('buzzy', { anchorX: 0.5, anchorY: 0.5 })); buzzy.x = 1024; // Center horizontally buzzy.y = 600; // Upper portion of screen // Create score display scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); scoreTxt.y = 120; // Move down from very top to avoid menu // Function to remove food from array function removeFoodFromArray(food) { var index = foodItems.indexOf(food); if (index > -1) { foodItems.splice(index, 1); } } // Function to spawn food function spawnFood() { var foodType = foodTypes[Math.floor(Math.random() * foodTypes.length)]; var food = new FoodItem(foodType); // Random position in lower area of screen food.x = Math.random() * (2048 - 200) + 100; food.y = Math.random() * (1500 - 1000) + 1000; game.addChild(food); foodItems.push(food); // Food appears with a pop animation food.scaleX = 0; food.scaleY = 0; tween(food, { scaleX: 1, scaleY: 1 }, { duration: 300, easing: tween.elasticOut }); } // Function to clean up old food items function cleanupOldFood() { for (var i = foodItems.length - 1; i >= 0; i--) { var food = foodItems[i]; // Remove food after 5 seconds if not touched if (LK.ticks - food.spawnTime > 300) { // 5 seconds at 60fps tween(food, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { food.destroy(); foodItems.splice(i, 1); } }); } } } // Initial spawn spawnFood(); game.update = function () { spawnTimer++; // Spawn new food periodically if (spawnTimer >= spawnInterval) { spawnFood(); spawnTimer = 0; // Gradually increase spawn rate if (spawnInterval > 60) { spawnInterval -= 1; } } // Mark spawn time for cleanup for (var i = 0; i < foodItems.length; i++) { if (foodItems[i].spawnTime === undefined) { foodItems[i].spawnTime = LK.ticks; } } // Clean up old food items every 3 seconds if (LK.ticks % 180 === 0) { cleanupOldFood(); } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,177 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var FoodItem = Container.expand(function (foodType) {
+ var self = Container.call(this);
+ self.foodType = foodType;
+ self.isGoodFood = foodType !== 'tomato';
+ var foodGraphics = self.attachAsset(foodType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.down = function (x, y, obj) {
+ if (self.isGoodFood) {
+ // Good food - Buzzy says yup and gets happy
+ LK.getSound('yup').play();
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ // Happy animation for Buzzy
+ tween(buzzy, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200
+ });
+ tween(buzzy, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200
+ });
+ // Food eaten animation
+ tween(self, {
+ alpha: 0,
+ scaleX: 0.5,
+ scaleY: 0.5
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ self.destroy();
+ removeFoodFromArray(self);
+ }
+ });
+ } else {
+ // Bad food - Buzzy cries
+ LK.getSound('cry').play();
+ // Sad animation for Buzzy
+ tween(buzzy, {
+ tint: 0xff6666
+ }, {
+ duration: 300
+ });
+ tween(buzzy, {
+ tint: 0xffb84d
+ }, {
+ duration: 300
+ });
+ // Remove tomato
+ tween(self, {
+ alpha: 0
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ self.destroy();
+ removeFoodFromArray(self);
+ }
+ });
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87ceeb
+});
+
+/****
+* Game Code
+****/
+var buzzy;
+var foodItems = [];
+var scoreTxt;
+var foodTypes = ['carrot', 'cheese', 'egg', 'orange', 'banana', 'tomato'];
+var spawnTimer = 0;
+var spawnInterval = 120; // Spawn food every 2 seconds at 60fps
+// Create Buzzy character
+buzzy = game.addChild(LK.getAsset('buzzy', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+buzzy.x = 1024; // Center horizontally
+buzzy.y = 600; // Upper portion of screen
+// Create score display
+scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+scoreTxt.y = 120; // Move down from very top to avoid menu
+// Function to remove food from array
+function removeFoodFromArray(food) {
+ var index = foodItems.indexOf(food);
+ if (index > -1) {
+ foodItems.splice(index, 1);
+ }
+}
+// Function to spawn food
+function spawnFood() {
+ var foodType = foodTypes[Math.floor(Math.random() * foodTypes.length)];
+ var food = new FoodItem(foodType);
+ // Random position in lower area of screen
+ food.x = Math.random() * (2048 - 200) + 100;
+ food.y = Math.random() * (1500 - 1000) + 1000;
+ game.addChild(food);
+ foodItems.push(food);
+ // Food appears with a pop animation
+ food.scaleX = 0;
+ food.scaleY = 0;
+ tween(food, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 300,
+ easing: tween.elasticOut
+ });
+}
+// Function to clean up old food items
+function cleanupOldFood() {
+ for (var i = foodItems.length - 1; i >= 0; i--) {
+ var food = foodItems[i];
+ // Remove food after 5 seconds if not touched
+ if (LK.ticks - food.spawnTime > 300) {
+ // 5 seconds at 60fps
+ tween(food, {
+ alpha: 0
+ }, {
+ duration: 500,
+ onFinish: function onFinish() {
+ food.destroy();
+ foodItems.splice(i, 1);
+ }
+ });
+ }
+ }
+}
+// Initial spawn
+spawnFood();
+game.update = function () {
+ spawnTimer++;
+ // Spawn new food periodically
+ if (spawnTimer >= spawnInterval) {
+ spawnFood();
+ spawnTimer = 0;
+ // Gradually increase spawn rate
+ if (spawnInterval > 60) {
+ spawnInterval -= 1;
+ }
+ }
+ // Mark spawn time for cleanup
+ for (var i = 0; i < foodItems.length; i++) {
+ if (foodItems[i].spawnTime === undefined) {
+ foodItems[i].spawnTime = LK.ticks;
+ }
+ }
+ // Clean up old food items every 3 seconds
+ if (LK.ticks % 180 === 0) {
+ cleanupOldFood();
+ }
+};
\ No newline at end of file