/**** * Classes ****/ // Create a class for the apple var Apple = Container.expand(function () { var self = Container.call(this); var appleGraphics = self.attachAsset('apple', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // The apple's movement logic will be implemented here }; }); // Create a class for the banana var Banana = Container.expand(function () { var self = Container.call(this); var bananaGraphics = self.attachAsset('banana', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // The banana's movement logic will be implemented here }; }); // 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 }; }); // Create a class for the rock var Rock = Container.expand(function () { var self = Container.call(this); var rockGraphics = self.attachAsset('rock', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Move the rock downwards self.y += 5; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFFFFF // Init game with white background }); /**** * Game Code ****/ // Add the 3D background image to the game var background = game.addChild(LK.getAsset('background', {})); // Initialize the monkey 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; }; // Initialize the array of mangos, apples, rocks and the missed mangos counter var mangos = []; var apples = []; var rocks = []; var bananas = []; var missedMangos = 0; // Generate a new rock every 600 frames (10 seconds) if (LK.ticks % 600 == 0) { var newRock = game.addChild(new Rock()); newRock.x = Math.random() * 2048; // Random x position across the screen width newRock.y = 0; // Start from the top of the screen rocks.push(newRock); } // Create a live score board at the top of the screen var scoreBoard = new Text2('**Score: 0**', { size: 50, fill: "#000000" }); scoreBoard.anchor.set(0.5, 0); LK.gui.top.addChild(scoreBoard); // Add a text and a small mango photo at the top right of the game screen var missedMangoText = new Text2("Don't miss 5", { size: 50, fill: "#000000" }); missedMangoText.anchor.set(1, 0); LK.gui.topRight.addChild(missedMangoText); // 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 = Math.random() * 2048; // Random x position across the screen width newMango.y = 0; // Start from the top of the screen mangos.push(newMango); game.addChild(newMango); } // Generate a new apple every 900 frames (15 seconds) if (LK.ticks % 900 == 0) { var newApple = new Apple(); newApple.x = Math.random() * 2048; // Random x position across the screen width newApple.y = 0; // Start from the top of the screen apples.push(newApple); game.addChild(newApple); } // Generate a new banana every 8400 frames (140 seconds) if (LK.ticks % 8400 == 0) { var newBanana = new Banana(); newBanana.x = Math.random() * 2048; // Random x position across the screen width newBanana.y = 0; // Start from the top of the screen bananas.push(newBanana); game.addChild(newBanana); } // 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(); // Increase the score by 10 LK.setScore(LK.getScore() + 10); // Update the score board scoreBoard.setText('Score: ' + LK.getScore()); } // 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(); } } } // Update the apples for (var i = apples.length - 1; i >= 0; i--) { var apple = apples[i]; // Move the apple downwards apple.y += 5; // Check if the apple has been caught by the monkey if (apple.intersects(monkey)) { apples.splice(i, 1); apple.destroy(); // Increase the score by 20 LK.setScore(LK.getScore() + 20); // Update the score board scoreBoard.setText('Score: ' + LK.getScore()); } // Check if the apple has fallen off the screen else if (apple.y > 2732) { apples.splice(i, 1); apple.destroy(); } } // Update the bananas for (var i = bananas.length - 1; i >= 0; i--) { var banana = bananas[i]; // Move the banana downwards banana.y += 5; // Check if the banana has been caught by the monkey if (banana.intersects(monkey)) { bananas.splice(i, 1); banana.destroy(); // Increase the score by 100 LK.setScore(LK.getScore() + 100); // Update the score board scoreBoard.setText('Score: ' + LK.getScore()); } // Check if the banana has fallen off the screen else if (banana.y > 2732) { bananas.splice(i, 1); banana.destroy(); } } // Update the rocks for (var i = rocks.length - 1; i >= 0; i--) { var rock = rocks[i]; // Move the rock downwards rock.y += 5; // Check if the rock has hit the monkey if (rock.intersects(monkey)) { rocks.splice(i, 1); rock.destroy(); // Decrease the score by 50 LK.setScore(LK.getScore() - 50); // Update the score board scoreBoard.setText('Score: ' + LK.getScore()); } // Check if the rock has fallen off the screen else if (rock.y > 2732) { rocks.splice(i, 1); rock.destroy(); } } };
/****
* Classes
****/
// Create a class for the apple
var Apple = Container.expand(function () {
var self = Container.call(this);
var appleGraphics = self.attachAsset('apple', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// The apple's movement logic will be implemented here
};
});
// Create a class for the banana
var Banana = Container.expand(function () {
var self = Container.call(this);
var bananaGraphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// The banana's movement logic will be implemented here
};
});
// 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
};
});
// Create a class for the rock
var Rock = Container.expand(function () {
var self = Container.call(this);
var rockGraphics = self.attachAsset('rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Move the rock downwards
self.y += 5;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFFFF // Init game with white background
});
/****
* Game Code
****/
// Add the 3D background image to the game
var background = game.addChild(LK.getAsset('background', {}));
// Initialize the monkey
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;
};
// Initialize the array of mangos, apples, rocks and the missed mangos counter
var mangos = [];
var apples = [];
var rocks = [];
var bananas = [];
var missedMangos = 0;
// Generate a new rock every 600 frames (10 seconds)
if (LK.ticks % 600 == 0) {
var newRock = game.addChild(new Rock());
newRock.x = Math.random() * 2048; // Random x position across the screen width
newRock.y = 0; // Start from the top of the screen
rocks.push(newRock);
}
// Create a live score board at the top of the screen
var scoreBoard = new Text2('**Score: 0**', {
size: 50,
fill: "#000000"
});
scoreBoard.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreBoard);
// Add a text and a small mango photo at the top right of the game screen
var missedMangoText = new Text2("Don't miss 5", {
size: 50,
fill: "#000000"
});
missedMangoText.anchor.set(1, 0);
LK.gui.topRight.addChild(missedMangoText);
// 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 = Math.random() * 2048; // Random x position across the screen width
newMango.y = 0; // Start from the top of the screen
mangos.push(newMango);
game.addChild(newMango);
}
// Generate a new apple every 900 frames (15 seconds)
if (LK.ticks % 900 == 0) {
var newApple = new Apple();
newApple.x = Math.random() * 2048; // Random x position across the screen width
newApple.y = 0; // Start from the top of the screen
apples.push(newApple);
game.addChild(newApple);
}
// Generate a new banana every 8400 frames (140 seconds)
if (LK.ticks % 8400 == 0) {
var newBanana = new Banana();
newBanana.x = Math.random() * 2048; // Random x position across the screen width
newBanana.y = 0; // Start from the top of the screen
bananas.push(newBanana);
game.addChild(newBanana);
}
// 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();
// Increase the score by 10
LK.setScore(LK.getScore() + 10);
// Update the score board
scoreBoard.setText('Score: ' + LK.getScore());
}
// 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();
}
}
}
// Update the apples
for (var i = apples.length - 1; i >= 0; i--) {
var apple = apples[i];
// Move the apple downwards
apple.y += 5;
// Check if the apple has been caught by the monkey
if (apple.intersects(monkey)) {
apples.splice(i, 1);
apple.destroy();
// Increase the score by 20
LK.setScore(LK.getScore() + 20);
// Update the score board
scoreBoard.setText('Score: ' + LK.getScore());
}
// Check if the apple has fallen off the screen
else if (apple.y > 2732) {
apples.splice(i, 1);
apple.destroy();
}
}
// Update the bananas
for (var i = bananas.length - 1; i >= 0; i--) {
var banana = bananas[i];
// Move the banana downwards
banana.y += 5;
// Check if the banana has been caught by the monkey
if (banana.intersects(monkey)) {
bananas.splice(i, 1);
banana.destroy();
// Increase the score by 100
LK.setScore(LK.getScore() + 100);
// Update the score board
scoreBoard.setText('Score: ' + LK.getScore());
}
// Check if the banana has fallen off the screen
else if (banana.y > 2732) {
bananas.splice(i, 1);
banana.destroy();
}
}
// Update the rocks
for (var i = rocks.length - 1; i >= 0; i--) {
var rock = rocks[i];
// Move the rock downwards
rock.y += 5;
// Check if the rock has hit the monkey
if (rock.intersects(monkey)) {
rocks.splice(i, 1);
rock.destroy();
// Decrease the score by 50
LK.setScore(LK.getScore() - 50);
// Update the score board
scoreBoard.setText('Score: ' + LK.getScore());
}
// Check if the rock has fallen off the screen
else if (rock.y > 2732) {
rocks.splice(i, 1);
rock.destroy();
}
}
};