Splash screen update, gamepad cleanup on main game.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
|
||||||
"math"
|
"math"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
"mover/assets"
|
"mover/assets"
|
||||||
@@ -49,8 +48,8 @@ type Game struct {
|
|||||||
timer int
|
timer int
|
||||||
targets []*elements.Mover
|
targets []*elements.Mover
|
||||||
|
|
||||||
gamepadIDsBuf []ebiten.GamepadID
|
//gamepadIDsBuf []ebiten.GamepadID
|
||||||
gamepadIDs map[ebiten.GamepadID]struct{}
|
//gamepadIDs map[ebiten.GamepadID]struct{}
|
||||||
//axes map[ebiten.GamepadID][]string
|
//axes map[ebiten.GamepadID][]string
|
||||||
//pressedButtons map[ebiten.GamepadID][]string
|
//pressedButtons map[ebiten.GamepadID][]string
|
||||||
}
|
}
|
||||||
@@ -101,22 +100,22 @@ func (g *Game) Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
|
/*
|
||||||
if g.gamepadIDs == nil {
|
if g.gamepadIDs == nil {
|
||||||
g.gamepadIDs = map[ebiten.GamepadID]struct{}{}
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
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 {
|
if !g.initialized || g.reset {
|
||||||
g.Initialize()
|
g.Initialize()
|
||||||
@@ -422,39 +421,39 @@ func (g *Game) AppendProjectiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) HandleInput() {
|
func (g *Game) HandleInput() {
|
||||||
if len(g.gamepadIDs) > 0 {
|
//if len(g.gamepadIDs) > 0 {
|
||||||
if inpututil.IsStandardGamepadButtonJustPressed(0, ebiten.StandardGamepadButtonRightStick) {
|
if inpututil.IsStandardGamepadButtonJustPressed(0, ebiten.StandardGamepadButtonRightStick) {
|
||||||
if !g.explosion.Active && !g.gameover {
|
if !g.explosion.Active && !g.gameover {
|
||||||
g.explosion.SetOrigin(g.hero.Pos)
|
g.explosion.SetOrigin(g.hero.Pos)
|
||||||
g.explosion.Reset()
|
g.explosion.Reset()
|
||||||
g.explosion.ToggleActivate()
|
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 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() {
|
func (g *Game) UpdateHeroPosition() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package screens
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"math"
|
||||||
"mover/fonts"
|
"mover/fonts"
|
||||||
"mover/gamedata"
|
"mover/gamedata"
|
||||||
|
|
||||||
@@ -11,29 +12,48 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type StartScreen struct {
|
type StartScreen struct {
|
||||||
eHandler map[ScreenManagerEvent]func()
|
eHandler map[ScreenManagerEvent]func()
|
||||||
dimensions gamedata.Area
|
dimensions gamedata.Area
|
||||||
|
target gamedata.Coordinates
|
||||||
|
current gamedata.Coordinates
|
||||||
|
targetreached bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStartScreen() *StartScreen {
|
func NewStartScreen() *StartScreen {
|
||||||
s := &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
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StartScreen) Update() error {
|
func (s *StartScreen) Update() error {
|
||||||
|
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
|
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) ||
|
||||||
|
ebiten.IsStandardGamepadButtonPressed(0, ebiten.StandardGamepadButtonCenterRight) {
|
||||||
s.eHandler[EventCompleted]()
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StartScreen) Draw(screen *ebiten.Image) {
|
func (s *StartScreen) Draw(screen *ebiten.Image) {
|
||||||
screen.Clear()
|
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()) {
|
func (s *StartScreen) SetEventHandler(e ScreenManagerEvent, f func()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user