diff --git a/src/graphics/sidebar.rs b/src/graphics/sidebar.rs index 3861aee..abb7634 100644 --- a/src/graphics/sidebar.rs +++ b/src/graphics/sidebar.rs @@ -103,12 +103,22 @@ pub fn draw(resources: &Resources, bterm: &mut BTerm) { &format!("{}", bterm.fps), ); + let mut debug_string = format!("{}", resources.clock.ticks); + + if resources.speed_time_ticks > 0 { + debug_string += " SPEED" + } + + if resources.slow_time_ticks > 0 { + debug_string += " SLOW" + } + bterm.print_color( 0, 0, RGB::named(vga::YELLOW_BRIGHT), RGB::named(vga::BLACK), - &format!("{}", resources.clock.ticks), + &debug_string, ); } } diff --git a/src/input/player.rs b/src/input/player.rs index f845062..e8785e4 100644 --- a/src/input/player.rs +++ b/src/input/player.rs @@ -106,7 +106,24 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool { true } crate::tile_data::TileType::Chest => todo!(), - crate::tile_data::TileType::SlowTime => todo!(), + crate::tile_data::TileType::SlowTime => { + if let (Some(sound_effects), Some(sound_output)) = + (&mut resources.sound_effects, &mut resources.sound_output) + { + sound_output.play_sound(sound_effects.slow_time.clone()); + } + + if !resources.message_shown.slow_time { + resources.flashing_message = Some(FlashingMessage::from( + "You activated a Slow Creature spell.", + )); + resources.message_shown.slow_time = true; + } + + resources.slow_time_ticks = 100; + resources.map.set_tile_at(point, TileType::Floor); + true + } crate::tile_data::TileType::Gem => { if let (Some(sound_effects), Some(sound_output)) = (&mut resources.sound_effects, &mut resources.sound_output) @@ -132,7 +149,24 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool { } crate::tile_data::TileType::Key => todo!(), crate::tile_data::TileType::Door => todo!(), - crate::tile_data::TileType::SpeedTime => todo!(), + crate::tile_data::TileType::SpeedTime => { + if let (Some(sound_effects), Some(sound_output)) = + (&mut resources.sound_effects, &mut resources.sound_output) + { + sound_output.play_sound(sound_effects.speed_time.clone()); + } + + if !resources.message_shown.speed_time { + resources.flashing_message = Some(FlashingMessage::from( + "You activated a Speed Creature spell.", + )); + resources.message_shown.speed_time = true; + } + + resources.speed_time_ticks = 80; + resources.map.set_tile_at(point, TileType::Floor); + true + } crate::tile_data::TileType::Trap => todo!(), crate::tile_data::TileType::River => todo!(), crate::tile_data::TileType::Power => todo!(), diff --git a/src/resources/message_shown.rs b/src/resources/message_shown.rs new file mode 100644 index 0000000..2bd036f --- /dev/null +++ b/src/resources/message_shown.rs @@ -0,0 +1,5 @@ +#[derive(Debug, Default)] +pub struct MessageShown { + pub slow_time: bool, + pub speed_time: bool, +} diff --git a/src/resources/mod.rs b/src/resources/mod.rs index d78d9e9..819e479 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -2,6 +2,7 @@ pub mod clock; pub mod difficulty; pub mod flashing_message; pub mod map; +pub mod message_shown; pub mod sound_effects; pub mod sound_output; pub mod stats; @@ -11,6 +12,7 @@ pub use clock::{Clock, StopClock}; pub use difficulty::Difficulty; pub use flashing_message::FlashingMessage; pub use map::Map; +use message_shown::MessageShown; pub use sound_effects::SoundEffects; pub use sound_output::SoundOutput; pub use stats::Stats; @@ -27,5 +29,8 @@ pub struct Resources { pub sound_effects: Option, pub sound_output: Option, pub flashing_message: Option, + pub message_shown: MessageShown, pub should_advance_level: bool, + pub speed_time_ticks: u32, + pub slow_time_ticks: u32, } diff --git a/src/resources/sound_effects.rs b/src/resources/sound_effects.rs index f0b7267..bcbae52 100644 --- a/src/resources/sound_effects.rs +++ b/src/resources/sound_effects.rs @@ -39,6 +39,8 @@ pub struct SoundEffects { pub medium_hit: SoundSamples, pub fast_hit: SoundSamples, pub pause: SoundSamples, + pub speed_time: SoundSamples, + pub slow_time: SoundSamples, rng: RandomNumberGenerator, } @@ -167,6 +169,23 @@ impl SoundEffects { sounds }, }), + speed_time: sound_output.render_sound_effect(&SoundEffect { + sounds: (1..=7) + .map(|x| Sound { + sound_type: SoundType::Tone(x * 50 + 300), + duration: Duration::from_millis(x as u64 * 10 + 40), + }) + .collect(), + }), + slow_time: sound_output.render_sound_effect(&SoundEffect { + sounds: (1..=7) + .rev() + .map(|x| Sound { + sound_type: SoundType::Tone(x * 50 + 300), + duration: Duration::from_millis(x as u64 * 10 + 40), + }) + .collect(), + }), rng: RandomNumberGenerator::new(), } } diff --git a/src/state.rs b/src/state.rs index 056d768..ea9186f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -76,7 +76,10 @@ impl State { "Press any key to begin this level.", Some(FlashingMessageIntent::Start), )), + message_shown: Default::default(), should_advance_level: false, + speed_time_ticks: 0, + slow_time_ticks: 0, }; State { world, resources } diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 6c7c96a..8640be6 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -1,4 +1,5 @@ pub mod monster_ai; +pub mod powerups; pub mod time; pub mod whip; @@ -7,6 +8,7 @@ use hecs::World; use crate::resources::Resources; pub fn run(world: &mut World, resources: &mut Resources) { + powerups::run(resources); whip::run(world, resources); monster_ai::run(world, resources); time::run(resources); diff --git a/src/systems/monster_ai.rs b/src/systems/monster_ai.rs index 5a21472..cbd4aea 100644 --- a/src/systems/monster_ai.rs +++ b/src/systems/monster_ai.rs @@ -91,7 +91,13 @@ pub fn run(world: &mut World, resources: &mut Resources) { } } - monster.ticks_until_move = ticks_for_kind(monster.kind); + if resources.speed_time_ticks > 0 { + monster.ticks_until_move = 3; + } else if resources.slow_time_ticks > 0 { + monster.ticks_until_move = ticks_for_kind(monster.kind) * 5; + } else { + monster.ticks_until_move = ticks_for_kind(monster.kind); + } } } } diff --git a/src/systems/powerups.rs b/src/systems/powerups.rs new file mode 100644 index 0000000..f5ba42e --- /dev/null +++ b/src/systems/powerups.rs @@ -0,0 +1,12 @@ +use crate::resources::Resources; + +pub fn run(resources: &mut Resources) { + if resources.clock.has_ticked { + if let Some(t) = resources.speed_time_ticks.checked_sub(1) { + resources.speed_time_ticks = t; + } + if let Some(t) = resources.slow_time_ticks.checked_sub(1) { + resources.slow_time_ticks = t; + } + } +}