UFOs no longer reuse the crow's bird mesh. EnemySystem.build_ufo_mesh() merges the mesh arrays of two CylinderMesh hull halves, a TorusMesh rim, a hemisphere SphereMesh dome and eight small sphere lights into one ArrayMesh (about 1.65 m across, -0.13..0.45 m about its origin), with per-part vertex colors and (glow, metalness) in UV. A second HordeRenderer (ufo_renderer) draws it with the new game/resources/ufo.gdshader: albedo from COLOR, no flap, a slow spin and bob with a per-enemy phase, chasing rim lights, and the bird shader's hit flash (INSTANCE_CUSTOM.g) and night_glow. Both batches mirror the dense slots (write_new, move_slot, clear), and commit_render scales each slot to nothing in the batch that doesn't draw its type. DayNight now takes a list of enemy materials and sets night_glow on both. UFOs get their own arrival cue (kenney/digital/powerUp2.ogg, previously unused) instead of the crow's caw. HordeRenderer.is_drawn() backs the new test_roster checks: a UFO is drawn by the UFO batch only, a crow by the bird batch only, a thief by neither, also after a swap-removal; and the saucer's size and centering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
4.6 KiB
GDScript
129 lines
4.6 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.
|
|
|
|
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()
|
|
|
|
|
|
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:
|
|
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 _mix(SUNRISE, DAY, 0.7)
|
|
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
|
|
|
|
|
|
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 = 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
|