More cleanup, added pause.

This commit is contained in:
2024-11-05 07:11:21 -05:00
parent 7608847727
commit f8f491a764

39
game.go
View File

@@ -21,12 +21,14 @@ type Game struct {
projectileMask *ebiten.Image
Pos Coordinates
Paused bool
initialized bool
mover *Mover
projectiles map[int]*Projectile
explosion *Explosion
counter int
timer int
targets []*Mover
gamepadIDsBuf []ebiten.GamepadID
@@ -69,17 +71,6 @@ func (g *Game) Update() error {
}
}
//handle gamepad input
inpx := ebiten.GamepadAxisValue(0, 0)
inpy := ebiten.GamepadAxisValue(0, 1)
if inpx >= 0.15 || inpx <= -0.15 {
g.mover.Pos.X += ebiten.GamepadAxisValue(0, 0) * 5
}
if inpy >= 0.15 || inpy <= -0.15 {
g.mover.Pos.Y += ebiten.GamepadAxisValue(0, 1) * 5
}
if !g.initialized {
g.Initialize()
@@ -89,7 +80,7 @@ func (g *Game) Update() error {
g.StepGame()
}
g.CleanupTargets()
g.timer++
return nil
}
@@ -165,6 +156,10 @@ func (g *Game) StepGame() {
g.HandleInput()
if !g.Paused {
g.UpdateHeroPosition()
g.mover.Update()
g.explosion.Update()
@@ -180,7 +175,9 @@ func (g *Game) StepGame() {
//handle pulsewave updates
g.HandlePulseWaveUpdate()
g.CleanupTargets()
g.counter++
}
}
func (g *Game) AddNewTargets() {
@@ -294,8 +291,6 @@ func (g *Game) AppendProjectiles() {
func (g *Game) HandleInput() {
if len(g.gamepadIDs) > 0 {
maxButton := ebiten.GamepadButton(ebiten.GamepadButtonCount(0))
for b := ebiten.GamepadButton(0); b < maxButton; b++ {
if ebiten.IsGamepadButtonPressed(0, ebiten.GamepadButton11) {
if !g.explosion.Active {
g.explosion.SetOrigin(g.mover.Pos)
@@ -303,6 +298,9 @@ func (g *Game) HandleInput() {
g.explosion.ToggleActivate()
}
}
if inpututil.IsGamepadButtonJustPressed(0, ebiten.GamepadButton9) {
g.Paused = !g.Paused
}
//account for controller sensitivity
@@ -320,3 +318,16 @@ func (g *Game) HandleInput() {
g.mover.SetAngle(inputangle)
}
}
func (g *Game) UpdateHeroPosition() {
//handle gamepad input
inpx := ebiten.GamepadAxisValue(0, 0)
inpy := ebiten.GamepadAxisValue(0, 1)
if inpx >= 0.15 || inpx <= -0.15 {
g.mover.Pos.X += ebiten.GamepadAxisValue(0, 0) * 5
}
if inpy >= 0.15 || inpy <= -0.15 {
g.mover.Pos.Y += ebiten.GamepadAxisValue(0, 1) * 5
}
}