they walked so they could run when I tweaked the sprite sheet

This commit is contained in:
Josh Deprez 2021-08-05 10:26:45 +10:00 committed by Josh Deprez
parent 4c8e8bf4a7
commit d8202c65f5
6 changed files with 39 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

BIN
asset_src/aw.aseprite Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 388 B

After

Width:  |  Height:  |  Size: 625 B

View file

@ -1,6 +1,7 @@
package engine
import (
"image/color"
"unsafe"
"github.com/hajimehoshi/ebiten/v2"
@ -30,3 +31,12 @@ func ToGeoMDef(m *ebiten.GeoM) *GeoMDef {
func (d *GeoMDef) GeoM() *ebiten.GeoM {
return (*ebiten.GeoM)(unsafe.Pointer(d))
}
// Fill fills the image with a colour.
type Fill struct {
Color color.Color
}
func (f Fill) Draw(screen *ebiten.Image, _ ebiten.GeoM) {
screen.Fill(color.Color(f.Color))
}

View file

@ -20,7 +20,7 @@ type Sprite struct {
ZPos
vx, vy float64 // TODO: refactor
animIdle, animWalkLeft, animWalkRight *Anim
animIdle, animRunLeft, animRunRight *Anim
}
func (s *Sprite) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
@ -59,10 +59,10 @@ func (s *Sprite) Update() error {
switch {
case ebiten.IsKeyPressed(ebiten.KeyLeft):
s.vx = -2
s.Anim = s.animWalkLeft
s.Anim = s.animRunLeft
case ebiten.IsKeyPressed(ebiten.KeyRight):
s.vx = 2
s.Anim = s.animWalkRight
s.Anim = s.animRunRight
default:
s.vx = 0
s.Anim = s.animIdle
@ -74,7 +74,7 @@ func (s *Sprite) Update() error {
func (s *Sprite) Build(g *Game) {
// TODO: better than this
s.animWalkLeft = &Anim{Def: AnimDefs["aw_walk_left"]}
s.animWalkRight = &Anim{Def: AnimDefs["aw_walk_right"]}
s.animRunLeft = &Anim{Def: AnimDefs["aw_run_left"]}
s.animRunRight = &Anim{Def: AnimDefs["aw_run_right"]}
s.animIdle = &Anim{Def: AnimDefs["aw_idle"]}
}

22
main.go
View file

@ -3,6 +3,7 @@ package main
import (
"embed"
"image"
"image/color"
_ "image/png"
"log"
@ -57,6 +58,22 @@ func main() {
{Frame: 8, Duration: 6},
},
},
"aw_run_right": {
Frames: []engine.AnimFrame{
{Frame: 9, Duration: 3},
{Frame: 10, Duration: 3},
{Frame: 11, Duration: 3},
{Frame: 12, Duration: 3},
},
},
"aw_run_left": {
Frames: []engine.AnimFrame{
{Frame: 13, Duration: 3},
{Frame: 14, Duration: 3},
{Frame: 15, Duration: 3},
{Frame: 16, Duration: 3},
},
},
}
tiles := [][]engine.Tile{
@ -80,6 +97,9 @@ func main() {
level1 := &engine.Scene{
ID: "level_1",
Components: []interface{}{
engine.Fill{
Color: color.White,
},
&engine.Tilemap{
ID: "terrain",
Map: tiles,
@ -107,7 +127,7 @@ func main() {
ID: "protagonist",
Actor: engine.Actor{
Position: image.Pt(100, 100),
Size: image.Pt(8, 16),
Size: image.Pt(10, 16),
},
Src: engine.ImageRef{Path: "assets/aw.png"},
ZPos: 1,