Splash screen update, gamepad cleanup on main game.

This commit is contained in:
2024-11-11 10:48:44 -05:00
parent e10bf47427
commit 56d1f62020
2 changed files with 73 additions and 54 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"image"
"image/color"
"log"
"math"
"math/rand/v2"
"mover/assets"
@@ -49,8 +48,8 @@ type Game struct {
timer int
targets []*elements.Mover
gamepadIDsBuf []ebiten.GamepadID
gamepadIDs map[ebiten.GamepadID]struct{}
//gamepadIDsBuf []ebiten.GamepadID
//gamepadIDs map[ebiten.GamepadID]struct{}
//axes map[ebiten.GamepadID][]string
//pressedButtons map[ebiten.GamepadID][]string
}
@@ -101,22 +100,22 @@ func (g *Game) Initialize() {
}
func (g *Game) Update() error {
if g.gamepadIDs == nil {
g.gamepadIDs = map[ebiten.GamepadID]struct{}{}
}
g.gamepadIDsBuf = inpututil.AppendJustConnectedGamepadIDs(g.gamepadIDsBuf[:0])
for _, id := range g.gamepadIDsBuf {
log.Printf("gamepad connected: id: %d, SDL ID: %s", id, ebiten.GamepadSDLID(id))
g.gamepadIDs[id] = struct{}{}
}
for id := range g.gamepadIDs {
if inpututil.IsGamepadJustDisconnected(id) {
log.Printf("gamepad disconnected: id: %d", id)
delete(g.gamepadIDs, id)
/*
if g.gamepadIDs == nil {
g.gamepadIDs = map[ebiten.GamepadID]struct{}{}
}
}
g.gamepadIDsBuf = inpututil.AppendJustConnectedGamepadIDs(g.gamepadIDsBuf[:0])
for _, id := range g.gamepadIDsBuf {
log.Printf("gamepad connected: id: %d, SDL ID: %s", id, ebiten.GamepadSDLID(id))
g.gamepadIDs[id] = struct{}{}
}
for id := range g.gamepadIDs {
if inpututil.IsGamepadJustDisconnected(id) {
log.Printf("gamepad disconnected: id: %d", id)
delete(g.gamepadIDs, id)
}
}*/
if !g.initialized || g.reset {
g.Initialize()
@@ -422,39 +421,39 @@ func (g *Game) AppendProjectiles() {
}
func (g *Game) HandleInput() {
if len(g.gamepadIDs) > 0 {
if inpututil.IsStandardGamepadButtonJustPressed(0, ebiten.StandardGamepadButtonRightStick) {
if !g.explosion.Active && !g.gameover {
g.explosion.SetOrigin(g.hero.Pos)
g.explosion.Reset()
g.explosion.ToggleActivate()
}
}
if inpututil.IsStandardGamepadButtonJustPressed(0, ebiten.StandardGamepadButtonCenterRight) {
if g.gameover {
g.reset = true
} else {
g.Paused = !g.Paused
}
}
//account for controller sensitivity
if !g.gameover {
xaxis := ebiten.StandardGamepadAxisValue(0, ebiten.StandardGamepadAxisRightStickHorizontal)
yaxis := ebiten.StandardGamepadAxisValue(0, ebiten.StandardGamepadAxisRightStickVertical)
if yaxis <= 0.09 && yaxis >= -0.09 {
yaxis = 0
}
if xaxis <= 0.09 && xaxis >= -0.09 {
xaxis = 0
}
inputangle := math.Atan2(yaxis, xaxis)
g.hero.SetAngle(inputangle)
//if len(g.gamepadIDs) > 0 {
if inpututil.IsStandardGamepadButtonJustPressed(0, ebiten.StandardGamepadButtonRightStick) {
if !g.explosion.Active && !g.gameover {
g.explosion.SetOrigin(g.hero.Pos)
g.explosion.Reset()
g.explosion.ToggleActivate()
}
}
if inpututil.IsStandardGamepadButtonJustPressed(0, ebiten.StandardGamepadButtonCenterRight) {
if g.gameover {
g.reset = true
} else {
g.Paused = !g.Paused
}
}
//account for controller sensitivity
if !g.gameover {
xaxis := ebiten.StandardGamepadAxisValue(0, ebiten.StandardGamepadAxisRightStickHorizontal)
yaxis := ebiten.StandardGamepadAxisValue(0, ebiten.StandardGamepadAxisRightStickVertical)
if yaxis <= 0.09 && yaxis >= -0.09 {
yaxis = 0
}
if xaxis <= 0.09 && xaxis >= -0.09 {
xaxis = 0
}
inputangle := math.Atan2(yaxis, xaxis)
g.hero.SetAngle(inputangle)
}
//}
}
func (g *Game) UpdateHeroPosition() {