/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Frog = Container.expand(function () {
var self = Container.call(this);
var frogGraphics = self.attachAsset('frog', {
anchorX: 0.5,
anchorY: 1.0
});
self.isJumping = false;
self.jumpPower = 0;
self.velocityX = 0;
self.velocityY = 0;
self.onGround = true;
self.startJump = function (power) {
if (!self.onGround) return;
self.isJumping = true;
self.onGround = false;
self.jumpPower = power;
// Convert power to velocity
var maxVelocityX = 25;
var maxVelocityY = -30;
self.velocityX = maxVelocityX * power;
self.velocityY = maxVelocityY * power;
LK.getSound('jump').play();
};
self.update = function () {
if (self.isJumping) {
// Apply gravity
self.velocityY += 1.2;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Check if landed on ground or platform
var landed = false;
// Check platform landings
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.x >= platform.x - 150 && self.x <= platform.x + 150) {
if (self.y >= platform.y - 30 && self.velocityY > 0) {
self.y = platform.y - 30;
landed = true;
break;
}
}
}
// Check if frog has fallen too far below any nearby platform (game over condition)
var gameOver = false;
if (self.y > 2732) {
gameOver = true;
} else if (self.isJumping && self.velocityY > 0) {
// Check if frog is falling and has passed below all nearby platforms
var nearbyPlatforms = [];
for (var j = 0; j < platforms.length; j++) {
var platform = platforms[j];
if (Math.abs(platform.x - self.x) < 800) {
nearbyPlatforms.push(platform);
}
}
if (nearbyPlatforms.length > 0) {
var lowestPlatform = nearbyPlatforms[0];
for (var k = 1; k < nearbyPlatforms.length; k++) {
if (nearbyPlatforms[k].y > lowestPlatform.y) {
lowestPlatform = nearbyPlatforms[k];
}
}
// If frog is more than 200 pixels below the lowest nearby platform, game over
if (self.y > lowestPlatform.y + 200) {
gameOver = true;
}
}
}
// Check for insect collisions while jumping or moving
for (var insectIndex = insects.length - 1; insectIndex >= 0; insectIndex--) {
var insect = insects[insectIndex];
if (self.intersects(insect)) {
// Eat the insect - add points and remove it
LK.setScore(LK.getScore() + 10);
insect.destroy();
insects.splice(insectIndex, 1);
}
}
// Check for owl collisions - game over if hit
for (var owlIndex = 0; owlIndex < owls.length; owlIndex++) {
var owl = owls[owlIndex];
if (self.intersects(owl)) {
// Hit by owl - game over immediately
LK.showGameOver();
return;
}
}
if (landed || gameOver) {
self.velocityX = 0;
self.velocityY = 0;
self.isJumping = false;
self.onGround = true;
if (landed) {
LK.getSound('land').play();
// Update distance if this is a new record
var currentDistance = Math.floor(self.x / 100);
if (currentDistance > bestDistance) {
bestDistance = currentDistance;
storage.bestDistance = bestDistance;
}
jumpDistance = currentDistance;
} else {
// Fell off screen or missed platforms - game over
LK.showGameOver();
}
}
}
};
return self;
});
var Insect = Container.expand(function (x, y) {
var self = Container.call(this);
var insectGraphics = self.attachAsset('insect', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.startY = y;
self.movementRange = 150;
self.startVerticalMovement = function () {
// Start moving down
tween(self, {
y: self.startY + self.movementRange
}, {
duration: 2000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Move back up
tween(self, {
y: self.startY - self.movementRange
}, {
duration: 2000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the cycle
self.startVerticalMovement();
}
});
}
});
};
// Start the movement cycle immediately
self.startVerticalMovement();
return self;
});
var JumpMeter = Container.expand(function () {
var self = Container.call(this);
var meterBg = self.attachAsset('jumpMeterBg', {
anchorX: 0.5,
anchorY: 1.0
});
var meterFill = self.attachAsset('jumpMeterFill', {
anchorX: 0.5,
anchorY: 1.0
});
self.power = 0;
self.charging = false;
self.direction = 1;
self.startCharging = function () {
self.charging = true;
self.power = 0;
self.direction = 1;
};
self.stopCharging = function () {
self.charging = false;
var finalPower = self.power;
self.power = 0;
return finalPower;
};
self.update = function () {
if (self.charging) {
self.power += self.direction * 0.03;
if (self.power >= 1.0) {
self.power = 1.0;
self.direction = -1;
} else if (self.power <= 0) {
self.power = 0;
self.direction = 1;
}
}
// Update fill height and color
var fillHeight = 290 * self.power;
meterFill.height = fillHeight;
meterFill.y = -2;
// Color coding: green in optimal zone (0.7-0.9), red otherwise
if (self.power >= 0.7 && self.power <= 0.9) {
meterFill.tint = 0x44FF44;
} else {
meterFill.tint = 0xFF4444;
}
};
return self;
});
var Owl = Container.expand(function (x, y) {
var self = Container.call(this);
var owlGraphics = self.attachAsset('owl', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.startX = x;
self.movementRange = 400;
self.startHorizontalMovement = function () {
// Move right
tween(self, {
x: self.startX + self.movementRange
}, {
duration: 3000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Move back left
tween(self, {
x: self.startX - self.movementRange
}, {
duration: 3000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the cycle
self.startHorizontalMovement();
}
});
}
});
};
// Start the movement cycle immediately
self.startHorizontalMovement();
return self;
});
var Platform = Container.expand(function (x, y) {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var frog;
var platforms = [];
var insects = [];
var owls = [];
var jumpMeter;
var jumpDistance = 0;
var bestDistance = storage.bestDistance || 0;
var isCharging = false;
// UI elements
var distanceText = new Text2('Distance: 0m', {
size: 60,
fill: 0x000000
});
distanceText.anchor.set(0.5, 0);
LK.gui.top.addChild(distanceText);
distanceText.y = 150;
var scoreText = new Text2('Score: 0', {
size: 50,
fill: 0x000000
});
scoreText.anchor.set(0, 0);
LK.gui.top.addChild(scoreText);
scoreText.x = -400;
scoreText.y = 50;
var bestText = new Text2('Best: ' + bestDistance + 'm', {
size: 50,
fill: 0x000000
});
bestText.anchor.set(1, 0);
LK.gui.topRight.addChild(bestText);
bestText.y = 100;
bestText.x = -20;
// Create frog
frog = game.addChild(new Frog());
frog.x = 400;
frog.y = 2200;
// Create starting platform underneath the frog
var startPlatform = game.addChild(new Platform(400, 2230));
platforms.push(startPlatform);
// Generate initial platforms
function generatePlatforms() {
for (var i = 1; i <= 20; i++) {
var x = 400 + i * 600 + (Math.random() - 0.5) * 200;
var y = 2230 + (Math.random() - 0.5) * 400;
var platform = game.addChild(new Platform(x, y));
platforms.push(platform);
}
}
// Generate initial insects
function generateInsects() {
for (var i = 0; i < platforms.length - 1; i++) {
var platform1 = platforms[i];
var platform2 = platforms[i + 1];
// Create 1-2 insects between each pair of platforms
var numInsects = 1 + Math.floor(Math.random() * 2);
for (var j = 0; j < numInsects; j++) {
var x = platform1.x + (platform2.x - platform1.x) * (0.3 + Math.random() * 0.4);
var y = Math.min(platform1.y, platform2.y) - 100 - Math.random() * 200;
var insect = game.addChild(new Insect(x, y));
insects.push(insect);
}
}
}
// Generate initial owls
function generateOwls() {
for (var i = 0; i < platforms.length - 1; i++) {
var platform1 = platforms[i];
var platform2 = platforms[i + 1];
// Create 1 owl high above the platforms (every 2-3 platform pairs)
if (i % 3 === 0) {
var x = platform1.x + (platform2.x - platform1.x) * 0.5;
var y = Math.min(platform1.y, platform2.y) - 300 - Math.random() * 200;
var owl = game.addChild(new Owl(x, y));
owls.push(owl);
}
}
}
generatePlatforms();
generateInsects();
generateOwls();
// Create jump meter
jumpMeter = game.addChild(new JumpMeter());
jumpMeter.x = 200;
jumpMeter.y = 2200;
// Input handling
game.down = function (x, y, obj) {
if (frog.onGround && !isCharging) {
isCharging = true;
jumpMeter.startCharging();
}
};
game.up = function (x, y, obj) {
if (isCharging && frog.onGround) {
isCharging = false;
var power = jumpMeter.stopCharging();
frog.startJump(power);
}
};
// Camera following
function updateCamera() {
var targetX = -frog.x + 1024;
var targetY = -frog.y + 1800;
// Smooth camera movement
game.x += (targetX - game.x) * 0.1;
game.y += (targetY - game.y) * 0.1;
// Generate more platforms if needed
var rightmostPlatform = platforms[platforms.length - 1];
if (frog.x > rightmostPlatform.x - 2000) {
var startIndex = platforms.length - 1;
for (var i = 0; i < 5; i++) {
var lastX = rightmostPlatform.x;
var x = lastX + 600 + Math.random() * 400;
var y = 2230 + (Math.random() - 0.5) * 400;
var platform = game.addChild(new Platform(x, y));
platforms.push(platform);
rightmostPlatform = platform;
}
// Generate insects for the new platforms
for (var k = startIndex; k < platforms.length - 1; k++) {
var platform1 = platforms[k];
var platform2 = platforms[k + 1];
var numInsects = 1 + Math.floor(Math.random() * 2);
for (var m = 0; m < numInsects; m++) {
var insectX = platform1.x + (platform2.x - platform1.x) * (0.3 + Math.random() * 0.4);
var insectY = Math.min(platform1.y, platform2.y) - 100 - Math.random() * 200;
var newInsect = game.addChild(new Insect(insectX, insectY));
insects.push(newInsect);
}
}
// Generate owls for the new platforms
for (var n = startIndex; n < platforms.length - 1; n++) {
if (n % 3 === 0) {
var owlPlatform1 = platforms[n];
var owlPlatform2 = platforms[n + 1];
var owlX = owlPlatform1.x + (owlPlatform2.x - owlPlatform1.x) * 0.5;
var owlY = Math.min(owlPlatform1.y, owlPlatform2.y) - 300 - Math.random() * 200;
var newOwl = game.addChild(new Owl(owlX, owlY));
owls.push(newOwl);
}
}
}
}
// Start background music
LK.playMusic('1suaradanaudimalamhari');
game.update = function () {
// Update distance display
jumpDistance = Math.floor(Math.max(0, frog.x - 400) / 100);
distanceText.setText('Distance: ' + jumpDistance + 'm');
bestText.setText('Best: ' + bestDistance + 'm');
scoreText.setText('Score: ' + LK.getScore());
updateCamera();
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Frog = Container.expand(function () {
var self = Container.call(this);
var frogGraphics = self.attachAsset('frog', {
anchorX: 0.5,
anchorY: 1.0
});
self.isJumping = false;
self.jumpPower = 0;
self.velocityX = 0;
self.velocityY = 0;
self.onGround = true;
self.startJump = function (power) {
if (!self.onGround) return;
self.isJumping = true;
self.onGround = false;
self.jumpPower = power;
// Convert power to velocity
var maxVelocityX = 25;
var maxVelocityY = -30;
self.velocityX = maxVelocityX * power;
self.velocityY = maxVelocityY * power;
LK.getSound('jump').play();
};
self.update = function () {
if (self.isJumping) {
// Apply gravity
self.velocityY += 1.2;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Check if landed on ground or platform
var landed = false;
// Check platform landings
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.x >= platform.x - 150 && self.x <= platform.x + 150) {
if (self.y >= platform.y - 30 && self.velocityY > 0) {
self.y = platform.y - 30;
landed = true;
break;
}
}
}
// Check if frog has fallen too far below any nearby platform (game over condition)
var gameOver = false;
if (self.y > 2732) {
gameOver = true;
} else if (self.isJumping && self.velocityY > 0) {
// Check if frog is falling and has passed below all nearby platforms
var nearbyPlatforms = [];
for (var j = 0; j < platforms.length; j++) {
var platform = platforms[j];
if (Math.abs(platform.x - self.x) < 800) {
nearbyPlatforms.push(platform);
}
}
if (nearbyPlatforms.length > 0) {
var lowestPlatform = nearbyPlatforms[0];
for (var k = 1; k < nearbyPlatforms.length; k++) {
if (nearbyPlatforms[k].y > lowestPlatform.y) {
lowestPlatform = nearbyPlatforms[k];
}
}
// If frog is more than 200 pixels below the lowest nearby platform, game over
if (self.y > lowestPlatform.y + 200) {
gameOver = true;
}
}
}
// Check for insect collisions while jumping or moving
for (var insectIndex = insects.length - 1; insectIndex >= 0; insectIndex--) {
var insect = insects[insectIndex];
if (self.intersects(insect)) {
// Eat the insect - add points and remove it
LK.setScore(LK.getScore() + 10);
insect.destroy();
insects.splice(insectIndex, 1);
}
}
// Check for owl collisions - game over if hit
for (var owlIndex = 0; owlIndex < owls.length; owlIndex++) {
var owl = owls[owlIndex];
if (self.intersects(owl)) {
// Hit by owl - game over immediately
LK.showGameOver();
return;
}
}
if (landed || gameOver) {
self.velocityX = 0;
self.velocityY = 0;
self.isJumping = false;
self.onGround = true;
if (landed) {
LK.getSound('land').play();
// Update distance if this is a new record
var currentDistance = Math.floor(self.x / 100);
if (currentDistance > bestDistance) {
bestDistance = currentDistance;
storage.bestDistance = bestDistance;
}
jumpDistance = currentDistance;
} else {
// Fell off screen or missed platforms - game over
LK.showGameOver();
}
}
}
};
return self;
});
var Insect = Container.expand(function (x, y) {
var self = Container.call(this);
var insectGraphics = self.attachAsset('insect', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.startY = y;
self.movementRange = 150;
self.startVerticalMovement = function () {
// Start moving down
tween(self, {
y: self.startY + self.movementRange
}, {
duration: 2000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Move back up
tween(self, {
y: self.startY - self.movementRange
}, {
duration: 2000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the cycle
self.startVerticalMovement();
}
});
}
});
};
// Start the movement cycle immediately
self.startVerticalMovement();
return self;
});
var JumpMeter = Container.expand(function () {
var self = Container.call(this);
var meterBg = self.attachAsset('jumpMeterBg', {
anchorX: 0.5,
anchorY: 1.0
});
var meterFill = self.attachAsset('jumpMeterFill', {
anchorX: 0.5,
anchorY: 1.0
});
self.power = 0;
self.charging = false;
self.direction = 1;
self.startCharging = function () {
self.charging = true;
self.power = 0;
self.direction = 1;
};
self.stopCharging = function () {
self.charging = false;
var finalPower = self.power;
self.power = 0;
return finalPower;
};
self.update = function () {
if (self.charging) {
self.power += self.direction * 0.03;
if (self.power >= 1.0) {
self.power = 1.0;
self.direction = -1;
} else if (self.power <= 0) {
self.power = 0;
self.direction = 1;
}
}
// Update fill height and color
var fillHeight = 290 * self.power;
meterFill.height = fillHeight;
meterFill.y = -2;
// Color coding: green in optimal zone (0.7-0.9), red otherwise
if (self.power >= 0.7 && self.power <= 0.9) {
meterFill.tint = 0x44FF44;
} else {
meterFill.tint = 0xFF4444;
}
};
return self;
});
var Owl = Container.expand(function (x, y) {
var self = Container.call(this);
var owlGraphics = self.attachAsset('owl', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.startX = x;
self.movementRange = 400;
self.startHorizontalMovement = function () {
// Move right
tween(self, {
x: self.startX + self.movementRange
}, {
duration: 3000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Move back left
tween(self, {
x: self.startX - self.movementRange
}, {
duration: 3000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the cycle
self.startHorizontalMovement();
}
});
}
});
};
// Start the movement cycle immediately
self.startHorizontalMovement();
return self;
});
var Platform = Container.expand(function (x, y) {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var frog;
var platforms = [];
var insects = [];
var owls = [];
var jumpMeter;
var jumpDistance = 0;
var bestDistance = storage.bestDistance || 0;
var isCharging = false;
// UI elements
var distanceText = new Text2('Distance: 0m', {
size: 60,
fill: 0x000000
});
distanceText.anchor.set(0.5, 0);
LK.gui.top.addChild(distanceText);
distanceText.y = 150;
var scoreText = new Text2('Score: 0', {
size: 50,
fill: 0x000000
});
scoreText.anchor.set(0, 0);
LK.gui.top.addChild(scoreText);
scoreText.x = -400;
scoreText.y = 50;
var bestText = new Text2('Best: ' + bestDistance + 'm', {
size: 50,
fill: 0x000000
});
bestText.anchor.set(1, 0);
LK.gui.topRight.addChild(bestText);
bestText.y = 100;
bestText.x = -20;
// Create frog
frog = game.addChild(new Frog());
frog.x = 400;
frog.y = 2200;
// Create starting platform underneath the frog
var startPlatform = game.addChild(new Platform(400, 2230));
platforms.push(startPlatform);
// Generate initial platforms
function generatePlatforms() {
for (var i = 1; i <= 20; i++) {
var x = 400 + i * 600 + (Math.random() - 0.5) * 200;
var y = 2230 + (Math.random() - 0.5) * 400;
var platform = game.addChild(new Platform(x, y));
platforms.push(platform);
}
}
// Generate initial insects
function generateInsects() {
for (var i = 0; i < platforms.length - 1; i++) {
var platform1 = platforms[i];
var platform2 = platforms[i + 1];
// Create 1-2 insects between each pair of platforms
var numInsects = 1 + Math.floor(Math.random() * 2);
for (var j = 0; j < numInsects; j++) {
var x = platform1.x + (platform2.x - platform1.x) * (0.3 + Math.random() * 0.4);
var y = Math.min(platform1.y, platform2.y) - 100 - Math.random() * 200;
var insect = game.addChild(new Insect(x, y));
insects.push(insect);
}
}
}
// Generate initial owls
function generateOwls() {
for (var i = 0; i < platforms.length - 1; i++) {
var platform1 = platforms[i];
var platform2 = platforms[i + 1];
// Create 1 owl high above the platforms (every 2-3 platform pairs)
if (i % 3 === 0) {
var x = platform1.x + (platform2.x - platform1.x) * 0.5;
var y = Math.min(platform1.y, platform2.y) - 300 - Math.random() * 200;
var owl = game.addChild(new Owl(x, y));
owls.push(owl);
}
}
}
generatePlatforms();
generateInsects();
generateOwls();
// Create jump meter
jumpMeter = game.addChild(new JumpMeter());
jumpMeter.x = 200;
jumpMeter.y = 2200;
// Input handling
game.down = function (x, y, obj) {
if (frog.onGround && !isCharging) {
isCharging = true;
jumpMeter.startCharging();
}
};
game.up = function (x, y, obj) {
if (isCharging && frog.onGround) {
isCharging = false;
var power = jumpMeter.stopCharging();
frog.startJump(power);
}
};
// Camera following
function updateCamera() {
var targetX = -frog.x + 1024;
var targetY = -frog.y + 1800;
// Smooth camera movement
game.x += (targetX - game.x) * 0.1;
game.y += (targetY - game.y) * 0.1;
// Generate more platforms if needed
var rightmostPlatform = platforms[platforms.length - 1];
if (frog.x > rightmostPlatform.x - 2000) {
var startIndex = platforms.length - 1;
for (var i = 0; i < 5; i++) {
var lastX = rightmostPlatform.x;
var x = lastX + 600 + Math.random() * 400;
var y = 2230 + (Math.random() - 0.5) * 400;
var platform = game.addChild(new Platform(x, y));
platforms.push(platform);
rightmostPlatform = platform;
}
// Generate insects for the new platforms
for (var k = startIndex; k < platforms.length - 1; k++) {
var platform1 = platforms[k];
var platform2 = platforms[k + 1];
var numInsects = 1 + Math.floor(Math.random() * 2);
for (var m = 0; m < numInsects; m++) {
var insectX = platform1.x + (platform2.x - platform1.x) * (0.3 + Math.random() * 0.4);
var insectY = Math.min(platform1.y, platform2.y) - 100 - Math.random() * 200;
var newInsect = game.addChild(new Insect(insectX, insectY));
insects.push(newInsect);
}
}
// Generate owls for the new platforms
for (var n = startIndex; n < platforms.length - 1; n++) {
if (n % 3 === 0) {
var owlPlatform1 = platforms[n];
var owlPlatform2 = platforms[n + 1];
var owlX = owlPlatform1.x + (owlPlatform2.x - owlPlatform1.x) * 0.5;
var owlY = Math.min(owlPlatform1.y, owlPlatform2.y) - 300 - Math.random() * 200;
var newOwl = game.addChild(new Owl(owlX, owlY));
owls.push(newOwl);
}
}
}
}
// Start background music
LK.playMusic('1suaradanaudimalamhari');
game.update = function () {
// Update distance display
jumpDistance = Math.floor(Math.max(0, frog.x - 400) / 100);
distanceText.setText('Distance: ' + jumpDistance + 'm');
bestText.setText('Best: ' + bestDistance + 'm');
scoreText.setText('Score: ' + LK.getScore());
updateCamera();
};