- DayNight.forced ("" / "morning" / "night") overrides target(); snap()
still works. DayNight.morning() is the MORNING phase's look.
lanterns_dark keeps every lantern at 0.
- synth_audio.gd: ufo_hum (4 s loop), ufo_whine, part_fall, life_flash,
ufo_zoom, car_door, each on its own seed (existing wavs unchanged).
FarmAudio cues for those plus door_creak (kenney creak1/2), all in
LOCAL_CUES.
- PlayerCharacter: a blue core glow on the chest bone (BoneAttachment3D):
an unshaded gem, an additive halo pulled toward the camera, and a weak
pulsing OmniLight3D. On for every scarecrow; set_core_glow(on) hides
it. set_tint skips it; the hit flash overlay and ToonLook leave it alone.
- test_look: forced/lanterns_dark, the intro cues, the glow on both
scarecrows, hit flash intact, set_core_glow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
146 lines
5.3 KiB
GDScript
146 lines
5.3 KiB
GDScript
class_name DayNight
|
|
extends Node
|
|
## Lighting through the vacation's phases. Four keyed looks (day, sunset, night, sunrise) set
|
|
## the sun's angle, color, and strength, the ambient and sky light, and a whole-picture
|
|
## brightness and saturation (Environment adjustments, which leave the HUD alone):
|
|
## morning review -> mostly day; day -> day; dusk -> day turning to sunset over the dusk;
|
|
## night -> sunset to night in the first NIGHTFALL seconds (the sun becomes the moon);
|
|
## dawn -> night to sunrise over the dawn grace (brightening early: by the square root).
|
|
## The scarecrow carries a lantern that lights up as it gets dark, and enemies glow faintly at
|
|
## night (night_glow in thief.gdshader and ufo.gdshader) so they stay readable. The current
|
|
## look eases toward the target, so phase changes never pop.
|
|
## A cutscene (the opening intro) can hold a look whatever the phase (forced: "morning" or
|
|
## "night") and keep the lanterns dark (lanterns_dark); both are cleared to give the phase back.
|
|
|
|
const NIGHTFALL := 8.0
|
|
const EASE := 2.5
|
|
|
|
const DAY := {"elev": 55.0, "yaw": -35.0, "color": Color(1.0, 0.96, 0.88), "energy": 1.1, "ambient": 1.0,
|
|
"sky": 1.0, "bright": 1.0, "sat": 1.0, "lantern": 0.0, "glow": 0.0}
|
|
const SUNSET := {"elev": 9.0, "yaw": -70.0, "color": Color(1.0, 0.55, 0.3), "energy": 0.8, "ambient": 0.6,
|
|
"sky": 0.55, "bright": 0.92, "sat": 1.05, "lantern": 0.6, "glow": 0.3}
|
|
const NIGHT := {"elev": 48.0, "yaw": 25.0, "color": Color(0.55, 0.66, 1.0), "energy": 0.38, "ambient": 0.35,
|
|
"sky": 0.12, "bright": 0.78, "sat": 0.62, "lantern": 1.9, "glow": 1.0}
|
|
const SUNRISE := {"elev": 10.0, "yaw": 150.0, "color": Color(1.0, 0.72, 0.58), "energy": 0.75, "ambient": 0.6,
|
|
"sky": 0.6, "bright": 0.94, "sat": 1.0, "lantern": 0.5, "glow": 0.2}
|
|
|
|
var campaign: CampaignController
|
|
var sun: DirectionalLight3D
|
|
var env: Environment
|
|
## The flyers' materials (crows, UFOs), given night_glow.
|
|
var enemy_materials: Array[ShaderMaterial] = []
|
|
## Set by FarmSim: the ground enemies' characters glow too.
|
|
var characters: EnemyCharacters
|
|
var lantern: OmniLight3D
|
|
## Co-op: player 2's lantern (add_lantern), lit the same.
|
|
var lanterns: Array[OmniLight3D] = []
|
|
var current := DAY.duplicate()
|
|
## "" follows the phase; "morning" holds the MORNING phase's look and "night" the NIGHT look
|
|
## (target() returns it; the current look eases toward it, or snap() jumps to it).
|
|
var forced := ""
|
|
## Every lantern stays off while set (the intro's scarecrow isn't alive yet).
|
|
var lanterns_dark := false
|
|
|
|
|
|
func setup(p_campaign: CampaignController, p_sun: DirectionalLight3D, p_env: Environment, player: Node3D,
|
|
p_enemy_materials: Array[ShaderMaterial]) -> void:
|
|
campaign = p_campaign
|
|
sun = p_sun
|
|
env = p_env
|
|
enemy_materials = p_enemy_materials
|
|
env.adjustment_enabled = true
|
|
lantern = add_lantern(player)
|
|
snap()
|
|
|
|
|
|
## A lantern carried by a scarecrow (the first is player 1's).
|
|
func add_lantern(body: Node3D) -> OmniLight3D:
|
|
var l := OmniLight3D.new()
|
|
l.name = "Lantern"
|
|
l.light_color = Color(1.0, 0.8, 0.5)
|
|
l.omni_range = 9.0
|
|
l.omni_attenuation = 1.4
|
|
l.shadow_enabled = false
|
|
l.position = Vector3(0.0, 2.6, 0.0)
|
|
body.add_child(l)
|
|
lanterns.append(l)
|
|
return l
|
|
|
|
|
|
## 0 in daylight .. 1 at full night.
|
|
func darkness() -> float:
|
|
return clampf(float(current["glow"]), 0.0, 1.0)
|
|
|
|
|
|
## Jumps straight to the current phase's look (new vacation, retry, tests).
|
|
func snap() -> void:
|
|
current = target()
|
|
_apply()
|
|
|
|
|
|
func target() -> Dictionary:
|
|
match forced:
|
|
"morning":
|
|
return morning()
|
|
"night":
|
|
return NIGHT
|
|
var s := campaign.state
|
|
var cfg := campaign.config
|
|
var length := campaign.phase_length(s.phase)
|
|
var elapsed := length - s.phase_time_left if is_finite(length) else 0.0
|
|
var p := clampf(elapsed / length, 0.0, 1.0) if is_finite(length) and length > 0.0 else 0.0
|
|
match s.phase:
|
|
CampaignController.Phase.MORNING:
|
|
return morning()
|
|
CampaignController.Phase.DUSK:
|
|
return _mix(DAY, SUNSET, p)
|
|
CampaignController.Phase.NIGHT:
|
|
return _mix(SUNSET, NIGHT, clampf(elapsed / NIGHTFALL, 0.0, 1.0))
|
|
CampaignController.Phase.DAWN:
|
|
return _mix(NIGHT, SUNRISE, sqrt(p))
|
|
CampaignController.Phase.GAME_OVER:
|
|
return current
|
|
return DAY
|
|
|
|
|
|
## The MORNING phase's look: mostly day, a little sunrise.
|
|
static func morning() -> Dictionary:
|
|
return _mix(SUNRISE, DAY, 0.7)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if campaign == null:
|
|
return
|
|
current = _mix(current, target(), 1.0 - exp(-EASE * delta))
|
|
_apply()
|
|
|
|
|
|
func _apply() -> void:
|
|
sun.rotation = Vector3(deg_to_rad(-float(current["elev"])), deg_to_rad(float(current["yaw"])), 0.0)
|
|
sun.light_color = current["color"]
|
|
sun.light_energy = current["energy"]
|
|
env.ambient_light_energy = current["ambient"]
|
|
env.background_energy_multiplier = current["sky"]
|
|
env.adjustment_brightness = current["bright"]
|
|
env.adjustment_saturation = current["sat"]
|
|
for l in lanterns:
|
|
if is_instance_valid(l):
|
|
l.light_energy = 0.0 if lanterns_dark else float(current["lantern"])
|
|
for m in enemy_materials:
|
|
if m != null:
|
|
m.set_shader_parameter("night_glow", current["glow"])
|
|
if characters != null:
|
|
characters.set_night_glow(current["glow"])
|
|
|
|
|
|
static func _mix(a: Dictionary, b: Dictionary, t: float) -> Dictionary:
|
|
var out := {}
|
|
for k in a:
|
|
var va: Variant = a[k]
|
|
if va is Color:
|
|
out[k] = (va as Color).lerp(b[k], t)
|
|
elif k == "yaw":
|
|
out[k] = rad_to_deg(lerp_angle(deg_to_rad(va), deg_to_rad(b[k]), t))
|
|
else:
|
|
out[k] = lerpf(va, b[k], t)
|
|
return out
|