Skip to content

Commit

Permalink
allow draging & r-clicking in more places
Browse files Browse the repository at this point in the history
Makes things feel more responsive.
  • Loading branch information
nhanb committed Sep 17, 2023
1 parent 0598a03 commit 32f35a3
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions states.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,16 @@ type StateRClick struct{}
func (s *StateRClick) Enter(sm *StateMachine) {
sm.SetAnim(RightClick)
}
func (s *StateRClick) Update(sm *StateMachine) {}
func (s *StateRClick) Update(sm *StateMachine) {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
sm.SetState(&StateDrag{})
return
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
sm.SetState(&StateRClick{})
return
}
}
func (s *StateRClick) EndAnimHook(sm *StateMachine) {
sm.SetState(&StateIdle{})
}
Expand All @@ -161,8 +170,17 @@ func (s *StateFeed) EndAnimHook(sm *StateMachine) {

type StateWalkL struct{}

func (s *StateWalkL) Enter(sm *StateMachine) { sm.SetAnim(WalkLeft) }
func (s *StateWalkL) Update(sm *StateMachine) {}
func (s *StateWalkL) Enter(sm *StateMachine) { sm.SetAnim(WalkLeft) }
func (s *StateWalkL) Update(sm *StateMachine) {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
sm.SetState(&StateDrag{})
return
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
sm.SetState(&StateRClick{})
return
}
}
func (s *StateWalkL) EndAnimHook(sm *StateMachine) {
if randBool(StopChance) {
sm.SetState(&StateIdle{})
Expand All @@ -171,8 +189,17 @@ func (s *StateWalkL) EndAnimHook(sm *StateMachine) {

type StateWalkR struct{}

func (s *StateWalkR) Enter(sm *StateMachine) { sm.SetAnim(WalkRight) }
func (s *StateWalkR) Update(sm *StateMachine) {}
func (s *StateWalkR) Enter(sm *StateMachine) { sm.SetAnim(WalkRight) }
func (s *StateWalkR) Update(sm *StateMachine) {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
sm.SetState(&StateDrag{})
return
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
sm.SetState(&StateRClick{})
return
}
}
func (s *StateWalkR) EndAnimHook(sm *StateMachine) {
if randBool(StopChance) {
sm.SetState(&StateIdle{})
Expand Down

0 comments on commit 32f35a3

Please sign in to comment.