Appearing platforms
This commit is contained in:
parent
cdb8b8dd83
commit
f31a32c7ec
BIN
game/assets/levels/level_0/appearing_platforms.png
Normal file
BIN
game/assets/levels/level_0/appearing_platforms.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -34,5 +34,11 @@
|
||||
"y": 789,
|
||||
"width": 108,
|
||||
"height": 211
|
||||
},
|
||||
{
|
||||
"x": 1110,
|
||||
"y": 942,
|
||||
"width": 366,
|
||||
"height": 57
|
||||
}
|
||||
]
|
||||
|
17
game/assets/levels/level_0/zones.json
Normal file
17
game/assets/levels/level_0/zones.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"appear": [
|
||||
{
|
||||
"x": 1110,
|
||||
"y": 942,
|
||||
"width": 366,
|
||||
"height": 57
|
||||
}
|
||||
],
|
||||
"disappear": [],
|
||||
"win": {
|
||||
"x": 3000,
|
||||
"y": 0,
|
||||
"width": 100,
|
||||
"height": 3000
|
||||
}
|
||||
}
|
@ -1,6 +1,12 @@
|
||||
use raylib::{RaylibHandle, RaylibThread};
|
||||
|
||||
use crate::{StaticGameData, utilities::{datastore::{load_texture_from_internal_data, ResourceLoadError}, world_paint_texture::WorldPaintTexture}};
|
||||
use crate::{
|
||||
utilities::{
|
||||
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
||||
world_paint_texture::WorldPaintTexture,
|
||||
},
|
||||
StaticGameData,
|
||||
};
|
||||
|
||||
use super::Level;
|
||||
|
||||
@ -23,8 +29,6 @@ pub fn load_all_levels(
|
||||
let mut levels = Vec::new();
|
||||
|
||||
for level_name in &level_names {
|
||||
|
||||
|
||||
levels.push(Level {
|
||||
name: level_name.to_string(),
|
||||
background_tex: WorldPaintTexture::new(load_texture_from_internal_data(
|
||||
@ -37,6 +41,11 @@ pub fn load_all_levels(
|
||||
thread,
|
||||
&format!("levels/{}/platforms.png", level_name),
|
||||
)?,
|
||||
appearing_platform_tex: load_texture_from_internal_data(
|
||||
raylib_handle,
|
||||
thread,
|
||||
&format!("levels/{}/appearing_platforms.png", level_name),
|
||||
)?,
|
||||
colliders: serde_json::from_str(
|
||||
&String::from_utf8(
|
||||
StaticGameData::get(&format!("levels/{}/colliders.json", level_name))
|
||||
@ -46,6 +55,15 @@ pub fn load_all_levels(
|
||||
)
|
||||
.unwrap(),
|
||||
)?,
|
||||
zones: serde_json::from_str(
|
||||
&String::from_utf8(
|
||||
StaticGameData::get(&format!("levels/{}/zones.json", level_name))
|
||||
.unwrap()
|
||||
.data
|
||||
.into(),
|
||||
)
|
||||
.unwrap(),
|
||||
)?,
|
||||
});
|
||||
}
|
||||
Ok(levels)
|
||||
|
@ -4,10 +4,19 @@ use crate::utilities::world_paint_texture::WorldPaintTexture;
|
||||
|
||||
pub mod loader;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct LevelZones {
|
||||
pub appear: Vec<Rectangle>,
|
||||
pub disappear: Vec<Rectangle>,
|
||||
pub win: Rectangle,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Level {
|
||||
pub name: String,
|
||||
pub background_tex: WorldPaintTexture,
|
||||
pub platform_tex: Texture2D,
|
||||
pub colliders: Vec<Rectangle>
|
||||
pub appearing_platform_tex: Texture2D,
|
||||
pub colliders: Vec<Rectangle>,
|
||||
pub zones: LevelZones,
|
||||
}
|
||||
|
@ -1,14 +1,18 @@
|
||||
use std::ops::Mul;
|
||||
use std::ops::{Div, Mul, Sub};
|
||||
|
||||
use super::InGameScreen;
|
||||
use crate::{
|
||||
character::render::render_character_in_camera_space,
|
||||
utilities::{non_ref_raylib::HackedRaylibHandle, render_layer::WorldSpaceRender},
|
||||
utilities::{
|
||||
math::interpolate_exp, non_ref_raylib::HackedRaylibHandle, render_layer::WorldSpaceRender,
|
||||
},
|
||||
GameConfig,
|
||||
};
|
||||
use raylib::prelude::*;
|
||||
use tracing::trace;
|
||||
|
||||
pub const WORLD_LEVEL_X_OFFSET: f32 = 200.0;
|
||||
pub const APPEAR_FADE_DISTANCE: f32 = 15.0;
|
||||
|
||||
impl WorldSpaceRender for InGameScreen {
|
||||
fn render_world_space(
|
||||
@ -33,6 +37,38 @@ 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.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);
|
||||
|
||||
// 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),
|
||||
);
|
||||
|
||||
#[cfg(all(debug_assertions, feature = "collider_debug"))]
|
||||
{
|
||||
for collider in &cur_level.colliders {
|
||||
|
Reference in New Issue
Block a user