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,7 +100,7 @@ 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{}{}
|
||||||
}
|
}
|
||||||
@@ -116,7 +115,7 @@ func (g *Game) Update() error {
|
|||||||
log.Printf("gamepad disconnected: id: %d", id)
|
log.Printf("gamepad disconnected: id: %d", id)
|
||||||
delete(g.gamepadIDs, id)
|
delete(g.gamepadIDs, id)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if !g.initialized || g.reset {
|
if !g.initialized || g.reset {
|
||||||
g.Initialize()
|
g.Initialize()
|
||||||
@@ -422,7 +421,7 @@ 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)
|
||||||
@@ -454,7 +453,7 @@ func (g *Game) HandleInput() {
|
|||||||
inputangle := math.Atan2(yaxis, xaxis)
|
inputangle := math.Atan2(yaxis, xaxis)
|
||||||
g.hero.SetAngle(inputangle)
|
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"
|
||||||
|
|
||||||
@@ -13,27 +14,46 @@ 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