Idle animations for Boy

This commit is contained in:
Noah 2022-05-07 20:18:44 -07:00
parent 434416d3a4
commit 34c45095b5
10 changed files with 32 additions and 10 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

View File

@ -9,7 +9,7 @@ import (
const ( const (
AppName = "Sketchy Maze" AppName = "Sketchy Maze"
Summary = "A drawing-based maze game" Summary = "A drawing-based maze game"
Version = "0.12.1" Version = "0.13.0"
Website = "https://www.sketchymaze.com" Website = "https://www.sketchymaze.com"
Copyright = "2022 Noah Petherbridge" Copyright = "2022 Noah Petherbridge"
Byline = "a game by Noah Petherbridge." Byline = "a game by Noah Petherbridge."

View File

@ -3,6 +3,7 @@ package modal
import ( import (
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/cursor"
"git.kirsle.net/apps/doodle/pkg/keybind" "git.kirsle.net/apps/doodle/pkg/keybind"
"git.kirsle.net/apps/doodle/pkg/modal/loadscreen" "git.kirsle.net/apps/doodle/pkg/modal/loadscreen"
"git.kirsle.net/apps/doodle/pkg/shmem" "git.kirsle.net/apps/doodle/pkg/shmem"
@ -91,6 +92,7 @@ func Handled(ev *event.State) bool {
// Draw the modal UI to the screen. // Draw the modal UI to the screen.
func Draw() { func Draw() {
if ready && current != nil { if ready && current != nil {
cursor.Current = cursor.NewPointer(engine)
screen.Present(engine, render.Origin) screen.Present(engine, render.Origin)
supervisor.Present(engine) supervisor.Present(engine)
} }