From ffd92b2d0ded6aea2f505dfce422252c378b7548 Mon Sep 17 00:00:00 2001 From: Raymond Hogenson Date: Sat, 18 Aug 2018 15:42:11 -0400 Subject: Add a health bar It's sweet now --- src/main.rs | 2 ++ src/state.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 603aa5c..ca1bdd8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,8 @@ fn frame(canvas: &mut sdl2::render::WindowCanvas, state: &mut state::State, even for bullet in state.bullets.iter() { bullet.draw(canvas, &textures.ebullet); } + canvas.set_draw_color(sdl2::pixels::Color::RGB(255, 0, 0)); + canvas.draw_rect(sdl2::rect::Rect::new(0, 0, (state.enemies[0].health as f64 / state::STARTING_HEALTH as f64 * constants::X_DIM as f64).round() as u32, 20)).unwrap(); state.count += 1; Result::Nothing } diff --git a/src/state.rs b/src/state.rs index d309862..5f622b5 100644 --- a/src/state.rs +++ b/src/state.rs @@ -28,7 +28,7 @@ pub struct Enemy { pub health: i64, } -const STARTING_HEALTH: i64 = 100; +pub const STARTING_HEALTH: i64 = 100; impl EBullet { pub fn new(x: i32, d_x: f64, y: i32, d_y: f64) -> EBullet { -- cgit v1.3.1