Implement speed and slow spells
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3129f1be1d
commit
ce05dcb194
9 changed files with 100 additions and 4 deletions
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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!(),
|
||||
|
|
5
src/resources/message_shown.rs
Normal file
5
src/resources/message_shown.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
#[derive(Debug, Default)]
|
||||
pub struct MessageShown {
|
||||
pub slow_time: bool,
|
||||
pub speed_time: bool,
|
||||
}
|
|
@ -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<SoundEffects>,
|
||||
pub sound_output: Option<SoundOutput>,
|
||||
pub flashing_message: Option<FlashingMessage>,
|
||||
pub message_shown: MessageShown,
|
||||
pub should_advance_level: bool,
|
||||
pub speed_time_ticks: u32,
|
||||
pub slow_time_ticks: u32,
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -91,10 +91,16 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for e in to_kill {
|
||||
let _ = world.despawn(e);
|
||||
|
|
12
src/systems/powerups.rs
Normal file
12
src/systems/powerups.rs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue