Add ability to advance and track level

This commit is contained in:
Daniel Lynn 2021-07-10 21:09:44 -05:00
parent 218f683651
commit f4e718ad7f
5 changed files with 13 additions and 3 deletions

View File

@ -8,7 +8,9 @@ pub struct Render {
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Player;
pub struct Player {
pub map_level: u32,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Enemy;

View File

@ -138,6 +138,8 @@ impl State {
self.reset_game_state();
}
}
fn advance_level(&mut self) {}
}
impl GameState for State {
@ -167,6 +169,7 @@ impl GameState for State {
.execute(&mut self.ecs, &mut self.resources),
TurnState::GameOver => self.game_over(ctx),
TurnState::Victory => self.victory(ctx),
TurnState::NextLevel => self.advance_level(),
}
render_draw_buffer(ctx).expect("Render error");

View File

@ -2,7 +2,7 @@ use crate::prelude::*;
pub fn spawn_player(ecs: &mut World, pos: Point) {
ecs.push((
Player,
Player { map_level: 0 },
pos,
Render {
color: ColorPair::new(WHITE, BLACK),

View File

@ -5,7 +5,7 @@ use crate::prelude::*;
#[read_component(Point)]
#[read_component(Player)]
#[read_component(AmuletOfYala)]
pub fn end_turn(ecs: &SubWorld, #[resource] turn_state: &mut TurnState) {
pub fn end_turn(ecs: &SubWorld, #[resource] turn_state: &mut TurnState, #[resource] map: &Map) {
let mut player_hp = <(&Health, &Point)>::query().filter(component::<Player>());
let mut amulet = <&Point>::query().filter(component::<AmuletOfYala>());
let amulet_default = Point::new(-1, -1);
@ -25,6 +25,10 @@ pub fn end_turn(ecs: &SubWorld, #[resource] turn_state: &mut TurnState) {
if pos == amulet_pos {
new_state = TurnState::Victory;
}
let idx = map.point2d_to_index(*pos);
if map.tiles[idx] == TileType::Exit {
new_state = TurnState::NextLevel;
}
});
*turn_state = new_state;

View File

@ -5,4 +5,5 @@ pub enum TurnState {
MonsterTurn,
GameOver,
Victory,
NextLevel,
}