More cleanup, added pause.
This commit is contained in:
73
game.go
73
game.go
@@ -21,12 +21,14 @@ type Game struct {
|
|||||||
projectileMask *ebiten.Image
|
projectileMask *ebiten.Image
|
||||||
|
|
||||||
Pos Coordinates
|
Pos Coordinates
|
||||||
|
Paused bool
|
||||||
initialized bool
|
initialized bool
|
||||||
mover *Mover
|
mover *Mover
|
||||||
projectiles map[int]*Projectile
|
projectiles map[int]*Projectile
|
||||||
explosion *Explosion
|
explosion *Explosion
|
||||||
|
|
||||||
counter int
|
counter int
|
||||||
|
timer int
|
||||||
targets []*Mover
|
targets []*Mover
|
||||||
|
|
||||||
gamepadIDsBuf []ebiten.GamepadID
|
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 {
|
if !g.initialized {
|
||||||
g.Initialize()
|
g.Initialize()
|
||||||
|
|
||||||
@@ -89,7 +80,7 @@ func (g *Game) Update() error {
|
|||||||
g.StepGame()
|
g.StepGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
g.CleanupTargets()
|
g.timer++
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -165,22 +156,28 @@ func (g *Game) StepGame() {
|
|||||||
|
|
||||||
g.HandleInput()
|
g.HandleInput()
|
||||||
|
|
||||||
g.mover.Update()
|
if !g.Paused {
|
||||||
g.explosion.Update()
|
|
||||||
|
|
||||||
g.UpdateTargets()
|
g.UpdateHeroPosition()
|
||||||
g.UpdateProjectiles()
|
|
||||||
|
|
||||||
//append new projectiles
|
g.mover.Update()
|
||||||
g.AppendProjectiles()
|
g.explosion.Update()
|
||||||
|
|
||||||
//add new target with increasing frequency
|
g.UpdateTargets()
|
||||||
g.AddNewTargets()
|
g.UpdateProjectiles()
|
||||||
|
|
||||||
//handle pulsewave updates
|
//append new projectiles
|
||||||
g.HandlePulseWaveUpdate()
|
g.AppendProjectiles()
|
||||||
|
|
||||||
g.counter++
|
//add new target with increasing frequency
|
||||||
|
g.AddNewTargets()
|
||||||
|
|
||||||
|
//handle pulsewave updates
|
||||||
|
g.HandlePulseWaveUpdate()
|
||||||
|
|
||||||
|
g.CleanupTargets()
|
||||||
|
g.counter++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) AddNewTargets() {
|
func (g *Game) AddNewTargets() {
|
||||||
@@ -294,17 +291,18 @@ func (g *Game) AppendProjectiles() {
|
|||||||
|
|
||||||
func (g *Game) HandleInput() {
|
func (g *Game) HandleInput() {
|
||||||
if len(g.gamepadIDs) > 0 {
|
if len(g.gamepadIDs) > 0 {
|
||||||
maxButton := ebiten.GamepadButton(ebiten.GamepadButtonCount(0))
|
if ebiten.IsGamepadButtonPressed(0, ebiten.GamepadButton11) {
|
||||||
for b := ebiten.GamepadButton(0); b < maxButton; b++ {
|
if !g.explosion.Active {
|
||||||
if ebiten.IsGamepadButtonPressed(0, ebiten.GamepadButton11) {
|
g.explosion.SetOrigin(g.mover.Pos)
|
||||||
if !g.explosion.Active {
|
g.explosion.Reset()
|
||||||
g.explosion.SetOrigin(g.mover.Pos)
|
g.explosion.ToggleActivate()
|
||||||
g.explosion.Reset()
|
|
||||||
g.explosion.ToggleActivate()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if inpututil.IsGamepadButtonJustPressed(0, ebiten.GamepadButton9) {
|
||||||
|
g.Paused = !g.Paused
|
||||||
|
}
|
||||||
|
|
||||||
//account for controller sensitivity
|
//account for controller sensitivity
|
||||||
xaxis := ebiten.StandardGamepadAxisValue(0, ebiten.StandardGamepadAxisRightStickHorizontal)
|
xaxis := ebiten.StandardGamepadAxisValue(0, ebiten.StandardGamepadAxisRightStickHorizontal)
|
||||||
yaxis := ebiten.StandardGamepadAxisValue(0, ebiten.StandardGamepadAxisRightStickVertical)
|
yaxis := ebiten.StandardGamepadAxisValue(0, ebiten.StandardGamepadAxisRightStickVertical)
|
||||||
@@ -320,3 +318,16 @@ func (g *Game) HandleInput() {
|
|||||||
g.mover.SetAngle(inputangle)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user