Implement whipping blocks and trees
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Alex Page 2022-02-10 17:40:00 -05:00
parent 36d109654c
commit 38d3333635
3 changed files with 66 additions and 27 deletions

View file

@ -7,6 +7,7 @@ use hecs::{Entity, World};
use crate::{
components::{monster::damage_for_kind, Monster, Position, WantsToWhip},
resources::Resources,
tile_data::TileType,
};
pub fn run(world: &mut World, resources: &mut Resources) {
@ -73,23 +74,15 @@ pub fn run(world: &mut World, resources: &mut Resources) {
resources.stats.add_score(damage_for_kind(monster.kind));
to_kill.push(e);
resources.map.clear_tile_content_at(dest);
if let Some(sound) = &mut wants_to_whip.sound {
sound.control::<oddio::Stop<_>, _>().stop();
}
if wants_to_whip.frame == 7 {
wants_to_whip.sound = None;
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.whipping_hit_end.clone());
}
} else if let (Some(sound_effects), Some(sound_output)) =
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
wants_to_whip.sound =
Some(sound_output.play_sound(sound_effects.whipping_hit.clone()));
sound_output.play_sound(sound_effects.whipping_hit_enemy.clone());
}
switch_to_hit_sound(resources, wants_to_whip);
}
} else {
hit_tile(resources, wants_to_whip, dest);
}
}
@ -115,3 +108,36 @@ pub fn run(world: &mut World, resources: &mut Resources) {
let _ = world.remove_one::<WantsToWhip>(e);
}
}
fn hit_tile(resources: &mut Resources, wants_to_whip: &mut WantsToWhip, location: Point) {
let tile = resources.map.get_tile_at(location);
match tile {
TileType::Block | TileType::Tree => {
let mut rng = RandomNumberGenerator::new();
if (rng.range(0, 7) as u32) < resources.stats.whip_power {
resources.map.set_tile_at(location, TileType::Floor);
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.whipping_hit_block.clone());
}
switch_to_hit_sound(resources, wants_to_whip);
}
}
TileType::Forest => todo!(),
_ => (),
}
}
fn switch_to_hit_sound(resources: &mut Resources, wants_to_whip: &mut WantsToWhip) {
if let Some(sound) = &mut wants_to_whip.sound {
sound.control::<oddio::Stop<_>, _>().stop();
}
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
wants_to_whip.sound = Some(sound_output.play_sound(sound_effects.whipping_hit.clone()));
}
}