Player walk animation

This commit is contained in:
2021-01-02 20:40:58 -07:00
parent b252ba12ee
commit 7a55495eb8
3 changed files with 32 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -5,7 +5,8 @@ import flixel.FlxSprite;
import flixel.util.FlxColor; import flixel.util.FlxColor;
import flixel.input.keyboard.FlxKey; import flixel.input.keyboard.FlxKey;
import flixel.math.FlxPoint; import flixel.math.FlxPoint;
import flixel.FlxObject;
import kiss.Prelude; import kiss.Prelude;
@:build(kiss.Kiss.build("source/Player.kiss")) @:build(kiss.Kiss.build("source/Player.kiss"))
class Player extends FlxSprite {} class Player extends FlxSprite {}

View File

@@ -2,7 +2,12 @@
(defmethod new [:Float x :Float y] (defmethod new [:Float x :Float y]
(super x y) (super x y)
(makeGraphic 16 16 FlxColor.BLUE) (loadGraphic AssetPaths.player__png true 16 16)
(setFacingFlip FlxObject.LEFT false false)
(setFacingFlip FlxObject.RIGHT true false)
(animation.add "lr" [3 4 3 5] 6 false)
(animation.add "u" [6 7 6 8] 6 false)
(animation.add "d" [0 1 0 2] 6 false)
(set drag.x (set drag.y 1600)) (set drag.x (set drag.y 1600))
(return)) (return))
@@ -22,20 +27,39 @@
(left (left
(set newAngle (- newAngle 45))) (set newAngle (- newAngle 45)))
(right (right
(set newAngle (+ newAngle 45))))) (set newAngle (+ newAngle 45))))
(set facing FlxObject.UP))
(down (down
(set newAngle 90) (set newAngle 90)
(cond (cond
(left (left
(set newAngle (+ newAngle 45))) (set newAngle (+ newAngle 45)))
(right (right
(set newAngle (- newAngle 45))))) (set newAngle (- newAngle 45))))
(set facing FlxObject.DOWN))
(left (left
(set newAngle 180)) (set newAngle 180)
(set facing FlxObject.LEFT))
(right (right
(set newAngle 0))) (set newAngle 0)
(set facing FlxObject.RIGHT)))
(velocity.set SPEED 0) (velocity.set SPEED 0)
(velocity.rotate (FlxPoint.weak 0 0) newAngle)))) (velocity.rotate (FlxPoint.weak 0 0) newAngle)))
// TODO != is not implemented. Not sure how it would work as a variadic, because other
// Lisps don't have that either
(when !(and (= 0 velocity.x) (= 0 velocity.y))
(case facing
// TODO allow | in case?
(FlxObject.LEFT
(animation.play "lr"))
(FlxObject.RIGHT
(animation.play "lr"))
(FlxObject.UP
(animation.play "u"))
(FlxObject.DOWN
(animation.play "d"))
(otherwise
(return)))))
(defmethod &override update [:Float elapsed] (defmethod &override update [:Float elapsed]
(updateMovement) (updateMovement)