Skip out-of-bounds whip frames
This commit is contained in:
parent
770793ea68
commit
1c54755039
2 changed files with 88 additions and 60 deletions
20
src/state.rs
20
src/state.rs
|
@ -172,10 +172,13 @@ impl State {
|
||||||
pub fn draw_whip(&self, ctx: &mut BTerm) {
|
pub fn draw_whip(&self, ctx: &mut BTerm) {
|
||||||
let positions = self.ecs.read_storage::<Position>();
|
let positions = self.ecs.read_storage::<Position>();
|
||||||
let wants_to_whips = self.ecs.read_storage::<WantsToWhip>();
|
let wants_to_whips = self.ecs.read_storage::<WantsToWhip>();
|
||||||
|
let map = self.ecs.read_resource::<Map>();
|
||||||
let mut rng = RandomNumberGenerator::new();
|
let mut rng = RandomNumberGenerator::new();
|
||||||
for (position, wants_to_whip) in (&positions, &wants_to_whips).join() {
|
for (position, wants_to_whip) in (&positions, &wants_to_whips).join() {
|
||||||
let color = RGB::named(vga::get_by_index(rng.range(1, 16)));
|
let color = RGB::named(vga::get_by_index(rng.range(1, 16)));
|
||||||
let frame_data = match wants_to_whip.frame {
|
let mut rendered_frame = wants_to_whip.frame;
|
||||||
|
let frame_data = loop {
|
||||||
|
let frame_data = match rendered_frame {
|
||||||
0 => Some((-1, -1, '\\')),
|
0 => Some((-1, -1, '\\')),
|
||||||
1 => Some((-1, 0, '─')),
|
1 => Some((-1, 0, '─')),
|
||||||
2 => Some((-1, 1, '/')),
|
2 => Some((-1, 1, '/')),
|
||||||
|
@ -186,6 +189,21 @@ impl State {
|
||||||
7 => Some((0, -1, '│')),
|
7 => Some((0, -1, '│')),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some(data) = frame_data {
|
||||||
|
let dest = Point {
|
||||||
|
x: position.x + data.0,
|
||||||
|
y: position.y + data.1,
|
||||||
|
};
|
||||||
|
if map.in_bounds(dest) {
|
||||||
|
break frame_data;
|
||||||
|
}
|
||||||
|
rendered_frame += 1;
|
||||||
|
if rendered_frame > 7 {
|
||||||
|
break None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
if let Some(data) = frame_data {
|
if let Some(data) = frame_data {
|
||||||
ctx.set(
|
ctx.set(
|
||||||
(position.x + MAP_X as i32) + data.0,
|
(position.x + MAP_X as i32) + data.0,
|
||||||
|
|
|
@ -43,6 +43,7 @@ impl<'a> System<'a> for WhipSystem {
|
||||||
stop_clock.0 = true;
|
stop_clock.0 = true;
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
if now - wants_to_whip.last_frame > Duration::from_secs_f32(0.1) {
|
if now - wants_to_whip.last_frame > Duration::from_secs_f32(0.1) {
|
||||||
|
let destination = loop {
|
||||||
let destination = match wants_to_whip.frame {
|
let destination = match wants_to_whip.frame {
|
||||||
0 => Some(Point {
|
0 => Some(Point {
|
||||||
x: position.x - 1,
|
x: position.x - 1,
|
||||||
|
@ -81,6 +82,16 @@ impl<'a> System<'a> for WhipSystem {
|
||||||
|
|
||||||
if let Some(dest) = destination {
|
if let Some(dest) = destination {
|
||||||
if map.in_bounds(dest) {
|
if map.in_bounds(dest) {
|
||||||
|
break destination;
|
||||||
|
}
|
||||||
|
wants_to_whip.frame += 1;
|
||||||
|
if wants_to_whip.frame > 7 {
|
||||||
|
break None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(dest) = destination {
|
||||||
if let Some(e) = map.get_tile_content(map.point2d_to_index(dest)) {
|
if let Some(e) = map.get_tile_content(map.point2d_to_index(dest)) {
|
||||||
if let Some(_monster) = monsters.get(e) {
|
if let Some(_monster) = monsters.get(e) {
|
||||||
let _ = entities.delete(e);
|
let _ = entities.delete(e);
|
||||||
|
@ -98,10 +109,9 @@ impl<'a> System<'a> for WhipSystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if wants_to_whip.frame < 7 {
|
if wants_to_whip.frame < 7 {
|
||||||
(*wants_to_whip).frame += 1;
|
wants_to_whip.frame += 1;
|
||||||
wants_to_whip.last_frame = now;
|
wants_to_whip.last_frame = now;
|
||||||
} else {
|
} else {
|
||||||
entities_to_remove.push(entity);
|
entities_to_remove.push(entity);
|
||||||
|
|
Loading…
Add table
Reference in a new issue