survivor

graphical action game for the linux terminal
git clone https://git.ce9e.org/survivor.git

commit
77f22affadbd2d3802a25578a984777f7cc9b1ab
parent
a3e7d6be3cf7eebf9fd0ebf5aef1c8279c8fd623
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-02-19 13:45
inline bar

Diffstat

M src/main.rs 48 ++++++++++++++++++++++--------------------------

1 files changed, 22 insertions, 26 deletions


diff --git a/src/main.rs b/src/main.rs

@@ -20,6 +20,11 @@ const PERK_HEAL: usize = 4;
   20    20 const PERK_RECOVER: usize = 5;
   21    21 const PERK_ATTRACT: usize = 6;
   22    22 
   -1    23 const BLACK: [u8; 3] = [0x00, 0x00, 0x00];
   -1    24 const RED: [u8; 3] = [0xff, 0x00, 0x00];
   -1    25 const GREEN: [u8; 3] = [0x00, 0xff, 0x00];
   -1    26 const BLUE: [u8; 3] = [0x00, 0x00, 0xff];
   -1    27 
   23    28 static RUNNING: AtomicBool = AtomicBool::new(true);
   24    29 
   25    30 #[derive(PartialEq)]
@@ -103,18 +108,6 @@ fn circle(screen: &mut term::Screen, cx: f32, cy: f32, r: f32, color: [u8; 3]) {
  103   108     }
  104   109 }
  105   110 
  106    -1 fn bar(screen: &mut term::Screen, y: usize, value: f32, color: [u8; 3]) {
  107    -1     let black = [0x00, 0x00, 0x00];
  108    -1 
  109    -1     for x in 0..screen.width {
  110    -1         let fx = x as f32 / screen.width as f32;
  111    -1         let c = if fx <= value { color } else { black };
  112    -1         for dy in 0..3 {
  113    -1             screen.set(x, y + dy, c);
  114    -1         }
  115    -1     }
  116    -1 }
  117    -1 
  118   111 struct Diamond {
  119   112     pub x: f32,
  120   113     pub y: f32,
@@ -350,7 +343,7 @@ fn main() {
  350   343             width / 2.0,
  351   344             height / 2.0,
  352   345             player.damage_radius,
  353    -1             [0x00, 0xff, 0x00],
   -1   346             GREEN,
  354   347         );
  355   348 
  356   349         for diamond in diamonds.iter() {
@@ -387,19 +380,22 @@ fn main() {
  387   380             );
  388   381         }
  389   382 
  390    -1         bar(
  391    -1             &mut screen,
  392    -1             0,
  393    -1             (player.xp - player.last_level) as f32 / (player.next_level - player.last_level) as f32,
  394    -1             [0x00, 0x00, 0xff],
  395    -1         );
  396    -1         let h = screen.height;
  397    -1         bar(
  398    -1             &mut screen,
  399    -1             h - 3,
  400    -1             player.health / player.health_max,
  401    -1             [0xff, 0x00, 0x00],
  402    -1         );
   -1   383         let xp_bar = (screen.width as f32 * (player.xp - player.last_level) as f32
   -1   384             / (player.next_level - player.last_level) as f32) as usize;
   -1   385         for x in 0..screen.width {
   -1   386             let c = if x <= xp_bar { BLUE } else { BLACK };
   -1   387             for y in 0..3 {
   -1   388                 screen.set(x, y, c);
   -1   389             }
   -1   390         }
   -1   391 
   -1   392         let health_bar = (screen.width as f32 * player.health / player.health_max) as usize;
   -1   393         for x in 0..screen.width {
   -1   394             let c = if x <= health_bar { RED } else { BLACK };
   -1   395             for y in (screen.height - 3)..screen.height {
   -1   396                 screen.set(x, y, c);
   -1   397             }
   -1   398         }
  403   399 
  404   400         screen.render();
  405   401