Merge pull request #22 from Ewpratten/darkness

darkness is taking over
This commit is contained in:
Evan Pratten 2021-04-24 21:16:14 -04:00 committed by GitHub
commit dcbe3eab2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 3 deletions

View File

@ -1,7 +1,7 @@
{ {
"end_position": { "end_position": {
"x": 10000.0, "x": 350.0,
"y": 10000.0 "y": 2100.0
}, },
"player_spawn": { "player_spawn": {
"x": 220.0, "x": 220.0,

View File

@ -25,7 +25,17 @@ impl StunGun {
pub struct AirBag; pub struct AirBag;
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct Flashlight; pub struct Flashlight {
pub radius: f32
}
impl Flashlight {
pub fn lvl1() -> Self {
Self {
radius: 120.0
}
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct Flippers { pub struct Flippers {

View File

@ -87,6 +87,46 @@ impl InGameScreen {
context_2d.draw_rectangle_lines_ex(collider, 1, Color::RED); context_2d.draw_rectangle_lines_ex(collider, 1, Color::RED);
} }
} }
fn render_darkness(&mut self, draw_handle: &mut RaylibDrawHandle, game_core: &mut GameCore) {
// Calculate the min view radius based on the current flashlight
let mut min_radius = 0.0;
if game_core.player.inventory.flashlight.is_some() {
min_radius = game_core
.player
.inventory
.flashlight
.as_ref()
.unwrap()
.radius;
}
// Get the window center
let win_height = draw_handle.get_screen_height();
let win_width = draw_handle.get_screen_width();
let window_center = Vector2 {
x: (win_width as f32 / 2.0),
y: (win_height as f32 / 2.0),
};
// Calculate the occusion radius based on depth
let radius = (win_width as f32
* (1.0
- (game_core.player.calculate_depth_percent(&game_core.world) * 1.3)
.clamp(0.0, 1.0)))
.max(min_radius);
// Render the overlay
draw_handle.draw_ring(
window_center,
radius,
win_width as f32,
0,
360,
128,
Color::BLACK,
);
}
} }
impl Screen for InGameScreen { impl Screen for InGameScreen {
@ -156,6 +196,9 @@ impl Screen for InGameScreen {
.render(&mut context_2d, &mut game_core.resources, dt); .render(&mut context_2d, &mut game_core.resources, dt);
} }
// Render the darkness layer
self.render_darkness(draw_handle, game_core);
// Render the hud // Render the hud
hud::render_hud(draw_handle, game_core, window_center); hud::render_hud(draw_handle, game_core, window_center);

View File

@ -25,6 +25,7 @@ impl PlayerInventory {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
stun_gun: Some(StunGun::lvl1()), //TMP stun_gun: Some(StunGun::lvl1()), //TMP
flashlight: Some(Flashlight::lvl1()), //TMP
..Default::default() ..Default::default()
} }
} }