From 196b220c4fee417d6a729bd691b75f97cfa1211c Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Thu, 5 Aug 2021 10:50:13 +1000 Subject: [PATCH] idle in a direction --- asset_src/aw.aseprite | Bin 2420 -> 2522 bytes assets/aw.png | Bin 625 -> 628 bytes engine/sprite.go | 26 +++++++++++++++++--------- main.go | 15 ++++++++++----- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/asset_src/aw.aseprite b/asset_src/aw.aseprite index d0c81dd7a9d341b4d867921ee2eac8264c2cb7f2..1eb950d33ad07a44f183123c7ed4799f67a1c9e2 100644 GIT binary patch delta 161 zcmew&bW5217AFJ4gQY?f*((`+H#W{-jAvqCWq^Z!(UCxIQF&rcHX8#_B@BG{@Bt{E z0}|(A;Dw1YFo4vvFccM)=J7EIB7{N8Sr~GF!eNs)a#&04lKkObRT8)m7=yEsfXZ)Mug1^_zbEKmRd delta 121 zcmca5{6&bpgp+~c!BWAA?3Ii`8yjaZ#xXLmFu=jT=tu@uhNAMsoNQJG4!AJGhYufs m;yEC3P6i%?I7mGULs3y_9xsCcLKvi+g&_why!kHEUp4??a~nPx%E=fc|RA_l181B}$^)bBCa@fmd z?ezx2+FKpRO5e=K{cHJ~Ez}hn4;2n?KcPO?cXE;Xj=}JVSfI+^l=M zC<=_R#{zBkYMbT0t#L+!SNOO#tE~kahgbO7yQs0n@ibolL)YJ13s0Q?;syyy?OAcH zk!pD11rB+=aYPz%Jt-LaQiD9F8((7@yRMDf%b#b@K5KR8R!&qKc3-vWb#ogpo4>3M zB8{IOIjS&WcpbimjuJh*nGR}fhZkzx+*y}foxdL7G{BAL#q&h|JUmj+rn?9P9PY{$ z-@y9Kx;?Jr2g!Px%D@jB_RA_S&67ydr2wI(8>LJDt(usjyky05=y`@5ibgH~|qRgQw;R_MO| zp6~BwV1+Ydkd2onL2^e5Q{|EQu%rHV*Kf4}D?ENINhfV|-#`wFgFHHVcbpmBET$eg z8D_LSU5(Q@%_9A;)X#fY{RV4atKZeA8cf#?=W=X06^+Ffkkz#@y*xayKLTvdRu^-y zdBEDO)){6Ru(yfOkLJPDu)2QM` zh8O<$ATI;!5!XA7K>rLN&zYXrafwsX=Izzbi)Wu@6E&-edc$d{F}>+)^JVMT>x0PS zmZRUAVUPYqYwAcJ;jK(O6FdA7#ZB9rO4aon0Zwn+P+mSe>gQpoQOz_ENF>}v6}7dx zz3GhWSm@qIu4)9-wlT3WVH$-swDqfO*6fO)z9Qe}^Kx(YBtiTEDV?bK`uOI900000 LNkvXXu0mjf>zy?7 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}, }, }, }