kroz-rs/src/graphics/whip.rs
Alex Page d9606e8b87
All checks were successful
continuous-integration/drone/push Build is passing
Switch from specs to hecs
2022-02-03 00:07:12 -05:00

51 lines
1.7 KiB
Rust

use bracket_lib::prelude::*;
use hecs::World;
use crate::{components::*, constants::*, resources::*};
use super::{vga_color as vga, vga_color::get_by_index};
pub fn draw(world: &World, resources: &Resources, bterm: &mut BTerm) {
let mut rng = RandomNumberGenerator::new();
for (_, (position, wants_to_whip)) in &mut world.query::<(&Position, &WantsToWhip)>() {
let color = RGB::named(get_by_index(rng.range(1, 16)));
let mut rendered_frame = wants_to_whip.frame;
let frame_data = loop {
let frame_data = match rendered_frame {
0 => Some((-1, -1, '\\')),
1 => Some((-1, 0, '─')),
2 => Some((-1, 1, '/')),
3 => Some((0, 1, '│')),
4 => Some((1, 1, '\\')),
5 => Some((1, 0, '─')),
6 => Some((1, -1, '/')),
7 => Some((0, -1, '│')),
_ => None,
};
if let Some(data) = frame_data {
let dest = Point {
x: position.x + data.0,
y: position.y + data.1,
};
if resources.map.in_bounds(dest) {
break frame_data;
}
rendered_frame += 1;
if rendered_frame > 7 {
break None;
}
}
};
if let Some(data) = frame_data {
bterm.set(
(position.x + MAP_X as i32) + data.0,
(position.y + MAP_Y as i32) + data.1,
color,
RGB::named(vga::BLACK),
to_cp437(data.2),
);
};
}
}