Keyboard input for moving
This commit is contained in:
14
hero/hero.go
14
hero/hero.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user