Direction
This commit is contained in:
38
hero/hero.go
38
hero/hero.go
@@ -3,13 +3,14 @@ package hero
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"gitlab.com/kbr4/9heroja/configuration"
|
||||
"gitlab.com/kbr4/9heroja/resources"
|
||||
"image"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
const WalkSpeedMs = 400
|
||||
const WalkSpeedMs = 300
|
||||
|
||||
var (
|
||||
heroImage *ebiten.Image
|
||||
@@ -17,7 +18,8 @@ var (
|
||||
)
|
||||
|
||||
type Hero struct {
|
||||
step int
|
||||
step int
|
||||
direction configuration.Direction
|
||||
}
|
||||
|
||||
type spritePosition struct {
|
||||
@@ -27,7 +29,10 @@ type spritePosition struct {
|
||||
|
||||
func (h *Hero) DrawHero(screen *ebiten.Image) {
|
||||
|
||||
positions := []spritePosition{
|
||||
// set movement positions to be hashmap of sprite positions for each direction
|
||||
|
||||
movementPositions := map[configuration.Direction][]spritePosition{}
|
||||
movementPositions[configuration.North] = []spritePosition{
|
||||
{0, 166},
|
||||
{33, 166},
|
||||
{66, 166},
|
||||
@@ -37,7 +42,28 @@ func (h *Hero) DrawHero(screen *ebiten.Image) {
|
||||
{66, 166},
|
||||
{33, 166},
|
||||
}
|
||||
p := positions[h.step%5]
|
||||
movementPositions[configuration.NorthEast] = []spritePosition{
|
||||
{168, 0},
|
||||
{201, 0},
|
||||
{0, 33},
|
||||
{33, 33},
|
||||
{66, 33},
|
||||
{33, 33},
|
||||
{0, 33},
|
||||
{201, 0},
|
||||
}
|
||||
|
||||
movementPositions[configuration.South] = []spritePosition{
|
||||
{66, 132},
|
||||
{0, 99},
|
||||
{33, 99},
|
||||
{66, 99},
|
||||
{99, 99},
|
||||
{66, 99},
|
||||
{33, 99},
|
||||
{0, 99},
|
||||
}
|
||||
p := movementPositions[h.direction][h.step%8]
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
screenWidth := screen.Bounds().Max.X
|
||||
@@ -88,6 +114,10 @@ func (h *Hero) Walk() {
|
||||
|
||||
}
|
||||
|
||||
func (h *Hero) ChangeDirection(d configuration.Direction) {
|
||||
h.direction = d
|
||||
}
|
||||
|
||||
func (h *Hero) Stop() {
|
||||
h.step = 2
|
||||
walkTicker.Stop()
|
||||
|
||||
Reference in New Issue
Block a user