Skip out-of-bounds whip frames
This commit is contained in:
parent
770793ea68
commit
1c54755039
2 changed files with 88 additions and 60 deletions
38
src/state.rs
38
src/state.rs
|
@ -172,19 +172,37 @@ 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;
|
||||||
0 => Some((-1, -1, '\\')),
|
let frame_data = loop {
|
||||||
1 => Some((-1, 0, '─')),
|
let frame_data = match rendered_frame {
|
||||||
2 => Some((-1, 1, '/')),
|
0 => Some((-1, -1, '\\')),
|
||||||
3 => Some((0, 1, '│')),
|
1 => Some((-1, 0, '─')),
|
||||||
4 => Some((1, 1, '\\')),
|
2 => Some((-1, 1, '/')),
|
||||||
5 => Some((1, 0, '─')),
|
3 => Some((0, 1, '│')),
|
||||||
6 => Some((1, -1, '/')),
|
4 => Some((1, 1, '\\')),
|
||||||
7 => Some((0, -1, '│')),
|
5 => Some((1, 0, '─')),
|
||||||
_ => None,
|
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 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(
|
||||||
|
|
|
@ -43,65 +43,75 @@ 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 = match wants_to_whip.frame {
|
let destination = loop {
|
||||||
0 => Some(Point {
|
let destination = match wants_to_whip.frame {
|
||||||
x: position.x - 1,
|
0 => Some(Point {
|
||||||
y: position.y - 1,
|
x: position.x - 1,
|
||||||
}),
|
y: position.y - 1,
|
||||||
1 => Some(Point {
|
}),
|
||||||
x: position.x - 1,
|
1 => Some(Point {
|
||||||
y: position.y,
|
x: position.x - 1,
|
||||||
}),
|
y: position.y,
|
||||||
2 => Some(Point {
|
}),
|
||||||
x: position.x - 1,
|
2 => Some(Point {
|
||||||
y: position.y + 1,
|
x: position.x - 1,
|
||||||
}),
|
y: position.y + 1,
|
||||||
3 => Some(Point {
|
}),
|
||||||
x: position.x,
|
3 => Some(Point {
|
||||||
y: position.y + 1,
|
x: position.x,
|
||||||
}),
|
y: position.y + 1,
|
||||||
4 => Some(Point {
|
}),
|
||||||
x: position.x + 1,
|
4 => Some(Point {
|
||||||
y: position.y + 1,
|
x: position.x + 1,
|
||||||
}),
|
y: position.y + 1,
|
||||||
5 => Some(Point {
|
}),
|
||||||
x: position.x + 1,
|
5 => Some(Point {
|
||||||
y: position.y,
|
x: position.x + 1,
|
||||||
}),
|
y: position.y,
|
||||||
6 => Some(Point {
|
}),
|
||||||
x: position.x + 1,
|
6 => Some(Point {
|
||||||
y: position.y - 1,
|
x: position.x + 1,
|
||||||
}),
|
y: position.y - 1,
|
||||||
7 => Some(Point {
|
}),
|
||||||
x: position.x,
|
7 => Some(Point {
|
||||||
y: position.y - 1,
|
x: position.x,
|
||||||
}),
|
y: position.y - 1,
|
||||||
_ => None,
|
}),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(dest) = destination {
|
||||||
|
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(dest) = destination {
|
||||||
if map.in_bounds(dest) {
|
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);
|
if let Some(sound) = &mut wants_to_whip.sound {
|
||||||
if let Some(sound) = &mut wants_to_whip.sound {
|
sound.control::<oddio::Stop<_>, _>().stop();
|
||||||
sound.control::<oddio::Stop<_>, _>().stop();
|
}
|
||||||
}
|
if wants_to_whip.frame == 7 {
|
||||||
if wants_to_whip.frame == 7 {
|
wants_to_whip.sound = None;
|
||||||
wants_to_whip.sound = None;
|
sound_output.play_sound(sound_effects.whipping_hit_end.clone());
|
||||||
sound_output.play_sound(sound_effects.whipping_hit_end.clone());
|
} else {
|
||||||
} else {
|
wants_to_whip.sound = Some(
|
||||||
wants_to_whip.sound = Some(
|
sound_output.play_sound(sound_effects.whipping_hit.clone()),
|
||||||
sound_output.play_sound(sound_effects.whipping_hit.clone()),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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