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,7 +100,7 @@ func (g *Game) Initialize() {
|
||||
}
|
||||
|
||||
func (g *Game) Update() error {
|
||||
|
||||
/*
|
||||
if g.gamepadIDs == nil {
|
||||
g.gamepadIDs = map[ebiten.GamepadID]struct{}{}
|
||||
}
|
||||
@@ -116,7 +115,7 @@ func (g *Game) Update() error {
|
||||
log.Printf("gamepad disconnected: id: %d", id)
|
||||
delete(g.gamepadIDs, id)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if !g.initialized || g.reset {
|
||||
g.Initialize()
|
||||
@@ -422,7 +421,7 @@ func (g *Game) AppendProjectiles() {
|
||||
}
|
||||
|
||||
func (g *Game) HandleInput() {
|
||||
if len(g.gamepadIDs) > 0 {
|
||||
//if len(g.gamepadIDs) > 0 {
|
||||
if inpututil.IsStandardGamepadButtonJustPressed(0, ebiten.StandardGamepadButtonRightStick) {
|
||||
if !g.explosion.Active && !g.gameover {
|
||||
g.explosion.SetOrigin(g.hero.Pos)
|
||||
@@ -454,7 +453,7 @@ func (g *Game) HandleInput() {
|
||||
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"
|
||||
|
||||
@@ -13,27 +14,46 @@ import (
|
||||
type StartScreen struct {
|
||||
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()),
|
||||
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