Add and place TileType::Exit
This commit is contained in:
parent
feb02b5fba
commit
218f683651
17
src/main.rs
17
src/main.rs
@ -39,10 +39,13 @@ impl State {
|
||||
let mut ecs = World::default();
|
||||
let mut resources = Resources::default();
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
let map_builder = MapBuilder::new(&mut rng);
|
||||
let mut map_builder = MapBuilder::new(&mut rng);
|
||||
|
||||
spawn_player(&mut ecs, map_builder.player_start);
|
||||
spawn_amulet_of_yala(&mut ecs, map_builder.amulet_start);
|
||||
//spawn_amulet_of_yala(&mut ecs, map_builder.amulet_start);
|
||||
|
||||
let exit_idx = map_builder.map.point2d_to_index(map_builder.amulet_start);
|
||||
map_builder.map.tiles[exit_idx] = TileType::Exit;
|
||||
|
||||
map_builder
|
||||
.monster_spawns
|
||||
@ -67,13 +70,19 @@ impl State {
|
||||
self.ecs = World::default();
|
||||
self.resources = Resources::default();
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
let map_builder = MapBuilder::new(&mut rng);
|
||||
let mut map_builder = MapBuilder::new(&mut rng);
|
||||
|
||||
spawn_player(&mut self.ecs, map_builder.player_start);
|
||||
spawn_amulet_of_yala(&mut self.ecs, map_builder.amulet_start);
|
||||
//spawn_amulet_of_yala(&mut self.ecs, map_builder.amulet_start);
|
||||
|
||||
let exit_idx = map_builder.map.point2d_to_index(map_builder.amulet_start);
|
||||
map_builder.map.tiles[exit_idx] = TileType::Exit;
|
||||
|
||||
map_builder
|
||||
.monster_spawns
|
||||
.iter()
|
||||
.for_each(|pos| spawn_entity(&mut self.ecs, &mut rng, *pos));
|
||||
|
||||
self.resources.insert(map_builder.map);
|
||||
self.resources.insert(Camera::new(map_builder.player_start));
|
||||
self.resources.insert(TurnState::AwaitingInput);
|
||||
|
@ -6,6 +6,7 @@ const NUM_TILES: usize = (SCREEN_WIDTH * SCREEN_HEIGHT) as usize;
|
||||
pub enum TileType {
|
||||
Wall,
|
||||
Floor,
|
||||
Exit,
|
||||
}
|
||||
|
||||
pub struct Map {
|
||||
@ -30,7 +31,9 @@ impl Map {
|
||||
}
|
||||
|
||||
pub fn can_enter_tile(&self, point: Point) -> bool {
|
||||
self.in_bounds(point) && self.tiles[map_idx(point.x, point.y)] == TileType::Floor
|
||||
self.in_bounds(point)
|
||||
&& (self.tiles[map_idx(point.x, point.y)] == TileType::Floor
|
||||
|| self.tiles[map_idx(point.x, point.y)] == TileType::Exit)
|
||||
}
|
||||
|
||||
pub fn try_idx(&self, point: Point) -> Option<usize> {
|
||||
|
@ -15,6 +15,7 @@ impl MapTheme for DungeonTheme {
|
||||
match tile_type {
|
||||
TileType::Floor => to_cp437('.'),
|
||||
TileType::Wall => to_cp437('#'),
|
||||
TileType::Exit => to_cp437('>'),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -30,6 +31,7 @@ impl MapTheme for ForestTheme {
|
||||
match tile_type {
|
||||
TileType::Floor => to_cp437(';'),
|
||||
TileType::Wall => to_cp437('"'),
|
||||
TileType::Exit => to_cp437('>'),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ use crate::prelude::*;
|
||||
pub fn end_turn(ecs: &SubWorld, #[resource] turn_state: &mut TurnState) {
|
||||
let mut player_hp = <(&Health, &Point)>::query().filter(component::<Player>());
|
||||
let mut amulet = <&Point>::query().filter(component::<AmuletOfYala>());
|
||||
let amulet_pos = amulet.iter(ecs).next().unwrap();
|
||||
let amulet_default = Point::new(-1, -1);
|
||||
let amulet_pos = amulet.iter(ecs).next().unwrap_or(&amulet_default);
|
||||
let current_state = *turn_state;
|
||||
let mut new_state = match current_state {
|
||||
TurnState::AwaitingInput => return,
|
||||
|
Loading…
x
Reference in New Issue
Block a user