Better commenting throughout

This commit is contained in:
2025-11-24 12:29:19 -07:00
parent 175479da69
commit 5e0413a259
14 changed files with 107 additions and 195 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/atridad/LilGuy/internal/world"
)
// Screen and hero defaults
var (
backgroundColor = color.NRGBA{R: 135, G: 206, B: 235, A: 255}
saveNotificationColor = color.NRGBA{R: 50, G: 200, B: 50, A: 255}
@@ -38,13 +39,12 @@ var (
heroColor = color.NRGBA{R: 210, G: 220, B: 255, A: 255}
)
// HUD settings.
// HUD positioning and colors
const (
hudX = 960 - 220 // ScreenWidth - 220
hudX = 960 - 220
hudY = 20
)
// HUD colors.
var (
staminaNormalColor = color.NRGBA{R: 0, G: 255, B: 180, A: 255}
staminaLowColor = color.NRGBA{R: 255, G: 60, B: 60, A: 255}
@@ -53,6 +53,7 @@ var (
fpsPoorColor = color.NRGBA{R: 255, G: 120, B: 120, A: 255}
)
// FPS monitoring thresholds
const (
staminaLowThreshold = 0.2
fpsWarnThreshold = 0.85
@@ -61,7 +62,6 @@ const (
targetTPS = 60
)
// Player input for the gameplay screen.
type GameplayInput struct {
Left bool
Right bool
@@ -70,8 +70,6 @@ type GameplayInput struct {
Shoot bool
}
// Manages the main gameplay state including the hero, HUD, and game world.
// This is where the actual game logic and rendering happens during active play.
type GameplayScreen struct {
hero *hero.Hero
hud hud.Overlay
@@ -90,7 +88,6 @@ type GameplayScreen struct {
showSaveNotification bool
}
// Creates a new gameplay screen instance.
func NewGameplayScreen(screenWidth, screenHeight int, fpsEnabled *bool) *GameplayScreen {
w := world.NewWorld()
@@ -133,7 +130,6 @@ func NewGameplayScreen(screenWidth, screenHeight int, fpsEnabled *bool) *Gamepla
}
}
// Processes gameplay logic with the given input and delta time.
func (g *GameplayScreen) Update(input GameplayInput, delta time.Duration) {
dt := delta.Seconds()
@@ -166,7 +162,7 @@ func (g *GameplayScreen) Update(input GameplayInput, delta time.Duration) {
}
}
// Calculates the current FPS if FPS monitoring is enabled.
// FPS tracking
func (g *GameplayScreen) trackFPS(delta time.Duration) {
if g.fpsEnabled == nil || !*g.fpsEnabled {
return
@@ -182,7 +178,7 @@ func (g *GameplayScreen) trackFPS(delta time.Duration) {
}
}
// Renders the gameplay screen.
// Rendering
func (g *GameplayScreen) Draw(screen *ebiten.Image) {
screen.Fill(backgroundColor)
@@ -205,7 +201,6 @@ func (g *GameplayScreen) Draw(screen *ebiten.Image) {
meters := []status.Meter{staminaMeter}
if g.fpsEnabled != nil && *g.fpsEnabled {
// Color based on target FPS (60).
ratio := g.fpsValue / float64(targetTPS)
fpsColor := fpsGoodColor
switch {
@@ -217,7 +212,7 @@ func (g *GameplayScreen) Draw(screen *ebiten.Image) {
fpsMeter := status.Meter{
Label: fmt.Sprintf("Framerate: %3.0f FPS", g.fpsValue),
Base: -1, // Negative base means text-only display.
Base: -1,
Level: 0,
Color: fpsColor,
}
@@ -266,7 +261,7 @@ func (g *GameplayScreen) ShowSaveNotification() {
g.saveNotificationTimer = saveNotificationDuration
}
// Resets the gameplay screen to its initial state.
// State management
func (g *GameplayScreen) Reset() {
screenWidth := int(g.bounds.Width)
screenHeight := int(g.bounds.Height)
@@ -307,7 +302,6 @@ func (g *GameplayScreen) Reset() {
g.fpsValue = 0
}
// SaveState converts the current gameplay state to a saveable format.
func (g *GameplayScreen) SaveState() *save.GameState {
return &save.GameState{
HeroX: g.hero.X,
@@ -317,7 +311,6 @@ func (g *GameplayScreen) SaveState() *save.GameState {
}
}
// LoadState restores gameplay state from saved data.
func (g *GameplayScreen) LoadState(state *save.GameState) {
screenWidth := int(g.bounds.Width)
screenHeight := int(g.bounds.Height)