Better commenting throughout
This commit is contained in:
@@ -15,14 +15,14 @@ var (
|
||||
basicFaceAscent = basicFace.Metrics().HAscent
|
||||
)
|
||||
|
||||
// Timing
|
||||
|
||||
const (
|
||||
splashDuration = 2 * time.Second
|
||||
fadeInDuration = 500 * time.Millisecond
|
||||
fadeOutDuration = 500 * time.Millisecond
|
||||
)
|
||||
|
||||
// Displays the game title with fade in/out effects.
|
||||
// This is typically the first screen shown when the game starts.
|
||||
type SplashScreen struct {
|
||||
startTime time.Time
|
||||
fadeInEnd time.Time
|
||||
@@ -30,7 +30,6 @@ type SplashScreen struct {
|
||||
endTime time.Time
|
||||
}
|
||||
|
||||
// Creates a new splash screen instance.
|
||||
func NewSplashScreen() *SplashScreen {
|
||||
now := time.Now()
|
||||
return &SplashScreen{
|
||||
@@ -41,15 +40,11 @@ func NewSplashScreen() *SplashScreen {
|
||||
}
|
||||
}
|
||||
|
||||
// Processes splash screen logic.
|
||||
// Returns true when the splash screen should end and transition to the next screen.
|
||||
func (s *SplashScreen) Update() bool {
|
||||
// Return true if splash is complete
|
||||
if time.Now().After(s.endTime) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Allow skipping with any key
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeySpace) ||
|
||||
inpututil.IsKeyJustPressed(ebiten.KeyEnter) ||
|
||||
inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
|
||||
@@ -59,14 +54,14 @@ func (s *SplashScreen) Update() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Renders the splash screen.
|
||||
// Rendering
|
||||
|
||||
func (s *SplashScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight int) {
|
||||
screen.Fill(color.RGBA{R: 0, G: 0, B: 0, A: 255})
|
||||
|
||||
now := time.Now()
|
||||
alpha := 1.0
|
||||
|
||||
// Calculate fade in/out
|
||||
if now.Before(s.fadeInEnd) {
|
||||
elapsed := now.Sub(s.startTime)
|
||||
alpha = float64(elapsed) / float64(fadeInDuration)
|
||||
@@ -81,10 +76,9 @@ func (s *SplashScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight int)
|
||||
alpha = 1
|
||||
}
|
||||
|
||||
// Draw large game title
|
||||
// Draw title
|
||||
titleText := "LIL GUY"
|
||||
|
||||
// Calculate size for large text (scale up the basic font)
|
||||
scale := 4.0
|
||||
charWidth := 7.0 * scale
|
||||
textWidth := float64(len(titleText)) * charWidth
|
||||
|
||||
Reference in New Issue
Block a user