User prompt
Don’t set jump force on move
User prompt
Increase jump power by 2x
User prompt
Increase jump power by 30%
User prompt
Decrease the jump power by a factor of 100
User prompt
Decrease the power of jumps by a factor of 100
User prompt
Jump force should be calculated based on the office from the initial touch point when releasing
User prompt
Have both x and y velocity for the player
User prompt
Make jumping based on dragging back and releasing, like a spring. You should be able to start dragging from anywhere on the screen
User prompt
Don’t start moving until I jump the first time
User prompt
The ground should move down along with the platforms
User prompt
Add a ground to the game that the player initially stands on
User prompt
Progress game
Initial prompt
Jumping game
var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', .5, .5); self.gravity = 1; self.jumpForce = 20; self.velocity = 0; self.setJumpForce = function (x, y) { var dx = this.x - x; var dy = this.y - y; this.jumpForce = Math.sqrt(dx * dx + dy * dy) / 10; }; self.update = function () { this.y += this.velocity; this.velocity += this.gravity; if (this.y > 2732) { this.y = 2732; this.velocity = 0; } }; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.createAsset('platform', 'Platform', .5, .5); self.speed = 5; self.move = function () { this.y += this.speed; }; }); var Game = Container.expand(function () { var self = Container.call(this); stage.on('up', function (obj) { if (dragStart) { player.velocity = -player.jumpForce; dragStart = null; } }); stage.on('move', function (obj) { if (dragStart) { var pos = obj.event.getLocalPosition(self); player.setJumpForce(dragStart.x, dragStart.y); } }); var platforms = []; var ground = self.createAsset('ground', 'Ground', 0, 1); ground.y = 2732; ground.speed = 5; ground.move = function () { this.y += this.speed; if (this.y > 2732) { this.y = 0; } }; var player = self.addChild(new Player()); player.x = 2048 / 2; player.y = ground.y - player.height; var firstJump = false; for (var i = 0; i < 5; i++) { var platform = new Platform(); platform.x = Math.random() * 2048; platform.y = i * (2732 / 5); platforms.push(platform); self.addChild(platform); } LK.on('tick', function () { player.update(); if (firstJump) { ground.move(); for (var i = 0; i < platforms.length; i++) { platforms[i].move(); if (platforms[i].y > 2732) { platforms[i].y = 0; platforms[i].x = Math.random() * 2048; } if (player.intersects(platforms[i]) && player.velocity > 0) { player.jump(); } } } }); var dragStart = null; stage.on('down', function (obj) { dragStart = obj.event.getLocalPosition(self); }); });
===================================================================
--- original.js
+++ change.js
@@ -3,10 +3,12 @@
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
self.gravity = 1;
self.jumpForce = 20;
self.velocity = 0;
- self.jump = function () {
- this.velocity = -this.jumpForce;
+ self.setJumpForce = function (x, y) {
+ var dx = this.x - x;
+ var dy = this.y - y;
+ this.jumpForce = Math.sqrt(dx * dx + dy * dy) / 10;
};
self.update = function () {
this.y += this.velocity;
this.velocity += this.gravity;
@@ -25,8 +27,20 @@
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
+ stage.on('up', function (obj) {
+ if (dragStart) {
+ player.velocity = -player.jumpForce;
+ dragStart = null;
+ }
+ });
+ stage.on('move', function (obj) {
+ if (dragStart) {
+ var pos = obj.event.getLocalPosition(self);
+ player.setJumpForce(dragStart.x, dragStart.y);
+ }
+ });
var platforms = [];
var ground = self.createAsset('ground', 'Ground', 0, 1);
ground.y = 2732;
ground.speed = 5;
@@ -62,13 +76,9 @@
}
}
}
});
+ var dragStart = null;
stage.on('down', function (obj) {
- var event = obj.event;
- var pos = event.getLocalPosition(self);
- if (player.intersects(pos)) {
- player.jump();
- firstJump = true;
- }
+ dragStart = obj.event.getLocalPosition(self);
});
});
Single cartoon frog sitting. Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Cartoon lillypad seen edge on. No flower Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cozy cartoon swamp background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.