Consolodated config, added portals, etc.

This commit is contained in:
2025-11-24 15:03:56 -07:00
parent f39684873b
commit 57d08f2f04
15 changed files with 895 additions and 212 deletions

View File

@@ -5,10 +5,10 @@ import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/atridad/LilGuy/internal/config"
"github.com/atridad/LilGuy/internal/projectile"
)
// Hero defaults
const (
defaultRadius = 24.0
defaultSpeed = 200.0
@@ -16,25 +16,7 @@ const (
defaultStaminaDrain = 50.0
defaultStaminaRegen = 30.0
sprintSpeedMultiplier = 1.8
sprintRecoveryThreshold = 0.2
normalAnimSpeed = 0.15
idleAnimSpeed = 0.3
sprintAnimSpeed = 0.08
exhaustedThreshold = 0.2
animFrameWrap = 4096
heroSpriteScale = 0.175
fixedSpriteHeight = 329.0
fixedSpriteWidth = 315.0
gravity = 1200.0
jumpStrength = -450.0
maxFallSpeed = 800.0
groundFriction = 0.85
airFriction = 0.95
heroSpriteScale = 0.175
)
// Input and bounds
@@ -163,9 +145,9 @@ func (h *Hero) Update(input Input, dt float64, bounds Bounds) {
// Movement and physics
func (h *Hero) updateMovement(input Input, dt float64, bounds Bounds) {
h.VelocityY += gravity * dt
if h.VelocityY > maxFallSpeed {
h.VelocityY = maxFallSpeed
h.VelocityY += config.Gravity * dt
if h.VelocityY > config.MaxFallSpeed {
h.VelocityY = config.MaxFallSpeed
}
h.Y += h.VelocityY * dt
@@ -180,7 +162,7 @@ func (h *Hero) updateMovement(input Input, dt float64, bounds Bounds) {
}
if input.Jump && h.isGrounded {
h.VelocityY = jumpStrength
h.VelocityY = config.JumpStrength
h.isGrounded = false
}
@@ -198,12 +180,12 @@ func (h *Hero) updateMovement(input Input, dt float64, bounds Bounds) {
h.isSprinting = input.Sprint && h.canSprint && h.Stamina > 0 && h.isMoving
if h.isSprinting {
targetVelocityX *= sprintSpeedMultiplier
targetVelocityX *= config.SprintSpeedMultiplier
}
friction := groundFriction
friction := config.GroundFriction
if !h.isGrounded {
friction = airFriction
friction = config.AirFriction
}
h.VelocityX = h.VelocityX*friction + targetVelocityX*(1-friction)
@@ -223,7 +205,7 @@ func (h *Hero) updateMovement(input Input, dt float64, bounds Bounds) {
func (h *Hero) updateStamina(input Input, dt float64) {
if !input.Sprint {
h.wasSprintHeld = false
if h.Stamina >= h.MaxStamina*sprintRecoveryThreshold {
if h.Stamina >= h.MaxStamina*config.SprintRecoveryThreshold {
h.canSprint = true
}
}
@@ -259,21 +241,24 @@ func (h *Hero) updateAnimation(dt float64) {
}
if isMoving {
animSpeed := normalAnimSpeed * 0.5
animSpeed := config.NormalAnimSpeed * 0.5
if h.isSprinting {
animSpeed = sprintAnimSpeed * 0.5
animSpeed = config.SprintAnimSpeed * 0.5
}
if !h.isGrounded {
animSpeed = config.JumpingAnimSpeed * 0.5
}
h.animTimer += dt
frameAdvance := int(h.animTimer / animSpeed)
if frameAdvance > 0 {
h.animTimer -= animSpeed * float64(frameAdvance)
h.animFrame = (h.animFrame + frameAdvance) % animFrameWrap
h.animFrame = (h.animFrame + frameAdvance) % config.AnimFrameWrap
}
}
}
func (h *Hero) getVisualState() VisualState {
if h.Stamina < h.MaxStamina*exhaustedThreshold {
if h.Stamina < h.MaxStamina*config.ExhaustedThreshold {
return StateExhausted
}
@@ -296,7 +281,7 @@ func (h *Hero) Draw(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-actualWidth/2, -actualHeight)
op.GeoM.Scale(heroSpriteScale, heroSpriteScale)
op.GeoM.Scale(config.HeroSpriteScale, config.HeroSpriteScale)
op.GeoM.Translate(h.X, h.Y)
state := h.getVisualState()