Add appearing and disappearing boxes
This commit is contained in:
parent
e61f67ee30
commit
f53dc8122e
BIN
game/assets/levels/level_0/disappearing_platforms.png
Normal file
BIN
game/assets/levels/level_0/disappearing_platforms.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@ -7,7 +7,20 @@
|
||||
"height": 57
|
||||
}
|
||||
],
|
||||
"disappear": [],
|
||||
"disappear": [
|
||||
{
|
||||
"x": 792,
|
||||
"y": 462,
|
||||
"width": 54,
|
||||
"height": 468
|
||||
},
|
||||
{
|
||||
"x": 2005,
|
||||
"y": 641,
|
||||
"width": 141,
|
||||
"height": 289
|
||||
}
|
||||
],
|
||||
"win": {
|
||||
"x": 3000,
|
||||
"y": 0,
|
||||
|
@ -46,6 +46,11 @@ pub fn load_all_levels(
|
||||
thread,
|
||||
&format!("levels/{}/appearing_platforms.png", level_name),
|
||||
)?,
|
||||
disappearing_platform_tex: load_texture_from_internal_data(
|
||||
raylib_handle,
|
||||
thread,
|
||||
&format!("levels/{}/disappearing_platforms.png", level_name),
|
||||
)?,
|
||||
colliders: serde_json::from_str(
|
||||
&String::from_utf8(
|
||||
StaticGameData::get(&format!("levels/{}/colliders.json", level_name))
|
||||
|
@ -17,6 +17,7 @@ pub struct Level {
|
||||
pub background_tex: WorldPaintTexture,
|
||||
pub platform_tex: Texture2D,
|
||||
pub appearing_platform_tex: Texture2D,
|
||||
pub disappearing_platform_tex: Texture2D,
|
||||
pub colliders: Vec<Rectangle>,
|
||||
pub zones: LevelZones,
|
||||
}
|
||||
|
@ -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,6 +38,7 @@ impl WorldSpaceRender for InGameScreen {
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
{
|
||||
// Calculate the distance between the player and the nearest appearing zone
|
||||
let appear_zone_dist = cur_level
|
||||
.zones
|
||||
@ -50,14 +52,21 @@ impl WorldSpaceRender for InGameScreen {
|
||||
.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),
|
||||
.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, opacity);
|
||||
trace!(
|
||||
"Appearing values: ({}, {})",
|
||||
appear_zone_dist,
|
||||
appear_opacity
|
||||
);
|
||||
|
||||
// Render the appearing layer
|
||||
raylib.draw_texture_v(
|
||||
@ -66,8 +75,50 @@ impl WorldSpaceRender for InGameScreen {
|
||||
WORLD_LEVEL_X_OFFSET,
|
||||
-cur_level.appearing_platform_tex.height as f32,
|
||||
),
|
||||
Color::WHITE.fade(opacity),
|
||||
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"))]
|
||||
{
|
||||
|
Reference in New Issue
Block a user