Bump mapgen.

This commit is contained in:
Nolan Darilek 2021-07-13 12:22:50 -05:00
parent 4749a09c5b
commit 1391856478
3 changed files with 25 additions and 29 deletions

View File

@ -29,7 +29,7 @@ coord_2d = "0.3"
crossbeam-channel = "0.5" crossbeam-channel = "0.5"
derive_more = "0.99" derive_more = "0.99"
gilrs = "0.8" gilrs = "0.8"
mapgen = "0.4" mapgen = { git = "https://github.com/ndarilek/mapgen.rs" }
maze_generator = "1" maze_generator = "1"
pathfinding = "2" pathfinding = "2"
rand = "0.8" rand = "0.8"

View File

@ -5,7 +5,7 @@ use bevy_input_actionmap::InputMap;
use bevy_rapier2d::prelude::*; use bevy_rapier2d::prelude::*;
use bevy_tts::Tts; use bevy_tts::Tts;
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
use mapgen::TileType; use mapgen::Tile;
use crate::{ use crate::{
core::{Coordinates, Player, PointLike}, core::{Coordinates, Player, PointLike},
@ -374,9 +374,11 @@ fn exploration_changed_announcement(
}, },
); );
if tokens.is_empty() { if tokens.is_empty() {
match map.tiles[idx] { let tile = map.tiles[idx];
TileType::Floor => "Floor".to_string(), if tile.is_blocked() {
TileType::Wall => "Wall".to_string(), "wall".to_string()
} else {
"floor".to_string()
} }
} else { } else {
tokens.join(": ") tokens.join(": ")

View File

@ -4,7 +4,7 @@ use bevy::prelude::*;
use bevy_rapier2d::prelude::*; use bevy_rapier2d::prelude::*;
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
pub use mapgen::Map; pub use mapgen::Map;
use mapgen::{geometry::Rect as MRect, MapFilter, TileType}; use mapgen::{geometry::Rect as MRect, MapFilter, Tile};
use maze_generator::{prelude::*, recursive_backtracking::RbGenerator}; use maze_generator::{prelude::*, recursive_backtracking::RbGenerator};
use rand::prelude::StdRng; use rand::prelude::StdRng;
@ -39,19 +39,13 @@ pub trait ITileType {
fn blocks_visibility(&self) -> bool; fn blocks_visibility(&self) -> bool;
} }
impl ITileType for TileType { impl ITileType for Tile {
fn blocks_motion(&self) -> bool { fn blocks_motion(&self) -> bool {
match self { self.is_blocked()
TileType::Wall => true,
TileType::Floor => false,
}
} }
fn blocks_visibility(&self) -> bool { fn blocks_visibility(&self) -> bool {
match self { self.is_blocked()
TileType::Wall => true,
TileType::Floor => false,
}
} }
} }
@ -153,22 +147,22 @@ impl MapFilter for GridBuilder {
if field.has_passage(&North) { if field.has_passage(&North) {
let x = x_offset + half_width; let x = x_offset + half_width;
let y = y_offset + self.room_height; let y = y_offset + self.room_height;
map.set_tile(x as usize, y as usize, TileType::Floor); map.set_tile(x as usize, y as usize, Tile::floor());
} }
if field.has_passage(&South) { if field.has_passage(&South) {
let x = x_offset + half_width; let x = x_offset + half_width;
let y = y_offset; let y = y_offset;
map.set_tile(x as usize, y as usize, TileType::Floor); map.set_tile(x as usize, y as usize, Tile::floor());
} }
if field.has_passage(&East) { if field.has_passage(&East) {
let x = x_offset + self.room_width; let x = x_offset + self.room_width;
let y = y_offset + half_height; let y = y_offset + half_height;
map.set_tile(x as usize, y as usize, TileType::Floor); map.set_tile(x as usize, y as usize, Tile::floor());
} }
if field.has_passage(&West) { if field.has_passage(&West) {
let x = x_offset; let x = x_offset;
let y = y_offset + half_height; let y = y_offset + half_height;
map.set_tile(x as usize, y as usize, TileType::Floor); map.set_tile(x as usize, y as usize, Tile::floor());
} }
} }
} }
@ -238,19 +232,19 @@ fn portal_spawner(
let mut spawn_portal = false; let mut spawn_portal = false;
if map.get_available_exits(x, y).len() > 2 { if map.get_available_exits(x, y).len() > 2 {
let idx = (x, y).to_index(map.width); let idx = (x, y).to_index(map.width);
if map.tiles[idx] == TileType::Floor if map.tiles[idx].is_walkable()
&& (x > 1 && map.tiles[idx - 1] == TileType::Floor) && (x > 1 && map.tiles[idx - 1].is_walkable())
&& (x < map.width - 2 && map.tiles[idx + 1] == TileType::Floor) && (x < map.width - 2 && map.tiles[idx + 1].is_walkable())
&& (y > 1 && map.tiles[idx - map.width] == TileType::Wall) && (y > 1 && map.tiles[idx - map.width].is_blocked())
&& (y < map.height - 2 && map.tiles[idx + map.width] == TileType::Wall) && (y < map.height - 2 && map.tiles[idx + map.width].is_blocked())
{ {
spawn_portal = true; spawn_portal = true;
} }
if map.tiles[idx] == TileType::Floor if map.tiles[idx].is_walkable()
&& (x > 1 && map.tiles[idx - 1] == TileType::Wall) && (x > 1 && map.tiles[idx - 1].is_blocked())
&& (x < map.width - 2 && map.tiles[idx + 1] == TileType::Wall) && (x < map.width - 2 && map.tiles[idx + 1].is_blocked())
&& (y > 1 && map.tiles[idx - map.width] == TileType::Floor) && (y > 1 && map.tiles[idx - map.width].is_walkable())
&& (y < map.height - 2 && map.tiles[idx + map.width] == TileType::Floor) && (y < map.height - 2 && map.tiles[idx + map.width].is_walkable())
{ {
spawn_portal = true; spawn_portal = true;
} }