/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = 25 + Math.random() * 15;
self.penalty = 100;
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var DragonFruit = Container.expand(function () {
var self = Container.call(this);
var dragonFruitGraphics = self.attachAsset('dragonFruit', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = (18 + Math.random() * 12) * 2; // Double speed
self.points = 50;
self.fruitType = 'dragonFruit';
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var Fruit = Container.expand(function (fruitType) {
var self = Container.call(this);
var fruitGraphics = self.attachAsset(fruitType, {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = 18 + Math.random() * 12;
self.points = 10;
self.fruitType = fruitType;
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var HealthKit = Container.expand(function () {
var self = Container.call(this);
var healthKitGraphics = self.attachAsset('healthKit', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = 12 + Math.random() * 8; // Slower fall speed
self.points = 0; // No points for health kits
self.fruitType = 'healthKit';
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var Ninja = Container.expand(function () {
var self = Container.call(this);
var ninjaGraphics = self.attachAsset('ninja', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
return self;
});
var Watermelon = Container.expand(function () {
var self = Container.call(this);
var watermelonGraphics = self.attachAsset('watermelon', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = (18 + Math.random() * 12) * 2; // Double speed
self.points = 20;
self.fruitType = 'watermelon';
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Add wooden background
var woodenBg = game.addChild(LK.getAsset('woodenBackground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Add wooden platform
var woodenPlatform = game.addChild(LK.getAsset('woodenPlatform', {
anchorX: 0.5,
anchorY: 1,
x: 2048 / 2,
y: 2732 - 50
}));
var ninja = game.addChild(new Ninja());
ninja.x = 2048 / 2;
ninja.y = 2732 - 350; // Position ninja higher above the platform
var fruits = [];
var bombs = [];
var fruitTypes = ['apple', 'banana', 'orange', 'grape'];
var dragonFruits = [];
var watermelons = [];
var spawnTimer = 0;
var spawnInterval = 120;
var bombSpawnTimer = 0;
var bombSpawnInterval = 300;
var watermelonSpawnTimer = 0;
var watermelonSpawnInterval = 300; // Every 5 seconds (5 * 60 fps)
var healthKits = [];
var healthKitSpawnTimer = 0;
var healthKitSpawnInterval = 1800; // Every 30 seconds (30 * 60 fps) - rare spawn
var difficultyTimer = 0;
var gameStartTimer = 0; // Track game time for dragon fruit spawning
var lives = 5; // Ninja has 5 lives
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF,
font: "Impact, 'Arial Black', Tahoma"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Add lives display
var livesTxt = new Text2('Lives: ' + lives, {
size: 100,
fill: 0xFF0000,
font: "Impact, 'Arial Black', Tahoma"
});
livesTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(livesTxt);
// Add timer display
var timerTxt = new Text2('Time: 2:00', {
size: 80,
fill: 0xFFFFFF,
font: "Impact, 'Arial Black', Tahoma"
});
timerTxt.anchor.set(0.5, 0);
timerTxt.y = 120; // Position below score
LK.gui.top.addChild(timerTxt);
// Timer variables
var gameTime = 7200; // 2 minutes in ticks (120 seconds * 60 fps)
var gameEnded = false;
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
if (dragNode.x < 180) dragNode.x = 180;
if (dragNode.x > 2048 - 180) dragNode.x = 2048 - 180;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = ninja;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
function spawnFruit() {
var randomType = fruitTypes[Math.floor(Math.random() * fruitTypes.length)];
var newFruit = game.addChild(new Fruit(randomType));
newFruit.x = 100 + Math.random() * (2048 - 200);
newFruit.y = -50;
newFruit.lastY = newFruit.y;
newFruit.lastIntersecting = false;
fruits.push(newFruit);
}
function spawnBomb() {
var newBomb = game.addChild(new Bomb());
newBomb.x = 100 + Math.random() * (2048 - 200);
newBomb.y = -50;
newBomb.lastY = newBomb.y;
newBomb.lastIntersecting = false;
bombs.push(newBomb);
}
function spawnDragonFruit() {
var newDragonFruit = game.addChild(new DragonFruit());
newDragonFruit.x = 100 + Math.random() * (2048 - 200);
newDragonFruit.y = -50;
newDragonFruit.lastY = newDragonFruit.y;
newDragonFruit.lastIntersecting = false;
dragonFruits.push(newDragonFruit);
}
function spawnWatermelon() {
var newWatermelon = game.addChild(new Watermelon());
newWatermelon.x = 100 + Math.random() * (2048 - 200);
newWatermelon.y = -50;
newWatermelon.lastY = newWatermelon.y;
newWatermelon.lastIntersecting = false;
watermelons.push(newWatermelon);
}
function spawnHealthKit() {
var newHealthKit = game.addChild(new HealthKit());
newHealthKit.x = 100 + Math.random() * (2048 - 200);
newHealthKit.y = -50;
newHealthKit.lastY = newHealthKit.y;
newHealthKit.lastIntersecting = false;
healthKits.push(newHealthKit);
}
game.update = function () {
// Check if game has ended
if (gameEnded) return;
// Update timer
gameTime--;
var minutes = Math.floor(gameTime / 3600);
var seconds = Math.floor(gameTime % 3600 / 60);
var timeString = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
timerTxt.setText('Time: ' + timeString);
// Check if time is up
if (gameTime <= 0) {
gameEnded = true;
LK.showGameOver();
return;
}
spawnTimer++;
bombSpawnTimer++;
watermelonSpawnTimer++;
healthKitSpawnTimer++;
difficultyTimer++;
gameStartTimer++;
// Increase difficulty over time
if (difficultyTimer % 1800 == 0 && spawnInterval > 30) {
spawnInterval -= 5;
}
// Spawn fruits with increasing frequency
var fruitsToSpawn = 1;
if (difficultyTimer > 3600) fruitsToSpawn = 2; // After 1 minute, spawn 2 fruits
if (difficultyTimer > 7200) fruitsToSpawn = 3; // After 2 minutes, spawn 3 fruits
if (difficultyTimer > 10800) fruitsToSpawn = 4; // After 3 minutes, spawn 4 fruits
if (spawnTimer >= spawnInterval) {
for (var j = 0; j < fruitsToSpawn; j++) {
spawnFruit();
}
spawnTimer = 0;
}
// Spawn bombs occasionally
if (bombSpawnTimer >= bombSpawnInterval) {
spawnBomb();
bombSpawnTimer = 0;
}
// Spawn dragon fruit occasionally after first 10 seconds (every 600 ticks = 10 seconds)
if (gameStartTimer >= 600 && LK.ticks % 600 == 0) {
spawnDragonFruit();
}
// Spawn watermelon every 5 seconds
if (watermelonSpawnTimer >= watermelonSpawnInterval) {
spawnWatermelon();
watermelonSpawnTimer = 0;
}
// Spawn health kit rarely (every 30 seconds)
if (healthKitSpawnTimer >= healthKitSpawnInterval) {
spawnHealthKit();
healthKitSpawnTimer = 0;
}
// Update fruits
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
// Check if fruit went off screen
if (fruit.lastY < 2732 + 100 && fruit.y >= 2732 + 100) {
// Play fruit fall sound
LK.getSound('fruitFall').play();
// Lose a life for missing fruit
lives--;
livesTxt.setText('Lives: ' + lives);
// Check if game over
if (lives <= 0) {
LK.getSound('gameOver').play();
gameEnded = true;
LK.showGameOver();
return;
}
// Penalty for missing fruit
LK.setScore(LK.getScore() - 50);
scoreTxt.setText('Score: ' + LK.getScore());
fruit.destroy();
fruits.splice(i, 1);
continue;
}
// Check collision with ninja
var currentIntersecting = fruit.intersects(ninja);
if (!fruit.lastIntersecting && currentIntersecting) {
LK.setScore(LK.getScore() + fruit.points);
scoreTxt.setText('Score: ' + LK.getScore());
// Play catch sound effect
LK.getSound('fruitCatch').play();
// Enhanced visual feedback with bounce effect
tween(fruit, {
scaleX: 1.8,
scaleY: 1.8,
alpha: 0.3,
rotation: Math.PI
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
fruit.destroy();
}
});
// Additional sparkle effect - create a brief flash
LK.effects.flashObject(fruit, 0xFFD700, 200);
fruits.splice(i, 1);
continue;
}
fruit.lastY = fruit.y;
fruit.lastIntersecting = currentIntersecting;
}
// Update bombs
for (var k = bombs.length - 1; k >= 0; k--) {
var bomb = bombs[k];
// Check if bomb went off screen
if (bomb.lastY < 2732 + 100 && bomb.y >= 2732 + 100) {
bomb.destroy();
bombs.splice(k, 1);
continue;
}
// Check collision with ninja
var bombIntersecting = bomb.intersects(ninja);
if (!bomb.lastIntersecting && bombIntersecting) {
// Lose a life for hitting bomb
lives--;
livesTxt.setText('Lives: ' + lives);
// Check if game over
if (lives <= 0) {
LK.getSound('gameOver').play();
gameEnded = true;
LK.showGameOver();
return;
}
LK.setScore(LK.getScore() - bomb.penalty);
scoreTxt.setText('Score: ' + LK.getScore());
// Play explosion sound effect
LK.getSound('bombExplosion').play();
// Play ninja pain sound
LK.getSound('ninjaPain').play();
// Enhanced explosion visual effects
tween(bomb, {
scaleX: 2.5,
scaleY: 2.5,
alpha: 0,
rotation: Math.PI * 2
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
bomb.destroy();
}
});
// Flash effect for bomb hit
LK.effects.flashScreen(0xFF0000, 500);
// Additional explosive flash effect on the bomb itself
LK.effects.flashObject(bomb, 0xFFFFFF, 300);
bombs.splice(k, 1);
continue;
}
bomb.lastY = bomb.y;
bomb.lastIntersecting = bombIntersecting;
}
// Update dragon fruits
for (var d = dragonFruits.length - 1; d >= 0; d--) {
var dragonFruit = dragonFruits[d];
// Check if dragon fruit went off screen
if (dragonFruit.lastY < 2732 + 100 && dragonFruit.y >= 2732 + 100) {
// Play fruit fall sound
LK.getSound('fruitFall').play();
// Lose a life for missing dragon fruit
lives--;
livesTxt.setText('Lives: ' + lives);
// Check if game over
if (lives <= 0) {
LK.getSound('gameOver').play();
gameEnded = true;
LK.showGameOver();
return;
}
// Penalty for missing dragon fruit
LK.setScore(LK.getScore() - 75);
scoreTxt.setText('Score: ' + LK.getScore());
dragonFruit.destroy();
dragonFruits.splice(d, 1);
continue;
}
// Check collision with ninja
var dragonIntersecting = dragonFruit.intersects(ninja);
if (!dragonFruit.lastIntersecting && dragonIntersecting) {
LK.setScore(LK.getScore() + dragonFruit.points);
scoreTxt.setText('Score: ' + LK.getScore());
// Play catch sound effect
LK.getSound('fruitCatch').play();
// Enhanced visual feedback with special dragon fruit effect
tween(dragonFruit, {
scaleX: 2.2,
scaleY: 2.2,
alpha: 0.2,
rotation: Math.PI * 2
}, {
duration: 400,
easing: tween.bounceOut,
onFinish: function onFinish() {
dragonFruit.destroy();
}
});
// Special golden flash for dragon fruit
LK.effects.flashObject(dragonFruit, 0xFFD700, 300);
LK.effects.flashScreen(0xFFD700, 200);
dragonFruits.splice(d, 1);
continue;
}
dragonFruit.lastY = dragonFruit.y;
dragonFruit.lastIntersecting = dragonIntersecting;
}
// Update watermelons
for (var w = watermelons.length - 1; w >= 0; w--) {
var watermelon = watermelons[w];
// Check if watermelon went off screen
if (watermelon.lastY < 2732 + 100 && watermelon.y >= 2732 + 100) {
// Play fruit fall sound
LK.getSound('fruitFall').play();
// Lose a life for missing watermelon
lives--;
livesTxt.setText('Lives: ' + lives);
// Check if game over
if (lives <= 0) {
LK.getSound('gameOver').play();
gameEnded = true;
LK.showGameOver();
return;
}
// Penalty for missing watermelon
LK.setScore(LK.getScore() - 50);
scoreTxt.setText('Score: ' + LK.getScore());
watermelon.destroy();
watermelons.splice(w, 1);
continue;
}
// Check collision with ninja
var watermelonIntersecting = watermelon.intersects(ninja);
if (!watermelon.lastIntersecting && watermelonIntersecting) {
LK.setScore(LK.getScore() + watermelon.points);
scoreTxt.setText('Score: ' + LK.getScore());
// Play catch sound effect
LK.getSound('fruitCatch').play();
// Enhanced visual feedback with bounce effect
tween(watermelon, {
scaleX: 1.8,
scaleY: 1.8,
alpha: 0.3,
rotation: Math.PI
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
watermelon.destroy();
}
});
// Additional sparkle effect - create a brief flash
LK.effects.flashObject(watermelon, 0xFFD700, 200);
watermelons.splice(w, 1);
continue;
}
watermelon.lastY = watermelon.y;
watermelon.lastIntersecting = watermelonIntersecting;
}
// Update health kits
for (var h = healthKits.length - 1; h >= 0; h--) {
var healthKit = healthKits[h];
// Check if health kit went off screen (no penalty or points)
if (healthKit.lastY < 2732 + 100 && healthKit.y >= 2732 + 100) {
healthKit.destroy();
healthKits.splice(h, 1);
continue;
}
// Check collision with ninja
var healthKitIntersecting = healthKit.intersects(ninja);
if (!healthKit.lastIntersecting && healthKitIntersecting) {
// Gain a life (max 5 lives)
if (lives < 5) {
lives++;
livesTxt.setText('Lives: ' + lives);
}
// Play health kit catch sound effect
LK.getSound('healthCatch').play();
// Enhanced visual feedback with healing effect
tween(healthKit, {
scaleX: 2.0,
scaleY: 2.0,
alpha: 0.2,
rotation: Math.PI
}, {
duration: 350,
easing: tween.bounceOut,
onFinish: function onFinish() {
healthKit.destroy();
}
});
// Special green flash for health kit
LK.effects.flashObject(healthKit, 0x00FF00, 300);
LK.effects.flashScreen(0x00FF00, 150);
healthKits.splice(h, 1);
continue;
}
healthKit.lastY = healthKit.y;
healthKit.lastIntersecting = healthKitIntersecting;
}
};
// Start background music when game begins
LK.playMusic('bgmusic'); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = 25 + Math.random() * 15;
self.penalty = 100;
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var DragonFruit = Container.expand(function () {
var self = Container.call(this);
var dragonFruitGraphics = self.attachAsset('dragonFruit', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = (18 + Math.random() * 12) * 2; // Double speed
self.points = 50;
self.fruitType = 'dragonFruit';
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var Fruit = Container.expand(function (fruitType) {
var self = Container.call(this);
var fruitGraphics = self.attachAsset(fruitType, {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = 18 + Math.random() * 12;
self.points = 10;
self.fruitType = fruitType;
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var HealthKit = Container.expand(function () {
var self = Container.call(this);
var healthKitGraphics = self.attachAsset('healthKit', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = 12 + Math.random() * 8; // Slower fall speed
self.points = 0; // No points for health kits
self.fruitType = 'healthKit';
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
var Ninja = Container.expand(function () {
var self = Container.call(this);
var ninjaGraphics = self.attachAsset('ninja', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
return self;
});
var Watermelon = Container.expand(function () {
var self = Container.call(this);
var watermelonGraphics = self.attachAsset('watermelon', {
anchorX: 0.5,
anchorY: 0.5
});
self.fallSpeed = (18 + Math.random() * 12) * 2; // Double speed
self.points = 20;
self.fruitType = 'watermelon';
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Add wooden background
var woodenBg = game.addChild(LK.getAsset('woodenBackground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Add wooden platform
var woodenPlatform = game.addChild(LK.getAsset('woodenPlatform', {
anchorX: 0.5,
anchorY: 1,
x: 2048 / 2,
y: 2732 - 50
}));
var ninja = game.addChild(new Ninja());
ninja.x = 2048 / 2;
ninja.y = 2732 - 350; // Position ninja higher above the platform
var fruits = [];
var bombs = [];
var fruitTypes = ['apple', 'banana', 'orange', 'grape'];
var dragonFruits = [];
var watermelons = [];
var spawnTimer = 0;
var spawnInterval = 120;
var bombSpawnTimer = 0;
var bombSpawnInterval = 300;
var watermelonSpawnTimer = 0;
var watermelonSpawnInterval = 300; // Every 5 seconds (5 * 60 fps)
var healthKits = [];
var healthKitSpawnTimer = 0;
var healthKitSpawnInterval = 1800; // Every 30 seconds (30 * 60 fps) - rare spawn
var difficultyTimer = 0;
var gameStartTimer = 0; // Track game time for dragon fruit spawning
var lives = 5; // Ninja has 5 lives
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF,
font: "Impact, 'Arial Black', Tahoma"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Add lives display
var livesTxt = new Text2('Lives: ' + lives, {
size: 100,
fill: 0xFF0000,
font: "Impact, 'Arial Black', Tahoma"
});
livesTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(livesTxt);
// Add timer display
var timerTxt = new Text2('Time: 2:00', {
size: 80,
fill: 0xFFFFFF,
font: "Impact, 'Arial Black', Tahoma"
});
timerTxt.anchor.set(0.5, 0);
timerTxt.y = 120; // Position below score
LK.gui.top.addChild(timerTxt);
// Timer variables
var gameTime = 7200; // 2 minutes in ticks (120 seconds * 60 fps)
var gameEnded = false;
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
if (dragNode.x < 180) dragNode.x = 180;
if (dragNode.x > 2048 - 180) dragNode.x = 2048 - 180;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = ninja;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
function spawnFruit() {
var randomType = fruitTypes[Math.floor(Math.random() * fruitTypes.length)];
var newFruit = game.addChild(new Fruit(randomType));
newFruit.x = 100 + Math.random() * (2048 - 200);
newFruit.y = -50;
newFruit.lastY = newFruit.y;
newFruit.lastIntersecting = false;
fruits.push(newFruit);
}
function spawnBomb() {
var newBomb = game.addChild(new Bomb());
newBomb.x = 100 + Math.random() * (2048 - 200);
newBomb.y = -50;
newBomb.lastY = newBomb.y;
newBomb.lastIntersecting = false;
bombs.push(newBomb);
}
function spawnDragonFruit() {
var newDragonFruit = game.addChild(new DragonFruit());
newDragonFruit.x = 100 + Math.random() * (2048 - 200);
newDragonFruit.y = -50;
newDragonFruit.lastY = newDragonFruit.y;
newDragonFruit.lastIntersecting = false;
dragonFruits.push(newDragonFruit);
}
function spawnWatermelon() {
var newWatermelon = game.addChild(new Watermelon());
newWatermelon.x = 100 + Math.random() * (2048 - 200);
newWatermelon.y = -50;
newWatermelon.lastY = newWatermelon.y;
newWatermelon.lastIntersecting = false;
watermelons.push(newWatermelon);
}
function spawnHealthKit() {
var newHealthKit = game.addChild(new HealthKit());
newHealthKit.x = 100 + Math.random() * (2048 - 200);
newHealthKit.y = -50;
newHealthKit.lastY = newHealthKit.y;
newHealthKit.lastIntersecting = false;
healthKits.push(newHealthKit);
}
game.update = function () {
// Check if game has ended
if (gameEnded) return;
// Update timer
gameTime--;
var minutes = Math.floor(gameTime / 3600);
var seconds = Math.floor(gameTime % 3600 / 60);
var timeString = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
timerTxt.setText('Time: ' + timeString);
// Check if time is up
if (gameTime <= 0) {
gameEnded = true;
LK.showGameOver();
return;
}
spawnTimer++;
bombSpawnTimer++;
watermelonSpawnTimer++;
healthKitSpawnTimer++;
difficultyTimer++;
gameStartTimer++;
// Increase difficulty over time
if (difficultyTimer % 1800 == 0 && spawnInterval > 30) {
spawnInterval -= 5;
}
// Spawn fruits with increasing frequency
var fruitsToSpawn = 1;
if (difficultyTimer > 3600) fruitsToSpawn = 2; // After 1 minute, spawn 2 fruits
if (difficultyTimer > 7200) fruitsToSpawn = 3; // After 2 minutes, spawn 3 fruits
if (difficultyTimer > 10800) fruitsToSpawn = 4; // After 3 minutes, spawn 4 fruits
if (spawnTimer >= spawnInterval) {
for (var j = 0; j < fruitsToSpawn; j++) {
spawnFruit();
}
spawnTimer = 0;
}
// Spawn bombs occasionally
if (bombSpawnTimer >= bombSpawnInterval) {
spawnBomb();
bombSpawnTimer = 0;
}
// Spawn dragon fruit occasionally after first 10 seconds (every 600 ticks = 10 seconds)
if (gameStartTimer >= 600 && LK.ticks % 600 == 0) {
spawnDragonFruit();
}
// Spawn watermelon every 5 seconds
if (watermelonSpawnTimer >= watermelonSpawnInterval) {
spawnWatermelon();
watermelonSpawnTimer = 0;
}
// Spawn health kit rarely (every 30 seconds)
if (healthKitSpawnTimer >= healthKitSpawnInterval) {
spawnHealthKit();
healthKitSpawnTimer = 0;
}
// Update fruits
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
// Check if fruit went off screen
if (fruit.lastY < 2732 + 100 && fruit.y >= 2732 + 100) {
// Play fruit fall sound
LK.getSound('fruitFall').play();
// Lose a life for missing fruit
lives--;
livesTxt.setText('Lives: ' + lives);
// Check if game over
if (lives <= 0) {
LK.getSound('gameOver').play();
gameEnded = true;
LK.showGameOver();
return;
}
// Penalty for missing fruit
LK.setScore(LK.getScore() - 50);
scoreTxt.setText('Score: ' + LK.getScore());
fruit.destroy();
fruits.splice(i, 1);
continue;
}
// Check collision with ninja
var currentIntersecting = fruit.intersects(ninja);
if (!fruit.lastIntersecting && currentIntersecting) {
LK.setScore(LK.getScore() + fruit.points);
scoreTxt.setText('Score: ' + LK.getScore());
// Play catch sound effect
LK.getSound('fruitCatch').play();
// Enhanced visual feedback with bounce effect
tween(fruit, {
scaleX: 1.8,
scaleY: 1.8,
alpha: 0.3,
rotation: Math.PI
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
fruit.destroy();
}
});
// Additional sparkle effect - create a brief flash
LK.effects.flashObject(fruit, 0xFFD700, 200);
fruits.splice(i, 1);
continue;
}
fruit.lastY = fruit.y;
fruit.lastIntersecting = currentIntersecting;
}
// Update bombs
for (var k = bombs.length - 1; k >= 0; k--) {
var bomb = bombs[k];
// Check if bomb went off screen
if (bomb.lastY < 2732 + 100 && bomb.y >= 2732 + 100) {
bomb.destroy();
bombs.splice(k, 1);
continue;
}
// Check collision with ninja
var bombIntersecting = bomb.intersects(ninja);
if (!bomb.lastIntersecting && bombIntersecting) {
// Lose a life for hitting bomb
lives--;
livesTxt.setText('Lives: ' + lives);
// Check if game over
if (lives <= 0) {
LK.getSound('gameOver').play();
gameEnded = true;
LK.showGameOver();
return;
}
LK.setScore(LK.getScore() - bomb.penalty);
scoreTxt.setText('Score: ' + LK.getScore());
// Play explosion sound effect
LK.getSound('bombExplosion').play();
// Play ninja pain sound
LK.getSound('ninjaPain').play();
// Enhanced explosion visual effects
tween(bomb, {
scaleX: 2.5,
scaleY: 2.5,
alpha: 0,
rotation: Math.PI * 2
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
bomb.destroy();
}
});
// Flash effect for bomb hit
LK.effects.flashScreen(0xFF0000, 500);
// Additional explosive flash effect on the bomb itself
LK.effects.flashObject(bomb, 0xFFFFFF, 300);
bombs.splice(k, 1);
continue;
}
bomb.lastY = bomb.y;
bomb.lastIntersecting = bombIntersecting;
}
// Update dragon fruits
for (var d = dragonFruits.length - 1; d >= 0; d--) {
var dragonFruit = dragonFruits[d];
// Check if dragon fruit went off screen
if (dragonFruit.lastY < 2732 + 100 && dragonFruit.y >= 2732 + 100) {
// Play fruit fall sound
LK.getSound('fruitFall').play();
// Lose a life for missing dragon fruit
lives--;
livesTxt.setText('Lives: ' + lives);
// Check if game over
if (lives <= 0) {
LK.getSound('gameOver').play();
gameEnded = true;
LK.showGameOver();
return;
}
// Penalty for missing dragon fruit
LK.setScore(LK.getScore() - 75);
scoreTxt.setText('Score: ' + LK.getScore());
dragonFruit.destroy();
dragonFruits.splice(d, 1);
continue;
}
// Check collision with ninja
var dragonIntersecting = dragonFruit.intersects(ninja);
if (!dragonFruit.lastIntersecting && dragonIntersecting) {
LK.setScore(LK.getScore() + dragonFruit.points);
scoreTxt.setText('Score: ' + LK.getScore());
// Play catch sound effect
LK.getSound('fruitCatch').play();
// Enhanced visual feedback with special dragon fruit effect
tween(dragonFruit, {
scaleX: 2.2,
scaleY: 2.2,
alpha: 0.2,
rotation: Math.PI * 2
}, {
duration: 400,
easing: tween.bounceOut,
onFinish: function onFinish() {
dragonFruit.destroy();
}
});
// Special golden flash for dragon fruit
LK.effects.flashObject(dragonFruit, 0xFFD700, 300);
LK.effects.flashScreen(0xFFD700, 200);
dragonFruits.splice(d, 1);
continue;
}
dragonFruit.lastY = dragonFruit.y;
dragonFruit.lastIntersecting = dragonIntersecting;
}
// Update watermelons
for (var w = watermelons.length - 1; w >= 0; w--) {
var watermelon = watermelons[w];
// Check if watermelon went off screen
if (watermelon.lastY < 2732 + 100 && watermelon.y >= 2732 + 100) {
// Play fruit fall sound
LK.getSound('fruitFall').play();
// Lose a life for missing watermelon
lives--;
livesTxt.setText('Lives: ' + lives);
// Check if game over
if (lives <= 0) {
LK.getSound('gameOver').play();
gameEnded = true;
LK.showGameOver();
return;
}
// Penalty for missing watermelon
LK.setScore(LK.getScore() - 50);
scoreTxt.setText('Score: ' + LK.getScore());
watermelon.destroy();
watermelons.splice(w, 1);
continue;
}
// Check collision with ninja
var watermelonIntersecting = watermelon.intersects(ninja);
if (!watermelon.lastIntersecting && watermelonIntersecting) {
LK.setScore(LK.getScore() + watermelon.points);
scoreTxt.setText('Score: ' + LK.getScore());
// Play catch sound effect
LK.getSound('fruitCatch').play();
// Enhanced visual feedback with bounce effect
tween(watermelon, {
scaleX: 1.8,
scaleY: 1.8,
alpha: 0.3,
rotation: Math.PI
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
watermelon.destroy();
}
});
// Additional sparkle effect - create a brief flash
LK.effects.flashObject(watermelon, 0xFFD700, 200);
watermelons.splice(w, 1);
continue;
}
watermelon.lastY = watermelon.y;
watermelon.lastIntersecting = watermelonIntersecting;
}
// Update health kits
for (var h = healthKits.length - 1; h >= 0; h--) {
var healthKit = healthKits[h];
// Check if health kit went off screen (no penalty or points)
if (healthKit.lastY < 2732 + 100 && healthKit.y >= 2732 + 100) {
healthKit.destroy();
healthKits.splice(h, 1);
continue;
}
// Check collision with ninja
var healthKitIntersecting = healthKit.intersects(ninja);
if (!healthKit.lastIntersecting && healthKitIntersecting) {
// Gain a life (max 5 lives)
if (lives < 5) {
lives++;
livesTxt.setText('Lives: ' + lives);
}
// Play health kit catch sound effect
LK.getSound('healthCatch').play();
// Enhanced visual feedback with healing effect
tween(healthKit, {
scaleX: 2.0,
scaleY: 2.0,
alpha: 0.2,
rotation: Math.PI
}, {
duration: 350,
easing: tween.bounceOut,
onFinish: function onFinish() {
healthKit.destroy();
}
});
// Special green flash for health kit
LK.effects.flashObject(healthKit, 0x00FF00, 300);
LK.effects.flashScreen(0x00FF00, 150);
healthKits.splice(h, 1);
continue;
}
healthKit.lastY = healthKit.y;
healthKit.lastIntersecting = healthKitIntersecting;
}
};
// Start background music when game begins
LK.playMusic('bgmusic');
An apple. 2d. High contrast. No shadows
Banana. 2d. High contrast. No shadows
An orange. 2d. High contrast. No shadows
A grape. 2d. High contrast. No shadows
Cute Ninja. 2d. High contrast. No shadows
Wooden Background
A bomb. In-Game asset. 2d. High contrast. No shadows
A dragonfruit. In-Game asset. 2d. High contrast. No shadows
Wooden platfom straigth. In-Game asset. 2d. High contrast. No shadows
A watermelon. In-Game asset. 2d. High contrast. No shadows
A health kit. In-Game asset. 2d. High contrast. No shadows