User prompt
perbaiki suara musik sebab tidak keluar
User prompt
kalau katak terkenan burung hantu langsung game over
User prompt
buat tambahan asset burung hantu yang terbang agak jauh diatas serangga terbang horizontal bolak balik ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
buat platpormnya di bawah katak
User prompt
buat image platform di bawah katak
User prompt
add background asset
User prompt
adakan asset latar belakang sebab saya ingin menambahkan wallpaper
User prompt
serangga kecil bisa jadi makanan dan point untuk katak
User prompt
buat serangga terbang kecil berkeliaran di antara paltform. buat gerak vertikal naik turun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
perbaiki game tidak respon saat tap
User prompt
meteran lompat tampilkan di layar kiri atas
User prompt
buat aturan kalau tidak sampai jatuh dan game over
Code edit (1 edits merged)
Please save this source code
User prompt
Frog Jump Champion
Initial prompt
buat game kodok melompat bisa long jump dengan ada meteran lompat. buat random platform generate
/**** * 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; } } } 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 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 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 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 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); } } } generatePlatforms(); generateInsects(); // 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); } } } } 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'); updateCamera(); };
===================================================================
--- original.js
+++ change.js
@@ -98,8 +98,44 @@
}
};
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,
@@ -170,8 +206,9 @@
****/
// Game variables
var frog;
var platforms = [];
+var insects = [];
var jumpMeter;
var jumpDistance = 0;
var bestDistance = storage.bestDistance || 0;
var isCharging = false;
@@ -206,27 +243,41 @@
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);
+ }
+ }
+}
generatePlatforms();
-// Create jump meter in GUI overlay (top-left)
-jumpMeter = LK.gui.topLeft.addChild(new JumpMeter());
-jumpMeter.x = 150;
-jumpMeter.y = 350;
+generateInsects();
+// Create jump meter
+jumpMeter = game.addChild(new JumpMeter());
+jumpMeter.x = 200;
+jumpMeter.y = 2200;
// Input handling
game.down = function (x, y, obj) {
- if (!isCharging && !frog.isJumping) {
+ if (frog.onGround && !isCharging) {
isCharging = true;
jumpMeter.startCharging();
}
};
game.up = function (x, y, obj) {
- if (isCharging) {
+ if (isCharging && frog.onGround) {
isCharging = false;
var power = jumpMeter.stopCharging();
- if (frog.onGround) {
- frog.startJump(power);
- }
+ frog.startJump(power);
}
};
// Camera following
function updateCamera() {
@@ -237,16 +288,29 @@
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);
+ }
+ }
}
}
game.update = function () {
// Update distance display