Better commenting throughout
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
)
|
||||
|
||||
// Represents the options available on the title screen.
|
||||
// Menu options
|
||||
type TitleMenuOption int
|
||||
|
||||
const (
|
||||
@@ -20,6 +20,7 @@ const (
|
||||
titleOptionCount
|
||||
)
|
||||
|
||||
// Screen modes
|
||||
type titleScreenMode int
|
||||
|
||||
const (
|
||||
@@ -27,8 +28,6 @@ const (
|
||||
titleModeSettings
|
||||
)
|
||||
|
||||
// Displays the main menu with Continue, New Game, Settings, and Quit options.
|
||||
// This is shown after the splash screen and when returning from the pause menu.
|
||||
type TitleScreen struct {
|
||||
selectedIndex int
|
||||
currentMode titleScreenMode
|
||||
@@ -36,7 +35,6 @@ type TitleScreen struct {
|
||||
hasSaveGame bool
|
||||
}
|
||||
|
||||
// Creates a new title screen instance.
|
||||
func NewTitleScreen() *TitleScreen {
|
||||
return &TitleScreen{
|
||||
selectedIndex: 0,
|
||||
@@ -46,28 +44,22 @@ func NewTitleScreen() *TitleScreen {
|
||||
}
|
||||
}
|
||||
|
||||
// Sets the FPS monitor toggle reference for settings.
|
||||
func (t *TitleScreen) SetFPSMonitor(enabled *bool) {
|
||||
t.settingsScreen.SetFPSMonitor(enabled)
|
||||
}
|
||||
|
||||
// Sets the FPS cap setting reference for settings.
|
||||
func (t *TitleScreen) SetFPSCap(cap FPSCapSetting) {
|
||||
t.settingsScreen.SetFPSCap(cap)
|
||||
}
|
||||
|
||||
// Sets whether a saved game exists.
|
||||
func (t *TitleScreen) SetHasSaveGame(hasSave bool) {
|
||||
t.hasSaveGame = hasSave
|
||||
// If no save game, skip Continue option
|
||||
if !hasSave && t.selectedIndex == 0 {
|
||||
t.selectedIndex = 1 // Move to New Game
|
||||
t.selectedIndex = 1
|
||||
}
|
||||
}
|
||||
|
||||
// Processes title screen input and returns the selected option if any.
|
||||
func (t *TitleScreen) Update() *TitleMenuOption {
|
||||
// Handle settings screen
|
||||
if t.currentMode == titleModeSettings {
|
||||
if t.settingsScreen.Update() {
|
||||
t.currentMode = titleModeMain
|
||||
@@ -76,13 +68,11 @@ func (t *TitleScreen) Update() *TitleMenuOption {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Handle main menu
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) || inpututil.IsKeyJustPressed(ebiten.KeyW) {
|
||||
t.selectedIndex--
|
||||
if t.selectedIndex < 0 {
|
||||
t.selectedIndex = int(titleOptionCount) - 1
|
||||
}
|
||||
// Skip Continue if no save exists
|
||||
if t.selectedIndex == int(TitleOptionContinue) && !t.hasSaveGame {
|
||||
t.selectedIndex--
|
||||
if t.selectedIndex < 0 {
|
||||
@@ -96,7 +86,6 @@ func (t *TitleScreen) Update() *TitleMenuOption {
|
||||
if t.selectedIndex >= int(titleOptionCount) {
|
||||
t.selectedIndex = 0
|
||||
}
|
||||
// Skip Continue if no save exists
|
||||
if t.selectedIndex == int(TitleOptionContinue) && !t.hasSaveGame {
|
||||
t.selectedIndex++
|
||||
if t.selectedIndex >= int(titleOptionCount) {
|
||||
@@ -118,18 +107,15 @@ func (t *TitleScreen) Update() *TitleMenuOption {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Renders the title screen.
|
||||
// Rendering
|
||||
func (t *TitleScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight int) {
|
||||
// If in settings mode, draw settings screen
|
||||
if t.currentMode == titleModeSettings {
|
||||
t.settingsScreen.Draw(screen, screenWidth, screenHeight, "SETTINGS")
|
||||
return
|
||||
}
|
||||
|
||||
// Draw main menu
|
||||
screen.Fill(color.RGBA{R: 20, G: 20, B: 30, A: 255})
|
||||
|
||||
// Draw game title
|
||||
titleText := "LIL GUY"
|
||||
scale := 3.0
|
||||
charWidth := 7.0 * scale
|
||||
@@ -144,12 +130,11 @@ func (t *TitleScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight int)
|
||||
op.ColorScale.ScaleWithColor(color.RGBA{R: 210, G: 220, B: 255, A: 255})
|
||||
text.Draw(screen, titleText, basicFace, op)
|
||||
|
||||
// Draw menu options
|
||||
// Draw menu
|
||||
options := []string{"Continue", "New Game", "Settings", "Quit"}
|
||||
startY := screenHeight/2 + 10
|
||||
|
||||
for i, option := range options {
|
||||
// Skip Continue option if no save exists
|
||||
if i == int(TitleOptionContinue) && !t.hasSaveGame {
|
||||
continue
|
||||
}
|
||||
@@ -163,12 +148,10 @@ func (t *TitleScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight int)
|
||||
}
|
||||
|
||||
if i == t.selectedIndex {
|
||||
// Draw selection indicator
|
||||
indicatorX := optionX - 20
|
||||
t.drawText(screen, ">", color.RGBA{R: 255, G: 200, B: 0, A: 255}, indicatorX, optionY)
|
||||
t.drawText(screen, option, color.RGBA{R: 255, G: 255, B: 100, A: 255}, optionX, optionY)
|
||||
|
||||
// Draw selection box
|
||||
boxPadding := float32(10.0)
|
||||
boxWidth := float32(len(option)*7) + boxPadding*2
|
||||
boxHeight := float32(20)
|
||||
@@ -182,7 +165,7 @@ func (t *TitleScreen) Draw(screen *ebiten.Image, screenWidth, screenHeight int)
|
||||
}
|
||||
}
|
||||
|
||||
// Draw hint text
|
||||
// Instructions
|
||||
hintText := "Use Arrow Keys/WASD to navigate, Enter/Space to select"
|
||||
hintX := (screenWidth / 2) - (len(hintText) * 7 / 2)
|
||||
hintY := screenHeight - 50
|
||||
@@ -196,9 +179,7 @@ func (t *TitleScreen) drawText(screen *ebiten.Image, txt string, clr color.Color
|
||||
text.Draw(screen, txt, basicFace, op)
|
||||
}
|
||||
|
||||
// Resets the title screen to its initial state.
|
||||
func (t *TitleScreen) Reset() {
|
||||
// Start at Continue if available, otherwise New Game
|
||||
if t.hasSaveGame {
|
||||
t.selectedIndex = 0
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user