From 264eab03081044fcfc94407ea8cfdb960cafc4c2 Mon Sep 17 00:00:00 2001 From: annieversary Date: Sat, 13 Aug 2022 12:34:51 +0100 Subject: [PATCH] make light pillars slowly light up --- assets/shaders/post-processing.wgsl | 2 +- src/main.rs | 5 ++-- src/pillar.rs | 37 +++++++++++++++++++++-------- src/player.rs | 4 ++-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/assets/shaders/post-processing.wgsl b/assets/shaders/post-processing.wgsl index 75606a7..e3bbcea 100644 --- a/assets/shaders/post-processing.wgsl +++ b/assets/shaders/post-processing.wgsl @@ -18,7 +18,7 @@ fn fragment( let uv = position.xy / vec2(view.width, view.height); let uv = floor(uv * 400.0) / 400.0; - let col = texturesample(texture, our_sampler, uv); + let col = textureSample(texture, our_sampler, uv); return round(col * 50.0) / 50.0; } diff --git a/src/main.rs b/src/main.rs index 42a0de7..50e5da6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ +#![allow(clippy::type_complexity)] + use bevy::{pbr::AmbientLight, prelude::*, sprite::Material2dPlugin, window::close_on_esc}; use bevy_mod_raycast::{DefaultRaycastingPlugin, RayCastMesh, RaycastSystem}; -// use bevy_prototype_debug_lines::*; mod camera; mod columns; @@ -28,7 +29,6 @@ fn main() { .insert_resource(Msaa { samples: 1 }) .insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0))) .add_plugins(DefaultPlugins) - // .add_plugin(DebugLinesPlugin::with_depth_test(true)) .add_plugin(Material2dPlugin::::default()) .init_resource::() .init_resource::() @@ -69,6 +69,7 @@ fn main() { .with_system(light_up_ball_when_close_to_player) .with_system(increase_progress_when_activating_pillar) .with_system(activate_pillar_when_progress_is_1) + .with_system(increase_range_up_to_max) .with_system(decrease_pillar_strength) .with_system(update_light_excitation_state) .with_system(toggle_debug), diff --git a/src/pillar.rs b/src/pillar.rs index cd9f8cb..e96198e 100644 --- a/src/pillar.rs +++ b/src/pillar.rs @@ -1,11 +1,20 @@ -use bevy::{pbr::CubemapVisibleEntities, prelude::*, render::primitives::CubemapFrusta}; +use bevy::{ + pbr::CubemapVisibleEntities, + prelude::*, + render::{primitives::CubemapFrusta, view::NoFrustumCulling}, +}; use crate::{camera::MouseCoords, player::LightFriends}; +// TODO maybe change these per pillar + const SIZE: f32 = 10.0; const HEIGHT: f32 = 20.0; -/// duration of pillar activation, in secs +/// how many seconds a pillar lasts activated const PILLAR_DURATION: f32 = 30.0; +/// the range for the pillar +const MAX_RANGE: f32 = 40.0; +const INTENSITY: f32 = 2000.0; #[derive(Component)] pub struct UnlitPillar; @@ -31,8 +40,11 @@ pub fn spawn_pillar( transform: Transform::from_translation(pos), ..Default::default() }) + // idk what these do .insert(CubemapFrusta::default()) .insert(CubemapVisibleEntities::default()) + // we want the light to keep working even if it's out of the camera + .insert(NoFrustumCulling) .insert(UnlitPillar); } @@ -94,7 +106,8 @@ pub fn activate_pillar_when_progress_is_1( }) .insert(PointLight { color: Color::rgb(15.0, 15.0, 15.0), - intensity: 500.0, + range: 1.0, + intensity: INTENSITY, ..Default::default() }); @@ -104,17 +117,21 @@ pub fn activate_pillar_when_progress_is_1( mat.emissive = Color::rgb(15.0, 15.0, 15.0); } } - } else { - if let Ok((handle, _)) = query.get(entity) { - if let Some(mat) = materials.get_mut(handle) { - mat.base_color = Color::rgb(15.0, 15.0, 15.0) * progress; - mat.emissive = Color::rgb(15.0, 15.0, 15.0) * progress; - } + } else if let Ok((handle, _)) = query.get(entity) { + if let Some(mat) = materials.get_mut(handle) { + mat.base_color = Color::rgb(15.0, 15.0, 15.0) * progress; + mat.emissive = Color::rgb(15.0, 15.0, 15.0) * progress; } } } } +pub fn increase_range_up_to_max(mut query: Query<&mut PointLight, With>) { + for mut light in &mut query { + light.range += (MAX_RANGE - light.range) / MAX_RANGE; + } +} + pub fn decrease_pillar_strength( mut commands: Commands, mut query: Query<( @@ -144,7 +161,7 @@ pub fn decrease_pillar_strength( mat.emissive = Color::rgb(0., 0., 0.); } } else { - light.intensity = i * 500.0; + light.intensity = i * INTENSITY; if let Some(mat) = materials.get_mut(handle) { mat.base_color = Color::rgb(15.0, 15.0, 15.0) * i.powf(1.3); diff --git a/src/player.rs b/src/player.rs index c769d2d..da0cc9b 100644 --- a/src/player.rs +++ b/src/player.rs @@ -182,7 +182,7 @@ pub fn move_player( mut animation_player: Query<&mut AnimationPlayer>, mut is_walking: Local, ) { - let ds = time.delta_seconds() * 5.0; + let ds = time.delta_seconds() * 7.0; let mut anim = if let Ok(player) = animation_player.get_single_mut() { player @@ -207,7 +207,7 @@ pub fn move_player( if !*is_walking && delta.length_squared() > 0.2 { anim.play(animations.run.clone_weak()).repeat(); - anim.set_speed(0.5); + anim.set_speed(0.7); *is_walking = true; } if *is_walking && delta.length_squared() < 0.2 {