Add changing levels when touching stairs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Alex Page 2022-02-03 20:16:33 -05:00
parent f38a80b0c7
commit fe7eef7770
4 changed files with 24 additions and 4 deletions

View file

@ -93,7 +93,7 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
true true
} }
crate::tile_data::TileType::Stairs => { crate::tile_data::TileType::Stairs => {
// TODO: Go to next level resources.should_advance_level = true;
true true
} }
crate::tile_data::TileType::Chest => todo!(), crate::tile_data::TileType::Chest => todo!(),

View file

@ -57,7 +57,8 @@ fn main() -> BError {
sound_effects, sound_effects,
sound_output, sound_output,
selected_difficulty: Some(selected_difficulty), 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) // let descent_sounds: Vec<Sound> = (20..100)

View file

@ -27,4 +27,5 @@ pub struct Resources {
pub sound_effects: SoundEffects, pub sound_effects: SoundEffects,
pub sound_output: SoundOutput, pub sound_output: SoundOutput,
pub flashing_message: Option<FlashingMessage>, pub flashing_message: Option<FlashingMessage>,
pub should_advance_level: bool,
} }

View file

@ -1,5 +1,6 @@
use crate::resources::Resources; use crate::resources::flashing_message::FlashingMessage;
use crate::{graphics, input, systems}; use crate::resources::{Map, Resources};
use crate::{graphics, input, levels, systems};
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
use hecs::World; use hecs::World;
@ -13,6 +14,10 @@ impl GameState for State {
input::handle(&mut self.world, &mut self.resources, bterm); input::handle(&mut self.world, &mut self.resources, bterm);
systems::run(&mut self.world, &mut self.resources); systems::run(&mut self.world, &mut self.resources);
graphics::draw(&self.world, &mut self.resources, bterm); 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 { pub fn new(world: World, resources: Resources) -> Self {
State { world, resources } 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;
}
} }