Splash screen update, gamepad cleanup on main game.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package screens
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"math"
|
||||
"mover/fonts"
|
||||
"mover/gamedata"
|
||||
|
||||
@@ -11,29 +12,48 @@ import (
|
||||
)
|
||||
|
||||
type StartScreen struct {
|
||||
eHandler map[ScreenManagerEvent]func()
|
||||
dimensions gamedata.Area
|
||||
eHandler map[ScreenManagerEvent]func()
|
||||
dimensions gamedata.Area
|
||||
target gamedata.Coordinates
|
||||
current gamedata.Coordinates
|
||||
targetreached bool
|
||||
}
|
||||
|
||||
func NewStartScreen() *StartScreen {
|
||||
s := &StartScreen{
|
||||
eHandler: make(map[ScreenManagerEvent]func()),
|
||||
eHandler: make(map[ScreenManagerEvent]func()),
|
||||
target: gamedata.Coordinates{X: 640/2 - 150, Y: 480 / 2},
|
||||
current: gamedata.Coordinates{X: 640/2 - 150, Y: -100},
|
||||
targetreached: false,
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *StartScreen) Update() error {
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) ||
|
||||
ebiten.IsStandardGamepadButtonPressed(0, ebiten.StandardGamepadButtonCenterRight) {
|
||||
s.eHandler[EventCompleted]()
|
||||
}
|
||||
|
||||
s.current.X += (s.target.X - s.current.X) / 8
|
||||
s.current.Y += (s.target.Y - s.current.Y) / 8
|
||||
|
||||
if math.Abs(s.current.Y-s.target.Y) < 1 && !s.targetreached {
|
||||
s.targetreached = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StartScreen) Draw(screen *ebiten.Image) {
|
||||
screen.Clear()
|
||||
text.Draw(screen, "survive", fonts.SurviveFont.ArcadeLarge, 40, 80, color.White)
|
||||
text.Draw(screen, "survive", fonts.SurviveFont.ArcadeLarge, int(s.current.X), int(s.current.Y), color.White)
|
||||
|
||||
if s.targetreached {
|
||||
text.Draw(screen, "press start", fonts.SurviveFont.Arcade, 640/2-25, 300, color.White)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *StartScreen) SetEventHandler(e ScreenManagerEvent, f func()) {
|
||||
|
||||
Reference in New Issue
Block a user