Added music and sfx.
This commit is contained in:
@@ -3,6 +3,7 @@ package screens
|
||||
import (
|
||||
"image/color"
|
||||
"math"
|
||||
"mover/assets"
|
||||
"mover/fonts"
|
||||
"mover/gamedata"
|
||||
|
||||
@@ -17,6 +18,8 @@ type StartScreen struct {
|
||||
target gamedata.Coordinates
|
||||
current gamedata.Coordinates
|
||||
targetreached bool
|
||||
audioplayed bool
|
||||
cycle int
|
||||
}
|
||||
|
||||
func NewStartScreen() *StartScreen {
|
||||
@@ -25,6 +28,8 @@ func NewStartScreen() *StartScreen {
|
||||
target: gamedata.Coordinates{X: 640/2 - 150, Y: 480 / 2},
|
||||
current: gamedata.Coordinates{X: 640/2 - 150, Y: -100},
|
||||
targetreached: false,
|
||||
cycle: 0,
|
||||
audioplayed: false,
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -36,13 +41,24 @@ func (s *StartScreen) Update() error {
|
||||
s.eHandler[EventCompleted]()
|
||||
}
|
||||
|
||||
s.current.X += (s.target.X - s.current.X) / 8
|
||||
s.current.Y += (s.target.Y - s.current.Y) / 8
|
||||
if !s.audioplayed {
|
||||
player := audioContext.NewPlayerFromBytes(assets.Survive)
|
||||
player.Play()
|
||||
s.audioplayed = true
|
||||
}
|
||||
|
||||
if !s.targetreached {
|
||||
s.current.X += (s.target.X - s.current.X) / 8
|
||||
s.current.Y += (s.target.Y - s.current.Y) / 8
|
||||
} else {
|
||||
s.current.Y += 0.5 * math.Sin(float64(s.cycle)/(math.Pi*8))
|
||||
}
|
||||
|
||||
if math.Abs(s.current.Y-s.target.Y) < 1 && !s.targetreached {
|
||||
s.targetreached = true
|
||||
}
|
||||
|
||||
s.cycle++
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user