use crate::game::*; use crate::iso::*; use crate::player::{facing_of, Mover, Pad, Player}; use crate::sheets::CharSheets; use crate::sprites; use crate::travel::{self, rnd, CampFlame, CampLight, Rain, Travel, BASE_CLEAR, NIGHT}; use crate::world::{Emissive, Glow, Lamp, Puff}; use bevy::prelude::*; use std::f32::consts::{FRAC_PI_4, TAU}; const WARM: Vec3 = Vec3::new(1.0, 0.86, 0.62); const SEEN: &str = "ev_wolves_seen"; const LEAVE: &str = "wolves_leave"; const PACK: usize = 3; const SPAWN_R: (f32, f32) = (10.0, 12.0); const WOLF_SPEED: f32 = 2.8; const FLEE_SPEED: f32 = 4.0; const STRIDE: f32 = 1.2; const RING_FIRE: f32 = 5.5; const RING_LIT: f32 = 5.0; const RING_DARK: f32 = 0.9; const BITE: f32 = 1.2; const GIVE_UP: f32 = 18.0; const LAMP_R: f32 = 4.0; const LANTERN_R: f32 = 4.5; const FIRE_R: f32 = 5.5; pub struct NightPlugin; impl Plugin for NightPlugin { fn build(&self, app: &mut App) { app.init_resource::().add_systems( Update, (lantern_key, pack_spawn, pack_run, lantern_glow, lighting, glow_blobs).chain().after(travel::roadside), ); } } #[derive(Resource, Default)] struct Pack { ring: f32, } #[derive(Component)] struct Wolf { pos: Vec2, facing: usize, slot: f32, run: f32, away: bool, eyes: Entity, } #[derive(Component)] struct Eyes; #[derive(Component)] struct LanternGlow; #[derive(Clone, Copy)] struct Src { pos: Vec2, r: f32, } fn wolf_hours(h: f32) -> bool { h >= 20.0 || h < 5.5 } fn sources(g: &Game, lamps: &Query<&Lamp>, fires: &Query<&CampLight>, player: Option) -> Vec { let mut v: Vec = lamps.iter().map(|l| Src { pos: l.0, r: LAMP_R }).collect(); v.extend(fires.iter().map(|f| Src { pos: f.0, r: FIRE_R })); if let Some(p) = player { if g.flag("lantern") && g.has(Item::Lantern) { v.push(Src { pos: p, r: LANTERN_R }); } } v } fn light_at(srcs: &[Src], p: Vec2) -> f32 { srcs.iter() .map(|s| { let t = ((p.distance(s.pos) / s.r - 0.4) / 0.6).clamp(0.0, 1.0); 1.0 - t * t * (3.0 - 2.0 * t) }) .fold(0.0, f32::max) } fn lantern_key(pad: Res, mut g: ResMut) { if !pad.lantern || g.dialog.is_some() || !g.has(Item::Lantern) { return; } if g.flag("lantern") { g.unset("lantern"); } else { g.set("lantern"); } g.sfx.push(Sfx::Lantern); } fn lantern_glow( mut commands: Commands, time: Res