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

@@ -8,6 +8,7 @@ import (
"github.com/atridad/LilGuy/internal/projectile"
)
// Hero defaults
const (
defaultRadius = 24.0
defaultSpeed = 200.0
@@ -36,6 +37,8 @@ const (
airFriction = 0.95
)
// Input and bounds
type Input struct {
Left bool
Right bool
@@ -64,6 +67,8 @@ const (
DirRight
)
// Hero state
type Hero struct {
X float64
Y float64
@@ -155,6 +160,8 @@ func (h *Hero) Update(input Input, dt float64, bounds Bounds) {
h.updateAnimation(dt)
}
// Movement and physics
func (h *Hero) updateMovement(input Input, dt float64, bounds Bounds) {
h.VelocityY += gravity * dt
if h.VelocityY > maxFallSpeed {
@@ -236,6 +243,8 @@ func (h *Hero) updateStamina(input Input, dt float64) {
}
}
// Animation
func (h *Hero) updateAnimation(dt float64) {
isMoving := h.isMoving
key := animationKey{direction: h.direction, state: animIdle}
@@ -275,6 +284,8 @@ func (h *Hero) getVisualState() VisualState {
return StateIdle
}
// Rendering
func (h *Hero) Draw(screen *ebiten.Image) {
sprite := h.getCurrentSprite()

View File

@@ -11,10 +11,12 @@ import (
"github.com/hajimehoshi/ebiten/v2"
)
// Asset paths
const (
heroDir = "assets/hero"
)
// Animation state
type animState int
const (
@@ -27,6 +29,7 @@ type animationKey struct {
state animState
}
// Sprite cache
var (
knightAnimations map[animationKey][]*ebiten.Image
)
@@ -47,6 +50,8 @@ func getKnightSprite(direction Direction, moving bool, frameIndex int) *ebiten.I
return frameFromSet(direction, state, frameIndex)
}
// Asset loading
func loadKnightAnimations() error {
frames, err := loadAnimationFrames(heroDir)
if err != nil {
@@ -113,6 +118,8 @@ func loadImage(path string) (*ebiten.Image, error) {
return ebiten.NewImageFromImage(img), nil
}
// Image manipulation
func flipImageHorizontally(img *ebiten.Image) *ebiten.Image {
bounds := img.Bounds()
w, h := bounds.Dx(), bounds.Dy()