they walked so they could run when I tweaked the sprite sheet
This commit is contained in:
parent
4c8e8bf4a7
commit
d8202c65f5
6 changed files with 39 additions and 9 deletions
BIN
asset_src/Screen Shot 2021-08-04 at 3.32.28 pm.png
Normal file
BIN
asset_src/Screen Shot 2021-08-04 at 3.32.28 pm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
BIN
asset_src/aw.aseprite
Normal file
BIN
asset_src/aw.aseprite
Normal file
Binary file not shown.
BIN
assets/aw.png
BIN
assets/aw.png
Binary file not shown.
Before Width: | Height: | Size: 388 B After Width: | Height: | Size: 625 B |
|
@ -1,6 +1,7 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
@ -30,3 +31,12 @@ func ToGeoMDef(m *ebiten.GeoM) *GeoMDef {
|
||||||
func (d *GeoMDef) GeoM() *ebiten.GeoM {
|
func (d *GeoMDef) GeoM() *ebiten.GeoM {
|
||||||
return (*ebiten.GeoM)(unsafe.Pointer(d))
|
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))
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ type Sprite struct {
|
||||||
ZPos
|
ZPos
|
||||||
|
|
||||||
vx, vy float64 // TODO: refactor
|
vx, vy float64 // TODO: refactor
|
||||||
animIdle, animWalkLeft, animWalkRight *Anim
|
animIdle, animRunLeft, animRunRight *Anim
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sprite) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
|
func (s *Sprite) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
|
||||||
|
@ -59,10 +59,10 @@ func (s *Sprite) Update() error {
|
||||||
switch {
|
switch {
|
||||||
case ebiten.IsKeyPressed(ebiten.KeyLeft):
|
case ebiten.IsKeyPressed(ebiten.KeyLeft):
|
||||||
s.vx = -2
|
s.vx = -2
|
||||||
s.Anim = s.animWalkLeft
|
s.Anim = s.animRunLeft
|
||||||
case ebiten.IsKeyPressed(ebiten.KeyRight):
|
case ebiten.IsKeyPressed(ebiten.KeyRight):
|
||||||
s.vx = 2
|
s.vx = 2
|
||||||
s.Anim = s.animWalkRight
|
s.Anim = s.animRunRight
|
||||||
default:
|
default:
|
||||||
s.vx = 0
|
s.vx = 0
|
||||||
s.Anim = s.animIdle
|
s.Anim = s.animIdle
|
||||||
|
@ -74,7 +74,7 @@ func (s *Sprite) Update() error {
|
||||||
|
|
||||||
func (s *Sprite) Build(g *Game) {
|
func (s *Sprite) Build(g *Game) {
|
||||||
// TODO: better than this
|
// TODO: better than this
|
||||||
s.animWalkLeft = &Anim{Def: AnimDefs["aw_walk_left"]}
|
s.animRunLeft = &Anim{Def: AnimDefs["aw_run_left"]}
|
||||||
s.animWalkRight = &Anim{Def: AnimDefs["aw_walk_right"]}
|
s.animRunRight = &Anim{Def: AnimDefs["aw_run_right"]}
|
||||||
s.animIdle = &Anim{Def: AnimDefs["aw_idle"]}
|
s.animIdle = &Anim{Def: AnimDefs["aw_idle"]}
|
||||||
}
|
}
|
28
main.go
28
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"image"
|
"image"
|
||||||
|
"image/color"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
@ -57,6 +58,22 @@ func main() {
|
||||||
{Frame: 8, Duration: 6},
|
{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{
|
tiles := [][]engine.Tile{
|
||||||
|
@ -80,6 +97,9 @@ func main() {
|
||||||
level1 := &engine.Scene{
|
level1 := &engine.Scene{
|
||||||
ID: "level_1",
|
ID: "level_1",
|
||||||
Components: []interface{}{
|
Components: []interface{}{
|
||||||
|
engine.Fill{
|
||||||
|
Color: color.White,
|
||||||
|
},
|
||||||
&engine.Tilemap{
|
&engine.Tilemap{
|
||||||
ID: "terrain",
|
ID: "terrain",
|
||||||
Map: tiles,
|
Map: tiles,
|
||||||
|
@ -104,13 +124,13 @@ func main() {
|
||||||
Rect: image.Rect(0, 192, 320, 240),
|
Rect: image.Rect(0, 192, 320, 240),
|
||||||
},*/
|
},*/
|
||||||
&engine.Sprite{
|
&engine.Sprite{
|
||||||
ID: "protagonist",
|
ID: "protagonist",
|
||||||
Actor: engine.Actor{
|
Actor: engine.Actor{
|
||||||
Position: image.Pt(100, 100),
|
Position: image.Pt(100, 100),
|
||||||
Size: image.Pt(8, 16),
|
Size: image.Pt(10, 16),
|
||||||
},
|
},
|
||||||
Src: engine.ImageRef{Path: "assets/aw.png"},
|
Src: engine.ImageRef{Path: "assets/aw.png"},
|
||||||
ZPos: 1,
|
ZPos: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue