Cleaned up controller deadzone logic, fixed bug related to uninitiated motion.

This commit is contained in:
dbenavid
2023-09-05 07:52:00 -04:00
parent f4299e15a5
commit c5f5c01ab0

View File

@@ -156,6 +156,8 @@ type SplashPad struct {
heroImpulse impulse
jumping bool
jumptimer int
controller bool
}
func NewSplashPad() SplashPad {
@@ -184,6 +186,7 @@ func NewSplashPad() SplashPad {
hero: h,
jumping: false,
jumptimer: 0,
controller: false,
}
gravity := &force{}
@@ -240,6 +243,13 @@ func (s *SplashPad) Update() error {
s.hero.jumptime = 0
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
}
@@ -468,15 +478,19 @@ func (s *SplashPad) handleLeftMovement() {
s.hero.runningLeft = true
log.Println(" left gamepad engaged")
s.hero.facingLeft = true
s.controller = true
}
if -SENSITIVITY < ebiten.GamepadAxisValue(0, 0) && ebiten.GamepadAxisValue(0, 0) < SENSITIVITY {
s.hero.runningLeft = false
if s.hero.runningStopFrame > 0 {
s.hero.runningStopFrame = s.increment
log.Println(" left gamepad released")
}
if s.controller {
if -SENSITIVITY < ebiten.GamepadAxisValue(0, 0) && ebiten.GamepadAxisValue(0, 0) < SENSITIVITY {
s.hero.runningLeft = false
if s.hero.runningStopFrame > 0 {
s.hero.runningStopFrame = s.increment
log.Println(" left gamepad released")
s.controller = false
}
}
}
//if running, need to update their position
@@ -501,7 +515,7 @@ func (s *SplashPad) handleLeftMovement() {
deltaT := float32(s.increment - s.hero.runningStopFrame)
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)
} else {
s.hero.runningStopFrame = 0
@@ -538,15 +552,18 @@ func (s *SplashPad) handleRightMovement() {
s.hero.runningRight = true
log.Println(" right gamepad engaged")
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