User prompt
Delete mango tree and assets
User prompt
Please fix the bug: 'ReferenceError: mangoTree is not defined' in or related to this line: 'newMango.x = mangoTree.x;' Line Number: 64
User prompt
Delete mango tree
User prompt
Please fix the bug: 'ReferenceError: mangoTree is not defined' in or related to this line: 'newMango.x = mangoTree.x;' Line Number: 64
User prompt
Delete mango tree
User prompt
I control my player with touch
User prompt
Big mango tree in background
Initial prompt
Mango & Monkey
/**** * Classes ****/ // Create a class for the mango var Mango = Container.expand(function () { var self = Container.call(this); var mangoGraphics = self.attachAsset('mango', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // The mango's movement logic will be implemented here }; }); // The assets will be automatically created and loaded by the LK engine // Create a class for the monkey var Monkey = Container.expand(function () { var self = Container.call(this); var monkeyGraphics = self.attachAsset('monkey', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // The monkey's movement logic will be implemented here }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFFFFF // Init game with white background }); /**** * Game Code ****/ // Initialize the monkey and the mango tree var monkey = game.addChild(new Monkey()); monkey.x = 1024; // Position the monkey at the center of the screen monkey.y = 2732 - monkey.height; // Position the monkey at the bottom of the screen // Add touch control to the monkey game.down = function (x, y, obj) { monkey.x = x; }; game.move = function (x, y, obj) { monkey.x = x; }; var mangoTree = game.attachAsset('mangoTree', { anchorX: 0.5, anchorY: 1 }); mangoTree.x = 1024; // Position the mango tree at the center of the screen mangoTree.y = 2732; // Position the mango tree at the bottom of the screen mangoTree.scaleX = 1.5; // Increase the size of the mango tree mangoTree.scaleY = 1.5; // Increase the size of the mango tree // Initialize the array of mangos and the missed mangos counter var mangos = []; var missedMangos = 0; // Implement the game logic game.update = function () { // Generate a new mango every 60 frames (1 second) if (LK.ticks % 60 == 0) { var newMango = new Mango(); newMango.x = mangoTree.x; newMango.y = mangoTree.y - mangoTree.height; mangos.push(newMango); game.addChild(newMango); } // Update the mangos for (var i = mangos.length - 1; i >= 0; i--) { var mango = mangos[i]; // Move the mango downwards mango.y += 5; // Check if the mango has been caught by the monkey if (mango.intersects(monkey)) { mangos.splice(i, 1); mango.destroy(); } // Check if the mango has fallen off the screen else if (mango.y > 2732) { mangos.splice(i, 1); mango.destroy(); missedMangos++; // End the game if 5 mangos have been missed if (missedMangos >= 5) { LK.showGameOver(); } } } };
===================================================================
--- original.js
+++ change.js
@@ -38,8 +38,15 @@
// Initialize the monkey and the mango tree
var monkey = game.addChild(new Monkey());
monkey.x = 1024; // Position the monkey at the center of the screen
monkey.y = 2732 - monkey.height; // Position the monkey at the bottom of the screen
+// Add touch control to the monkey
+game.down = function (x, y, obj) {
+ monkey.x = x;
+};
+game.move = function (x, y, obj) {
+ monkey.x = x;
+};
var mangoTree = game.attachAsset('mangoTree', {
anchorX: 0.5,
anchorY: 1
});