Keyboard input for moving

This commit is contained in:
2023-11-28 07:29:17 +01:00
parent 46f331aa00
commit 9ea4c3beb2
5 changed files with 84 additions and 23 deletions

View File

@@ -20,6 +20,7 @@ var (
type Hero struct {
step int
direction configuration.Direction
IsWalking bool
}
type spritePosition struct {
@@ -146,7 +147,8 @@ func init() {
func NewHero() *Hero {
hero := &Hero{
step: 0,
step: 0,
IsWalking: false,
}
go func() {
@@ -165,15 +167,21 @@ func NewHero() *Hero {
func (h *Hero) Walk() {
walkTicker.Reset(WalkSpeedMs * time.Millisecond)
if !h.IsWalking {
walkTicker.Reset(WalkSpeedMs * time.Millisecond)
h.IsWalking = true
}
}
func (h *Hero) ChangeDirection(d configuration.Direction) {
h.direction = d
if d != configuration.PreviouslyHeld {
h.direction = d
}
}
func (h *Hero) Stop() {
h.step = 2
walkTicker.Stop()
h.IsWalking = false
}