diff --git a/asset_src/aw.aseprite b/asset_src/aw.aseprite index d0c81dd..1eb950d 100644 Binary files a/asset_src/aw.aseprite and b/asset_src/aw.aseprite differ diff --git a/assets/aw.png b/assets/aw.png index 85733f1..ec0f544 100644 Binary files a/assets/aw.png and b/assets/aw.png differ diff --git a/engine/sprite.go b/engine/sprite.go index 96d9669..e427b0a 100644 --- a/engine/sprite.go +++ b/engine/sprite.go @@ -13,14 +13,16 @@ const gravity = 0.2 // Sprite combines an Actor with the ability to Draw... type Sprite struct { Actor - *Anim // TODO: better + *Anim // TODO: better Hidden bool ID Src ImageRef ZPos - vx, vy float64 // TODO: refactor - animIdle, animRunLeft, animRunRight *Anim + vx, vy float64 // TODO: refactor + facingLeft bool + + animIdleLeft, animIdleRight, animRunLeft, animRunRight *Anim } func (s *Sprite) Draw(screen *ebiten.Image, geom ebiten.GeoM) { @@ -34,12 +36,12 @@ func (s *Sprite) Draw(screen *ebiten.Image, geom ebiten.GeoM) { frame := s.Anim.CurrentFrame() src := s.Src.Image() w, _ := src.Size() - sx, sy := (frame * s.Actor.Size.X) % w, ((frame * s.Actor.Size.X) / w) * s.Actor.Size.Y + sx, sy := (frame*s.Actor.Size.X)%w, ((frame*s.Actor.Size.X)/w)*s.Actor.Size.Y - screen.DrawImage(src.SubImage(image.Rect(sx, sy, sx + s.Actor.Size.X, sy+s.Actor.Size.Y)).(*ebiten.Image), &op) + screen.DrawImage(src.SubImage(image.Rect(sx, sy, sx+s.Actor.Size.X, sy+s.Actor.Size.Y)).(*ebiten.Image), &op) } -func (s *Sprite) Scan() []interface{}{ +func (s *Sprite) Scan() []interface{} { return []interface{}{&s.Actor} } @@ -60,12 +62,17 @@ func (s *Sprite) Update() error { case ebiten.IsKeyPressed(ebiten.KeyLeft): s.vx = -2 s.Anim = s.animRunLeft + s.facingLeft = true case ebiten.IsKeyPressed(ebiten.KeyRight): s.vx = 2 s.Anim = s.animRunRight + s.facingLeft = false default: s.vx = 0 - s.Anim = s.animIdle + s.Anim = s.animIdleRight + if s.facingLeft { + s.Anim = s.animIdleLeft + } } s.Actor.MoveX(s.vx, func() { s.vx = -s.vx * dampen }) s.Actor.MoveY(s.vy, func() { s.vy = -s.vy * dampen }) @@ -76,5 +83,6 @@ func (s *Sprite) Build(g *Game) { // TODO: better than this s.animRunLeft = &Anim{Def: AnimDefs["aw_run_left"]} s.animRunRight = &Anim{Def: AnimDefs["aw_run_right"]} - s.animIdle = &Anim{Def: AnimDefs["aw_idle"]} -} \ No newline at end of file + s.animIdleLeft = &Anim{Def: AnimDefs["aw_idle_left"]} + s.animIdleRight = &Anim{Def: AnimDefs["aw_idle_right"]} +} diff --git a/main.go b/main.go index 2e49791..df0a324 100644 --- a/main.go +++ b/main.go @@ -37,41 +37,46 @@ func main() { {Frame: 6, Duration: 12}, }, }, - "aw_idle": { + "aw_idle_right": { Frames: []engine.AnimFrame{ {Frame: 0, Duration: 60}, }, }, + "aw_idle_left": { + Frames: []engine.AnimFrame{ + {Frame: 1, Duration: 60}, + }, + }, "aw_walk_right": { Frames: []engine.AnimFrame{ - {Frame: 1, Duration: 6}, {Frame: 2, Duration: 6}, {Frame: 3, Duration: 6}, {Frame: 4, Duration: 6}, + {Frame: 5, Duration: 6}, }, }, "aw_walk_left": { Frames: []engine.AnimFrame{ - {Frame: 5, Duration: 6}, {Frame: 6, Duration: 6}, {Frame: 7, Duration: 6}, {Frame: 8, Duration: 6}, + {Frame: 9, Duration: 3}, }, }, "aw_run_right": { Frames: []engine.AnimFrame{ - {Frame: 9, Duration: 3}, {Frame: 10, Duration: 3}, {Frame: 11, Duration: 3}, {Frame: 12, Duration: 3}, + {Frame: 13, Duration: 3}, }, }, "aw_run_left": { Frames: []engine.AnimFrame{ - {Frame: 13, Duration: 3}, {Frame: 14, Duration: 3}, {Frame: 15, Duration: 3}, {Frame: 16, Duration: 3}, + {Frame: 17, Duration: 3}, }, }, }