Idle animations for Boy

This commit is contained in:
Noah 2022-05-07 20:18:44 -07:00
parent 7005786a31
commit 94c4ed24d2
8 changed files with 29 additions and 9 deletions

View File

@ -5,6 +5,8 @@ build:
doodad convert -t "Boy" stand-right.png stand-left.png \ doodad convert -t "Boy" stand-right.png stand-left.png \
walk-right-1.png walk-right-2.png walk-right-3.png \ walk-right-1.png walk-right-2.png walk-right-3.png \
walk-left-1.png walk-left-2.png walk-left-3.png \ walk-left-1.png walk-left-2.png walk-left-3.png \
idle-right-1.png idle-right-2.png idle-right-3.png \
idle-left-1.png idle-left-2.png idle-left-3.png \
boy.doodad boy.doodad
doodad install-script boy.js boy.doodad doodad install-script boy.js boy.doodad

View File

@ -1,8 +1,9 @@
const playerSpeed = 12; const playerSpeed = 12;
let Vx = Vy = 0, let Vx = Vy = 0,
animating = false, walking = false,
animStart = animEnd = 0; direction = "right",
lastDirection = direction;
function main() { function main() {
Self.SetMobile(true); Self.SetMobile(true);
@ -11,6 +12,8 @@ function main() {
Self.SetHitbox(0, 0, 32, 52); Self.SetHitbox(0, 0, 32, 52);
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-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"]); Self.AddAnimation("walk-right", 200, ["stand-right", "walk-right-1", "walk-right-2", "walk-right-3", "walk-right-2", "walk-right-1"]);
Self.AddAnimation("idle-left", 200, ["idle-left-1", "idle-left-2", "idle-left-3", "idle-left-2"]);
Self.AddAnimation("idle-right", 200, ["idle-right-1", "idle-right-2", "idle-right-3", "idle-right-2"]);
// If the player suddenly changes direction, reset the animation state to quickly switch over. // If the player suddenly changes direction, reset the animation state to quickly switch over.
let lastVelocity = Vector(0, 0); let lastVelocity = Vector(0, 0);
@ -25,20 +28,35 @@ function main() {
Self.StopAnimation(); Self.StopAnimation();
} }
lastVelocity = curVelocity; lastVelocity = curVelocity;
lastDirection = direction;
let wasWalking = walking;
if (ev.Right) { if (ev.Right) {
if (!Self.IsAnimating()) { direction = "right";
Self.PlayAnimation("walk-right", null);
}
Vx = playerSpeed; Vx = playerSpeed;
walking = true;
} else if (ev.Left) { } else if (ev.Left) {
if (!Self.IsAnimating()) { direction = "left";
Self.PlayAnimation("walk-left", null);
}
Vx = -playerSpeed; Vx = -playerSpeed;
walking = true;
} else { } else {
// Has stopped walking!
walking = false;
stoppedWalking = true;
}
// Should we stop animating? (changed state)
if (direction !== lastDirection || wasWalking !== walking) {
Self.StopAnimation(); Self.StopAnimation();
animating = false; }
// And play what animation?
if (!Self.IsAnimating()) {
if (walking) {
Self.PlayAnimation("walk-"+direction, null);
} else {
Self.PlayAnimation("idle-"+direction, null);
}
} }
}) })
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB