From f53dc8122e50f711e42aaefcac30b422a0bb21e0 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 2 Oct 2021 23:48:30 -0400 Subject: [PATCH] Add appearing and disappearing boxes --- .../levels/level_0/disappearing_platforms.png | Bin 0 -> 17202 bytes game/assets/levels/level_0/zones.json | 15 ++- game/src/scenes/ingame_scene/level/loader.rs | 5 + game/src/scenes/ingame_scene/level/mod.rs | 1 + game/src/scenes/ingame_scene/world.rs | 111 +++++++++++++----- 5 files changed, 101 insertions(+), 31 deletions(-) create mode 100644 game/assets/levels/level_0/disappearing_platforms.png diff --git a/game/assets/levels/level_0/disappearing_platforms.png b/game/assets/levels/level_0/disappearing_platforms.png new file mode 100644 index 0000000000000000000000000000000000000000..3e1666c59f515370026e9f1f4857daa0508f527f GIT binary patch literal 17202 zcmeAS@N?(olHy`uVBq!ia0y~y;9tPN!2E)P4JdNz3S&6~17l03vvYu_v$H}$QGQxx zPAUU~#>Co*wjPHAL|XlWmj-Dyl?fD{2$-wW(Pfb(+7+O9g=?+Vj6GlYXPKyI>h(2c zA3Qk!=&I)K&FlEqH7WdHe)R0wk{3#<_oj|uYIJUeNyYA<;NMG;wp7dc0Kwi{e01Brt>|sW`40LoD!i^w&BvjH7Qv~f{z%6 zUe=61QMIP%-lH|4S!+uD{~hv(i;sL}wKh>@V~47Tz`_M>Mp_#Lm&d9fb((cf*zTX= zb^VFnis6zyGTbYin&137`2WH8oVACZv`iQAWVox}_t}uCrK~aSZsERu+2xf?Eb|++ z_r6_k)-com((7E^GL|p7%;MK`eQz@Bl{XwzcQ#86=ei`s#roiH&pu6do;yqrP4n~C z7SFL`ken6zip|1;#jShF-glqh%{#aA@9oR8?(-kKUXFdh=l#7{JL#%STQ4Irw0)wZEV@SoVHwPIR zfeIQX{9FHy0~Gb6U^E0qLtr!nMnhmU1V%$(Gz3ONU^E0qLtr!nMnhmU1V%$(ScgEv z&F#rdEsP2rP28?$7BYvvI3VMj;m0I8v+%?9+Kt27>!Y3<4S~@R7!85Z5Eu=C(GVC7 zfzc2c4S~@RfQ7&T(YroC_McOqKU)6(xbFJz57wYbLl~G|V2;cM39CA=!(<_J0?P|j z0frE!5;PIF20l~~hf!l-0Wumku#gx{H?WYPJWnMmD4&3>1pu2$xskLt=EtV;<7yl% z3<50S0<$;st=`m^f9{F>&JY99G_M^smax#Fy+crJVi?V#u<#hop|Fq`3fT$fRtP|LV{tmpnwI%Xh8uBiP3@r z780Wc1uP^+3kq0BJjlA=$H~BuAi;KY|0~KI7KkA@611&*c}NI;C{CP+ApmNU?dF, pub zones: LevelZones, } diff --git a/game/src/scenes/ingame_scene/world.rs b/game/src/scenes/ingame_scene/world.rs index e0b9242..7ed6877 100644 --- a/game/src/scenes/ingame_scene/world.rs +++ b/game/src/scenes/ingame_scene/world.rs @@ -13,6 +13,7 @@ use tracing::trace; pub const WORLD_LEVEL_X_OFFSET: f32 = 200.0; pub const APPEAR_FADE_DISTANCE: f32 = 16.0; +pub const DISAPPEAR_FADE_DISTANCE: f32 = 18.0; impl WorldSpaceRender for InGameScreen { fn render_world_space( @@ -37,37 +38,87 @@ impl WorldSpaceRender for InGameScreen { Color::WHITE, ); - // Calculate the distance between the player and the nearest appearing zone - let appear_zone_dist = cur_level - .zones - .appear - .iter() - .map(|zone| { - Vector2::new( - zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), - zone.y - cur_level.platform_tex.height as f32, - ) - .distance_to(self.player.position) as i32 - }) - .min() - .unwrap(); - let opacity = interpolate_exp( - (appear_zone_dist as f32).sub(APPEAR_FADE_DISTANCE.div(2.0)).div(APPEAR_FADE_DISTANCE).mul(-1.0), - -APPEAR_FADE_DISTANCE..APPEAR_FADE_DISTANCE, - 0.0..1.0, - 8.0, - ); - trace!("Appearing values: ({}, {})", appear_zone_dist, opacity); + { + // Calculate the distance between the player and the nearest appearing zone + let appear_zone_dist = cur_level + .zones + .appear + .iter() + .map(|zone| { + Vector2::new( + zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), + zone.y - cur_level.platform_tex.height as f32, + ) + .distance_to(self.player.position) as i32 + }) + .min() + .unwrap_or(i32::MAX); + let appear_opacity = interpolate_exp( + (appear_zone_dist as f32) + .sub(APPEAR_FADE_DISTANCE.div(2.0)) + .div(APPEAR_FADE_DISTANCE) + .mul(-1.0), + -APPEAR_FADE_DISTANCE..APPEAR_FADE_DISTANCE, + 0.0..1.0, + 8.0, + ); + trace!( + "Appearing values: ({}, {})", + appear_zone_dist, + appear_opacity + ); - // Render the appearing layer - raylib.draw_texture_v( - &cur_level.appearing_platform_tex, - Vector2::new( - WORLD_LEVEL_X_OFFSET, - -cur_level.appearing_platform_tex.height as f32, - ), - Color::WHITE.fade(opacity), - ); + // Render the appearing layer + raylib.draw_texture_v( + &cur_level.appearing_platform_tex, + Vector2::new( + WORLD_LEVEL_X_OFFSET, + -cur_level.appearing_platform_tex.height as f32, + ), + Color::WHITE.fade(appear_opacity), + ); + } + + { + // Calculate the distance between the player and the nearest disappearing zone + let disappear_zone_dist = cur_level + .zones + .disappear + .iter() + .map(|zone| { + Vector2::new( + zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), + zone.y - cur_level.platform_tex.height as f32, + ) + .distance_to(self.player.position) as i32 + }) + .min() + .unwrap_or(i32::MAX); + let disappear_opacity = interpolate_exp( + (disappear_zone_dist as f32) + .sub(DISAPPEAR_FADE_DISTANCE.div(2.0)) + .div(DISAPPEAR_FADE_DISTANCE) + .mul(-1.0), + -DISAPPEAR_FADE_DISTANCE..DISAPPEAR_FADE_DISTANCE, + 0.0..1.0, + 8.0, + ); + trace!( + "Disappearing values: ({}, {})", + disappear_zone_dist, + disappear_opacity + ); + + // Render the appearing layer + raylib.draw_texture_v( + &cur_level.disappearing_platform_tex, + Vector2::new( + WORLD_LEVEL_X_OFFSET, + -cur_level.disappearing_platform_tex.height as f32, + ), + Color::WHITE.fade(1.0 - disappear_opacity), + ); + } #[cfg(all(debug_assertions, feature = "collider_debug"))] {