Add changing levels when touching stairs
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
f38a80b0c7
commit
fe7eef7770
4 changed files with 24 additions and 4 deletions
|
@ -93,7 +93,7 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
|||
true
|
||||
}
|
||||
crate::tile_data::TileType::Stairs => {
|
||||
// TODO: Go to next level
|
||||
resources.should_advance_level = true;
|
||||
true
|
||||
}
|
||||
crate::tile_data::TileType::Chest => todo!(),
|
||||
|
|
|
@ -57,7 +57,8 @@ fn main() -> BError {
|
|||
sound_effects,
|
||||
sound_output,
|
||||
selected_difficulty: Some(selected_difficulty),
|
||||
flashing_message: None,
|
||||
flashing_message: Some(FlashingMessage::from("Press any key to begin this level.")),
|
||||
should_advance_level: false,
|
||||
};
|
||||
|
||||
// let descent_sounds: Vec<Sound> = (20..100)
|
||||
|
|
|
@ -27,4 +27,5 @@ pub struct Resources {
|
|||
pub sound_effects: SoundEffects,
|
||||
pub sound_output: SoundOutput,
|
||||
pub flashing_message: Option<FlashingMessage>,
|
||||
pub should_advance_level: bool,
|
||||
}
|
||||
|
|
22
src/state.rs
22
src/state.rs
|
@ -1,5 +1,6 @@
|
|||
use crate::resources::Resources;
|
||||
use crate::{graphics, input, systems};
|
||||
use crate::resources::flashing_message::FlashingMessage;
|
||||
use crate::resources::{Map, Resources};
|
||||
use crate::{graphics, input, levels, systems};
|
||||
use bracket_lib::prelude::*;
|
||||
use hecs::World;
|
||||
|
||||
|
@ -13,6 +14,10 @@ impl GameState for State {
|
|||
input::handle(&mut self.world, &mut self.resources, bterm);
|
||||
systems::run(&mut self.world, &mut self.resources);
|
||||
graphics::draw(&self.world, &mut self.resources, bterm);
|
||||
|
||||
if self.resources.should_advance_level {
|
||||
self.next_level();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,4 +25,17 @@ impl State {
|
|||
pub fn new(world: World, resources: Resources) -> Self {
|
||||
State { world, resources }
|
||||
}
|
||||
|
||||
fn next_level(&mut self) {
|
||||
self.resources.level_number += 1;
|
||||
|
||||
self.world.clear();
|
||||
self.resources.map = Map::from(levels::get_level(self.resources.level_number));
|
||||
self.resources.map.spawn_entities(&mut self.world);
|
||||
|
||||
self.resources.flashing_message =
|
||||
Some(FlashingMessage::from("Press any key to begin this level."));
|
||||
|
||||
self.resources.should_advance_level = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue