Add breath and boost hud

This commit is contained in:
Evan Pratten 2021-04-24 09:10:14 -04:00
parent bfef2269e8
commit fa9bc120e3
6 changed files with 59 additions and 21 deletions

View File

@ -17,25 +17,25 @@ pub fn render_hud(
let progress = (dist_from_start_to_end - dist_from_player_to_end) / dist_from_start_to_end; let progress = (dist_from_start_to_end - dist_from_player_to_end) / dist_from_start_to_end;
// Render the base of the progress bar // Render the base of the progress bar
let progress_bar_rect = Rectangle { // let progress_bar_rect = Rectangle {
x: 20.0, // x: 20.0,
y: (window_center.y * 2.0) - 20.0 - 40.0, // y: (window_center.y * 2.0) - 20.0 - 40.0,
width: (window_center.x * 2.0) - 40.0, // width: (window_center.x * 2.0) - 40.0,
height: 40.0, // height: 40.0,
}; // };
draw_handle.draw_rectangle_rec(progress_bar_rect, Color::BLUE); // draw_handle.draw_rectangle_rec(progress_bar_rect, Color::BLUE);
draw_handle.draw_rectangle_lines_ex(progress_bar_rect, 6, Color::WHITE); // draw_handle.draw_rectangle_lines_ex(progress_bar_rect, 6, Color::WHITE);
// Render the slider of the progress bar // // Render the slider of the progress bar
let progress_bar_slider = Rectangle { // let progress_bar_slider = Rectangle {
x: (((window_center.x * 2.0) - 40.0) * progress.abs().clamp(0.0, 1.0)) + 10.0, // x: (((window_center.x * 2.0) - 40.0) * progress.abs().clamp(0.0, 1.0)) + 10.0,
y: (window_center.y * 2.0) - 20.0 - 50.0, // y: (window_center.y * 2.0) - 20.0 - 50.0,
width: 40.0, // width: 40.0,
height: 60.0, // height: 60.0,
}; // };
draw_handle.draw_rectangle_rec(progress_bar_slider, Color::BLUE); // draw_handle.draw_rectangle_rec(progress_bar_slider, Color::BLUE);
//TODO: This causes a render bug // //TODO: This causes a render bug
draw_handle.draw_rectangle_lines_ex(progress_bar_slider, 6, Color::WHITE); // draw_handle.draw_rectangle_lines_ex(progress_bar_slider, 6, Color::WHITE);
// TODO: Breath bar // TODO: Breath bar
// TODO: Boost bar // TODO: Boost bar

View File

@ -47,7 +47,7 @@ impl Screen for InGameScreen {
game_core: &mut GameCore, game_core: &mut GameCore,
) -> Option<GameState> { ) -> Option<GameState> {
// Clear frame // Clear frame
draw_handle.clear_background(Color::RAYWHITE); draw_handle.clear_background(Color::BLUE);
// Handle the pause menu being opened // Handle the pause menu being opened
if draw_handle.is_key_pressed(KeyboardKey::KEY_ESCAPE) { if draw_handle.is_key_pressed(KeyboardKey::KEY_ESCAPE) {

View File

@ -1,6 +1,9 @@
use raylib::prelude::*; use raylib::prelude::*;
use crate::gamecore::GameCore; use crate::{
gamecore::GameCore,
pallette::{TRANSLUCENT_WHITE_128, TRANSLUCENT_WHITE_64},
};
const NORMAL_PLAYER_SPEED: i32 = 4; const NORMAL_PLAYER_SPEED: i32 = 4;
const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2; const BOOST_PLAYER_SPEED: i32 = NORMAL_PLAYER_SPEED * 2;
@ -59,6 +62,25 @@ pub fn render_player(context_2d: &mut RaylibMode2D<RaylibDrawHandle>, game_core:
// Convert the player direction to a rotation // Convert the player direction to a rotation
let player_rotation = Vector2::zero().angle_to(player.direction); let player_rotation = Vector2::zero().angle_to(player.direction);
// Render the player's boost ring
// This functions both as a breath meter, and as a boost meter
let boost_ring_max_radius = player.size.x + 5.0;
context_2d.draw_circle(
player.position.x as i32,
player.position.y as i32,
boost_ring_max_radius * player.boost_percent,
TRANSLUCENT_WHITE_64,
);
context_2d.draw_ring(
player.position,
boost_ring_max_radius - 2.0,
boost_ring_max_radius + 2.0,
0,
(360.0 * player.breath_percent) as i32,
0,
TRANSLUCENT_WHITE_128,
);
// TODO: tmp rect // TODO: tmp rect
context_2d.draw_rectangle_pro( context_2d.draw_rectangle_pro(
Rectangle { Rectangle {

View File

@ -4,6 +4,7 @@ mod logic;
mod resources; mod resources;
mod player; mod player;
mod world; mod world;
mod pallette;
use gamecore::{GameCore, GameState}; use gamecore::{GameCore, GameState};
use lib::{utils::profiler::GameProfiler, wrappers::audio::player::AudioPlayer}; use lib::{utils::profiler::GameProfiler, wrappers::audio::player::AudioPlayer};

View File

@ -0,0 +1,15 @@
use raylib::color::Color;
pub const TRANSLUCENT_WHITE_128: Color = Color {
r: 255,
g: 255,
b: 255,
a: 128,
};
pub const TRANSLUCENT_WHITE_64: Color = Color {
r: 255,
g: 255,
b: 255,
a: 64,
};

View File

@ -20,7 +20,7 @@ impl Player {
x: 11.0 * 4.0, x: 11.0 * 4.0,
y: 21.0 * 4.0 y: 21.0 * 4.0
}, },
breath_percent: 1.0, breath_percent: 0.5,
..Default::default() ..Default::default()
} }