Code edit (1 edits merged)
Please save this source code
User prompt
the hold duration should be correlated to the jump's height. the longer the finger is held, the higher the character should jump
User prompt
the player should not jump while the finger is pressed, instead it should only jump after the tap is released. So holding the finger on the screen should charge up the jump, and based on this duration, after releasing the finger, the jump isexecuted
Initial prompt
Hold to jump higher - no enemy
/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Define the Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 1.0 }); self.velocityY = 0; self.isJumping = false; self.jumpStartTime = 0; self.jumpCharge = 0; self.update = function () { if (self.isJumping) { self.jumpCharge = Math.min(20, LK.ticks - self.jumpStartTime); } else { self.velocityY += 1; // Gravity if (self.jumpCharge > 0) { self.velocityY = -self.jumpCharge * 10; // Multiply the jump charge by 2 to increase the jump height self.jumpCharge = 0; } } self.y += self.velocityY; // Prevent player from falling below the ground if (self.y > 2732 - playerGraphics.height) { self.y = 2732 - playerGraphics.height; self.velocityY = 0; } }; self.startJump = function () { self.isJumping = true; self.jumpStartTime = LK.ticks; }; self.endJump = function () { self.isJumping = false; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 100; game.down = function (x, y, obj) { player.startJump(); }; game.up = function (x, y, obj) { player.endJump(); }; game.update = function () { player.update(); };
===================================================================
--- original.js
+++ change.js
@@ -18,9 +18,9 @@
self.jumpCharge = Math.min(20, LK.ticks - self.jumpStartTime);
} else {
self.velocityY += 1; // Gravity
if (self.jumpCharge > 0) {
- self.velocityY = -self.jumpCharge * 2; // Multiply the jump charge by 2 to increase the jump height
+ self.velocityY = -self.jumpCharge * 10; // Multiply the jump charge by 2 to increase the jump height
self.jumpCharge = 0;
}
}
self.y += self.velocityY;
pixelated 8-bit cute sitting frog seen from the front. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelated 8-bit cute jumping frog seen from the front. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
background of a pond in the middle of the nature. pixelated 8-bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.