Cleaned up controller deadzone logic, fixed bug related to uninitiated motion.
This commit is contained in:
@@ -156,6 +156,8 @@ type SplashPad struct {
|
|||||||
heroImpulse impulse
|
heroImpulse impulse
|
||||||
jumping bool
|
jumping bool
|
||||||
jumptimer int
|
jumptimer int
|
||||||
|
|
||||||
|
controller bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSplashPad() SplashPad {
|
func NewSplashPad() SplashPad {
|
||||||
@@ -184,6 +186,7 @@ func NewSplashPad() SplashPad {
|
|||||||
hero: h,
|
hero: h,
|
||||||
jumping: false,
|
jumping: false,
|
||||||
jumptimer: 0,
|
jumptimer: 0,
|
||||||
|
controller: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
gravity := &force{}
|
gravity := &force{}
|
||||||
@@ -240,6 +243,13 @@ func (s *SplashPad) Update() error {
|
|||||||
s.hero.jumptime = 0
|
s.hero.jumptime = 0
|
||||||
s.hero.jumping = false
|
s.hero.jumping = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check for user input to transition scene
|
||||||
|
if inpututil.IsKeyJustPressed(ebiten.KeyQ) {
|
||||||
|
if s.events[groovy.COMPLETED] != nil {
|
||||||
|
s.events[groovy.COMPLETED]()
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,15 +478,19 @@ func (s *SplashPad) handleLeftMovement() {
|
|||||||
s.hero.runningLeft = true
|
s.hero.runningLeft = true
|
||||||
log.Println(" left gamepad engaged")
|
log.Println(" left gamepad engaged")
|
||||||
s.hero.facingLeft = true
|
s.hero.facingLeft = true
|
||||||
|
s.controller = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if -SENSITIVITY < ebiten.GamepadAxisValue(0, 0) && ebiten.GamepadAxisValue(0, 0) < SENSITIVITY {
|
if s.controller {
|
||||||
s.hero.runningLeft = false
|
if -SENSITIVITY < ebiten.GamepadAxisValue(0, 0) && ebiten.GamepadAxisValue(0, 0) < SENSITIVITY {
|
||||||
if s.hero.runningStopFrame > 0 {
|
s.hero.runningLeft = false
|
||||||
s.hero.runningStopFrame = s.increment
|
if s.hero.runningStopFrame > 0 {
|
||||||
log.Println(" left gamepad released")
|
s.hero.runningStopFrame = s.increment
|
||||||
}
|
log.Println(" left gamepad released")
|
||||||
|
s.controller = false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if running, need to update their position
|
//if running, need to update their position
|
||||||
@@ -501,7 +515,7 @@ func (s *SplashPad) handleLeftMovement() {
|
|||||||
deltaT := float32(s.increment - s.hero.runningStopFrame)
|
deltaT := float32(s.increment - s.hero.runningStopFrame)
|
||||||
|
|
||||||
offset = TOP_SPEED - int(scaler*deltaT)
|
offset = TOP_SPEED - int(scaler*deltaT)
|
||||||
offset = max(0, offset) //should not be less than zero, otherwise player would move wrong way ??
|
offset = int(math.Max(0, float64(offset))) //should not be less than zero, otherwise player would move wrong way ??
|
||||||
log.Printf(" stopping (%d,%d)...", s.hero.posX, s.hero.posY)
|
log.Printf(" stopping (%d,%d)...", s.hero.posX, s.hero.posY)
|
||||||
} else {
|
} else {
|
||||||
s.hero.runningStopFrame = 0
|
s.hero.runningStopFrame = 0
|
||||||
@@ -538,15 +552,18 @@ func (s *SplashPad) handleRightMovement() {
|
|||||||
s.hero.runningRight = true
|
s.hero.runningRight = true
|
||||||
log.Println(" right gamepad engaged")
|
log.Println(" right gamepad engaged")
|
||||||
s.hero.facingLeft = false
|
s.hero.facingLeft = false
|
||||||
|
s.controller = true
|
||||||
}
|
}
|
||||||
|
if s.controller {
|
||||||
|
if -SENSITIVITY < ebiten.GamepadAxisValue(0, 0) && ebiten.GamepadAxisValue(0, 0) < SENSITIVITY {
|
||||||
|
s.hero.runningRight = false
|
||||||
|
if s.hero.runningStopFrame > 0 {
|
||||||
|
s.hero.runningStopFrame = s.increment
|
||||||
|
log.Println(" right gamepad released")
|
||||||
|
s.controller = false
|
||||||
|
}
|
||||||
|
|
||||||
if -SENSITIVITY < ebiten.GamepadAxisValue(0, 0) && ebiten.GamepadAxisValue(0, 0) < SENSITIVITY {
|
|
||||||
s.hero.runningRight = false
|
|
||||||
if s.hero.runningStopFrame > 0 {
|
|
||||||
s.hero.runningStopFrame = s.increment
|
|
||||||
log.Println(" right gamepad released")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if running, need to update their position
|
//if running, need to update their position
|
||||||
|
|||||||
Reference in New Issue
Block a user