/**** * Classes ****/ //<Write imports for supported plugins here> // Character class with gravity and jump functionality var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.velocityY = 0; self.gravity = 0.5; self.jumpStrength = -15; self.update = function () { self.velocityY += self.gravity; self.y += self.velocityY; // Prevent character from falling through the ground if (self.y > 2732 - 100) { self.y = 2732 - 100; self.velocityY = 0; } }; self.jump = function () { if (self.y >= 2732 - 100) { // Allow jump only if on the ground self.velocityY = self.jumpStrength; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize assets used in this game. // Create and position the character in the middle of the screen var character = game.addChild(new Character()); character.x = 2048 / 2; character.y = 2732 / 2; // Create and position the sky at the top of the screen var sky = LK.getAsset('sky', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 5 }); game.addChild(sky); // Create and position the ground at the bottom of the screen var ground = LK.getAsset('ground', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 - 5 }); game.addChild(ground); // Create and position the tube off the right side of the screen var tube = LK.getAsset('tube', { anchorX: 0.5, anchorY: 0.5, x: 2048 + 50, y: 2732 - 150 }); game.addChild(tube); // Handle touch events to make the character jump game.down = function (x, y, obj) { character.jump(); }; // Update game state every tick game.update = function () { character.update(); };
===================================================================
--- original.js
+++ change.js
@@ -9,10 +9,10 @@
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
- self.gravity = 0.3;
- self.jumpStrength = -20;
+ self.gravity = 0.5;
+ self.jumpStrength = -15;
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Prevent character from falling through the ground
@@ -42,9 +42,9 @@
// Initialize assets used in this game.
// Create and position the character in the middle of the screen
var character = game.addChild(new Character());
character.x = 2048 / 2;
-character.y = 2732 - 100;
+character.y = 2732 / 2;
// Create and position the sky at the top of the screen
var sky = LK.getAsset('sky', {
anchorX: 0.5,
anchorY: 0.5,