/**** * Classes ****/ // Define the Banana class var Banana = Container.expand(function () { var self = Container.call(this); var bananaGraphics = self.attachAsset('banana', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { bananaGraphics.color = 0x00ff00; // Change the color of the banana to green self.destroy(); bananas.splice(bananas.indexOf(self), 1); } }; }); // Define the HealthBar class var HealthBar = Container.expand(function () { var self = Container.call(this); var healthBarGraphics = self.attachAsset('healthBar', { anchorX: 0.0, anchorY: 0.0 }); self.update = function () { // Update health bar width based on hero's health healthBarGraphics.width = hero.health * 20; }; }); //<Assets used in the game will automatically appear here> // Define the Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Hero update logic }; self.whip = function () { var whip = new Whip(); whip.x = self.x; whip.y = self.y; whips.push(whip); game.addChild(whip); LK.getSound('Whiping1').play(); LK.getSound('Whiping1').play(); }; }); // Define the HomeScreen class var HomeScreen = Container.expand(function () { var self = Container.call(this); var homeScreenGraphics = self.attachAsset('homeScreen', { anchorX: 0.5, anchorY: 0.5 }); self.visible = false; self.update = function () { // Home screen update logic }; self.down = function (x, y, obj) { self.down = function (x, y, obj) { self.visible = false; LK.restartGame(); }; // Handle touch events on the home screen }; }); // Define the Monkey class var Monkey = Container.expand(function () { var self = Container.call(this); var monkeyGraphics = self.attachAsset('monkey', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); monkeys.splice(monkeys.indexOf(self), 1); } }; }); // Define the Whip class var Whip = Container.expand(function () { var self = Container.call(this); var whipGraphics = self.attachAsset('whip', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < 0) { self.destroy(); whips.splice(whips.indexOf(self), 1); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Clear the background color }); /**** * Game Code ****/ var jungleBackground = game.attachAsset('jungle', { anchorX: 0.0, anchorY: 0.0 }); jungleBackground.width = 2048; jungleBackground.height = 2732; var homeScreen = game.addChild(new HomeScreen()); homeScreen.x = 2048 / 2; homeScreen.y = 2732 / 2; var whipping = false; // Add jungle image asset var jungleBackground = game.attachAsset('jungle', { anchorX: 0.0, anchorY: 0.0 }); // Initialize arrays and variables var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 200; hero.health = 2; // Initialize hero's health to 2 var healthBar = game.addChild(new HealthBar()); healthBar.x = 50; healthBar.y = 50; var monkeys = []; var whips = []; var bananas = []; var score = 0; var scoreMultiplier = 1; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Function to handle game updates game.update = function () { // Update hero hero.update(); // Update monkeys for (var i = monkeys.length - 1; i >= 0; i--) { monkeys[i].update(); if (monkeys[i].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); homeScreen.visible = true; LK.showGameOver(); } } // Update whips for (var j = whips.length - 1; j >= 0; j--) { whips[j].update(); for (var k = monkeys.length - 1; k >= 0; k--) { if (whips[j] && monkeys[k] && whips[j].intersects(monkeys[k])) { monkeys[k].destroy(); whips[j].destroy(); monkeys.splice(k, 1); whips.splice(j, 1); score++; scoreTxt.setText(score); // Update score multiplier if (score >= 20 * 10) { scoreMultiplier = 2.5; } else if (score >= 10) { scoreMultiplier = 1.5; } else { scoreMultiplier = 1; } break; } } // Check if whip intersects with bananas for (var b = bananas.length - 1; b >= 0; b--) { if (whips[j] && bananas[b] && whips[j].intersects(bananas[b])) { bananas[b].destroy(); whips[j].destroy(); bananas.splice(b, 1); whips.splice(j, 1); score += 2; // Increase score by 2 when a whip hits a banana scoreTxt.setText(score); // Update score text break; } } } // Spawn monkeys if (LK.ticks % Math.floor(30 / scoreMultiplier) == 0) { var monkey = new Monkey(); monkey.x = Math.random() * 2048; monkey.y = -100; monkeys.push(monkey); game.addChild(monkey); var banana = new Banana(); banana.x = monkey.x; banana.y = monkey.y; bananas.push(banana); game.addChild(banana); } var currentTime = Date.now(); // Update bananas and check for collisions with the hero for (var i = bananas.length - 1; i >= 0; i--) { bananas[i].update(); if (bananas[i].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); bananas[i].destroy(); bananas.splice(i, 1); LK.setTimeout(function () { var banana = new Banana(); banana.x = Math.random() * 2048; banana.y = -100; bananas.push(banana); game.addChild(banana); }, 1000); if (hero.health <= 0) { homeScreen.visible = true; LK.showGameOver(); } } } if (whipping && Date.now() - lastWhipTime >= 333) { hero.whip(); lastWhipTime = Date.now(); } if (score >= 502) { LK.showGameOver(); } }; // Handle touch events for hero movement and whipping var lastWhipTime = 0; game.down = function (x, y, obj) { hero.x = x; hero.y = y; whipping = true; }; game.move = function (x, y, obj) { hero.x = x; hero.y = y; }; game.up = function (x, y, obj) { whipping = false; };
/****
* Classes
****/
// Define the Banana class
var Banana = Container.expand(function () {
var self = Container.call(this);
var bananaGraphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
bananaGraphics.color = 0x00ff00; // Change the color of the banana to green
self.destroy();
bananas.splice(bananas.indexOf(self), 1);
}
};
});
// Define the HealthBar class
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var healthBarGraphics = self.attachAsset('healthBar', {
anchorX: 0.0,
anchorY: 0.0
});
self.update = function () {
// Update health bar width based on hero's health
healthBarGraphics.width = hero.health * 20;
};
});
//<Assets used in the game will automatically appear here>
// Define the Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Hero update logic
};
self.whip = function () {
var whip = new Whip();
whip.x = self.x;
whip.y = self.y;
whips.push(whip);
game.addChild(whip);
LK.getSound('Whiping1').play();
LK.getSound('Whiping1').play();
};
});
// Define the HomeScreen class
var HomeScreen = Container.expand(function () {
var self = Container.call(this);
var homeScreenGraphics = self.attachAsset('homeScreen', {
anchorX: 0.5,
anchorY: 0.5
});
self.visible = false;
self.update = function () {
// Home screen update logic
};
self.down = function (x, y, obj) {
self.down = function (x, y, obj) {
self.visible = false;
LK.restartGame();
};
// Handle touch events on the home screen
};
});
// Define the Monkey class
var Monkey = Container.expand(function () {
var self = Container.call(this);
var monkeyGraphics = self.attachAsset('monkey', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
monkeys.splice(monkeys.indexOf(self), 1);
}
};
});
// Define the Whip class
var Whip = Container.expand(function () {
var self = Container.call(this);
var whipGraphics = self.attachAsset('whip', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -15;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
whips.splice(whips.indexOf(self), 1);
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Clear the background color
});
/****
* Game Code
****/
var jungleBackground = game.attachAsset('jungle', {
anchorX: 0.0,
anchorY: 0.0
});
jungleBackground.width = 2048;
jungleBackground.height = 2732;
var homeScreen = game.addChild(new HomeScreen());
homeScreen.x = 2048 / 2;
homeScreen.y = 2732 / 2;
var whipping = false;
// Add jungle image asset
var jungleBackground = game.attachAsset('jungle', {
anchorX: 0.0,
anchorY: 0.0
});
// Initialize arrays and variables
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 200;
hero.health = 2; // Initialize hero's health to 2
var healthBar = game.addChild(new HealthBar());
healthBar.x = 50;
healthBar.y = 50;
var monkeys = [];
var whips = [];
var bananas = [];
var score = 0;
var scoreMultiplier = 1;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to handle game updates
game.update = function () {
// Update hero
hero.update();
// Update monkeys
for (var i = monkeys.length - 1; i >= 0; i--) {
monkeys[i].update();
if (monkeys[i].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
homeScreen.visible = true;
LK.showGameOver();
}
}
// Update whips
for (var j = whips.length - 1; j >= 0; j--) {
whips[j].update();
for (var k = monkeys.length - 1; k >= 0; k--) {
if (whips[j] && monkeys[k] && whips[j].intersects(monkeys[k])) {
monkeys[k].destroy();
whips[j].destroy();
monkeys.splice(k, 1);
whips.splice(j, 1);
score++;
scoreTxt.setText(score);
// Update score multiplier
if (score >= 20 * 10) {
scoreMultiplier = 2.5;
} else if (score >= 10) {
scoreMultiplier = 1.5;
} else {
scoreMultiplier = 1;
}
break;
}
}
// Check if whip intersects with bananas
for (var b = bananas.length - 1; b >= 0; b--) {
if (whips[j] && bananas[b] && whips[j].intersects(bananas[b])) {
bananas[b].destroy();
whips[j].destroy();
bananas.splice(b, 1);
whips.splice(j, 1);
score += 2; // Increase score by 2 when a whip hits a banana
scoreTxt.setText(score); // Update score text
break;
}
}
}
// Spawn monkeys
if (LK.ticks % Math.floor(30 / scoreMultiplier) == 0) {
var monkey = new Monkey();
monkey.x = Math.random() * 2048;
monkey.y = -100;
monkeys.push(monkey);
game.addChild(monkey);
var banana = new Banana();
banana.x = monkey.x;
banana.y = monkey.y;
bananas.push(banana);
game.addChild(banana);
}
var currentTime = Date.now();
// Update bananas and check for collisions with the hero
for (var i = bananas.length - 1; i >= 0; i--) {
bananas[i].update();
if (bananas[i].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
bananas[i].destroy();
bananas.splice(i, 1);
LK.setTimeout(function () {
var banana = new Banana();
banana.x = Math.random() * 2048;
banana.y = -100;
bananas.push(banana);
game.addChild(banana);
}, 1000);
if (hero.health <= 0) {
homeScreen.visible = true;
LK.showGameOver();
}
}
}
if (whipping && Date.now() - lastWhipTime >= 333) {
hero.whip();
lastWhipTime = Date.now();
}
if (score >= 502) {
LK.showGameOver();
}
};
// Handle touch events for hero movement and whipping
var lastWhipTime = 0;
game.down = function (x, y, obj) {
hero.x = x;
hero.y = y;
whipping = true;
};
game.move = function (x, y, obj) {
hero.x = x;
hero.y = y;
};
game.up = function (x, y, obj) {
whipping = false;
};
Banana. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Jungle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2 hearts. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Golden trophy. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.