Adjust Gravity and Prevent Moonwalking

* Tweak max gravity speed to match player max velocity.
* Boy's script watches for his velocity to flip suddenly and stops
  animations, limiting the moonwalking a bit.
* JS API: Self.GetVelocity() added.
master
Noah 2021-10-07 18:49:09 -07:00
parent 7702406579
commit 81dbb1e42a
1 changed files with 10 additions and 2 deletions

View File

@ -1,11 +1,9 @@
function main() {
var playerSpeed = 12;
var gravity = 4;
var Vx = Vy = 0;
var animating = false;
var animStart = animEnd = 0;
var animFrame = animStart;
Self.SetMobile(true);
Self.SetInventory(true);
@ -14,10 +12,20 @@ function main() {
Self.AddAnimation("walk-left", 200, ["stand-left", "walk-left-1", "walk-left-2", "walk-left-3", "walk-left-2", "walk-left-1"]);
Self.AddAnimation("walk-right", 200, ["stand-right", "walk-right-1", "walk-right-2", "walk-right-3", "walk-right-2", "walk-right-1"]);
// If the player suddenly changes direction, reset the animation state to quickly switch over.
var lastVelocity = Vector(0, 0);
Events.OnKeypress(function (ev) {
Vx = 0;
Vy = 0;
var curVelocity = Self.GetVelocity();
if ((lastVelocity.X < 0 && curVelocity.X > 0) ||
(lastVelocity.X > 0 && curVelocity.X < 0)) {
Self.StopAnimation();
}
lastVelocity = curVelocity;
if (ev.Right) {
if (!Self.IsAnimating()) {
Self.PlayAnimation("walk-right", null);