Lighting experiments
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/atridad/LilGuy/internal/maps"
|
||||
"github.com/atridad/LilGuy/internal/portal"
|
||||
"github.com/atridad/LilGuy/internal/projectile"
|
||||
"github.com/atridad/LilGuy/internal/raycast"
|
||||
"github.com/atridad/LilGuy/internal/save"
|
||||
"github.com/atridad/LilGuy/internal/status"
|
||||
"github.com/atridad/LilGuy/internal/ui/hud"
|
||||
@@ -48,9 +49,14 @@ type GameplayScreen struct {
|
||||
showSaveNotification bool
|
||||
|
||||
portalVisibility *bool
|
||||
|
||||
// Raycasting system
|
||||
raycastSystem *raycast.System
|
||||
raycastEnabled *bool
|
||||
raycastDebugMode *bool
|
||||
}
|
||||
|
||||
func NewGameplayScreen(screenWidth, screenHeight int, mapManager *maps.Manager, fpsEnabled *bool, portalVisibility *bool) *GameplayScreen {
|
||||
func NewGameplayScreen(screenWidth, screenHeight int, mapManager *maps.Manager, fpsEnabled *bool, portalVisibility *bool, raycastEnabled *bool, raycastDebugMode *bool) *GameplayScreen {
|
||||
cfg := config.Default()
|
||||
|
||||
// Ensure we have a current map
|
||||
@@ -100,6 +106,9 @@ func NewGameplayScreen(screenWidth, screenHeight int, mapManager *maps.Manager,
|
||||
gameStartTime: time.Now(),
|
||||
fpsEnabled: fpsEnabled,
|
||||
portalVisibility: portalVisibility,
|
||||
raycastSystem: raycast.NewSystem(screenWidth, screenHeight),
|
||||
raycastEnabled: raycastEnabled,
|
||||
raycastDebugMode: raycastDebugMode,
|
||||
}
|
||||
|
||||
gs.portals.OnTransition = gs.handlePortalTransition
|
||||
@@ -132,6 +141,9 @@ func (g *GameplayScreen) Update(input GameplayInput, delta time.Duration) {
|
||||
g.projectiles.Update(dt, g.bounds.Width, g.bounds.Height)
|
||||
g.portals.Update(dt)
|
||||
|
||||
// Update raycasting lights based on current map
|
||||
g.updateRaycastLights()
|
||||
|
||||
// check for portal collisions
|
||||
g.checkPortalCollision()
|
||||
|
||||
@@ -148,6 +160,40 @@ func (g *GameplayScreen) Update(input GameplayInput, delta time.Duration) {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameplayScreen) updateRaycastLights() {
|
||||
g.raycastSystem.ClearLights()
|
||||
|
||||
currentMap := g.mapManager.CurrentMap()
|
||||
if currentMap == nil {
|
||||
return
|
||||
}
|
||||
|
||||
screenWidth := g.bounds.Width
|
||||
|
||||
lightX := float64(screenWidth - 80)
|
||||
lightY := 80.0
|
||||
|
||||
if currentMap.TimeOfDay == maps.Daytime {
|
||||
g.raycastSystem.SetShadowIntensity(0.25)
|
||||
g.raycastSystem.AddLight(&raycast.LightSource{
|
||||
X: lightX,
|
||||
Y: lightY,
|
||||
Radius: 800.0,
|
||||
Color: color.RGBA{R: 255, G: 250, B: 220, A: 255},
|
||||
Intensity: 1.0,
|
||||
})
|
||||
} else {
|
||||
g.raycastSystem.SetShadowIntensity(0.7)
|
||||
g.raycastSystem.AddLight(&raycast.LightSource{
|
||||
X: lightX,
|
||||
Y: lightY,
|
||||
Radius: 500.0,
|
||||
Color: color.RGBA{R: 200, G: 220, B: 255, A: 255},
|
||||
Intensity: 0.7,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// portal collision detection
|
||||
func (g *GameplayScreen) checkPortalCollision() {
|
||||
heroRadius := g.hero.Radius
|
||||
@@ -229,6 +275,26 @@ func (g *GameplayScreen) Draw(screen *ebiten.Image) {
|
||||
if currentMap != nil {
|
||||
currentMap.Draw(screen)
|
||||
g.hud.ScreenName = currentMap.DisplayName
|
||||
|
||||
// Apply nighttime darkening overlay BEFORE raycasting
|
||||
if currentMap.TimeOfDay == maps.Nighttime {
|
||||
g.drawNightOverlay(screen)
|
||||
}
|
||||
|
||||
// Draw raycasting shadows/lighting
|
||||
if g.raycastEnabled != nil && *g.raycastEnabled {
|
||||
g.raycastSystem.Draw(screen, g.world)
|
||||
|
||||
if g.raycastDebugMode != nil && *g.raycastDebugMode {
|
||||
g.raycastSystem.DrawDebug(screen, g.world)
|
||||
}
|
||||
}
|
||||
|
||||
// Draw sun or moon circle in top-right
|
||||
g.drawCelestialBody(screen, currentMap)
|
||||
|
||||
// Update hero lighting state
|
||||
g.updateHeroLighting(currentMap)
|
||||
} else {
|
||||
screen.Fill(cfg.Visual.BackgroundColor)
|
||||
}
|
||||
@@ -307,6 +373,55 @@ func (g *GameplayScreen) drawSaveNotification(screen *ebiten.Image) {
|
||||
ebitenutil.DebugPrintAt(screen, msg, int(textX), int(textY))
|
||||
}
|
||||
|
||||
func (g *GameplayScreen) updateHeroLighting(currentMap *maps.Map) {
|
||||
if g.raycastEnabled == nil || !*g.raycastEnabled {
|
||||
g.hero.InShadow = false
|
||||
g.hero.ShadowIntensity = 0
|
||||
return
|
||||
}
|
||||
|
||||
// Check if hero is in shadow
|
||||
inShadow := g.raycastSystem.IsPointInShadow(g.hero.X, g.hero.Y, g.world)
|
||||
g.hero.InShadow = inShadow
|
||||
|
||||
if inShadow {
|
||||
if currentMap.TimeOfDay == maps.Daytime {
|
||||
g.hero.ShadowIntensity = 0.3
|
||||
} else {
|
||||
g.hero.ShadowIntensity = 0.6
|
||||
}
|
||||
} else {
|
||||
g.hero.ShadowIntensity = 0
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameplayScreen) drawNightOverlay(screen *ebiten.Image) {
|
||||
opts := &ebiten.DrawImageOptions{}
|
||||
opts.ColorScale.Scale(0.4, 0.4, 0.6, 1.0)
|
||||
|
||||
overlay := ebiten.NewImage(int(g.bounds.Width), int(g.bounds.Height))
|
||||
overlay.Fill(color.RGBA{R: 0, G: 0, B: 30, A: 120})
|
||||
screen.DrawImage(overlay, &ebiten.DrawImageOptions{})
|
||||
}
|
||||
|
||||
func (g *GameplayScreen) drawCelestialBody(screen *ebiten.Image, currentMap *maps.Map) {
|
||||
if currentMap == nil {
|
||||
return
|
||||
}
|
||||
|
||||
cx := float32(g.bounds.Width - 80)
|
||||
cy := float32(80)
|
||||
radius := float32(25)
|
||||
|
||||
if currentMap.TimeOfDay == maps.Daytime {
|
||||
vector.DrawFilledCircle(screen, cx, cy, radius, color.RGBA{R: 255, G: 230, B: 100, A: 255}, true)
|
||||
vector.DrawFilledCircle(screen, cx, cy, radius+3, color.RGBA{R: 255, G: 240, B: 150, A: 100}, true)
|
||||
} else {
|
||||
vector.DrawFilledCircle(screen, cx, cy, radius, color.RGBA{R: 240, G: 240, B: 255, A: 255}, true)
|
||||
vector.DrawFilledCircle(screen, cx, cy, radius+3, color.RGBA{R: 200, G: 200, B: 255, A: 80}, true)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameplayScreen) ShowSaveNotification() {
|
||||
g.showSaveNotification = true
|
||||
g.saveNotificationTimer = config.SaveNotificationDuration
|
||||
@@ -431,3 +546,33 @@ func (g *GameplayScreen) LoadState(state *save.GameState) {
|
||||
g.fpsAccumulator = 0
|
||||
g.fpsValue = 0
|
||||
}
|
||||
|
||||
// ToggleRaycast toggles the raycasting lighting system on/off
|
||||
func (g *GameplayScreen) ToggleRaycast() {
|
||||
if g.raycastEnabled != nil {
|
||||
*g.raycastEnabled = !*g.raycastEnabled
|
||||
}
|
||||
}
|
||||
|
||||
// ToggleRaycastDebug toggles the raycasting debug visualization
|
||||
func (g *GameplayScreen) ToggleRaycastDebug() {
|
||||
if g.raycastDebugMode != nil {
|
||||
*g.raycastDebugMode = !*g.raycastDebugMode
|
||||
}
|
||||
}
|
||||
|
||||
// IsRaycastEnabled returns whether raycasting is enabled
|
||||
func (g *GameplayScreen) IsRaycastEnabled() bool {
|
||||
if g.raycastEnabled == nil {
|
||||
return false
|
||||
}
|
||||
return *g.raycastEnabled
|
||||
}
|
||||
|
||||
// IsRaycastDebugMode returns whether raycasting debug mode is enabled
|
||||
func (g *GameplayScreen) IsRaycastDebugMode() bool {
|
||||
if g.raycastDebugMode == nil {
|
||||
return false
|
||||
}
|
||||
return *g.raycastDebugMode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user