summaryrefslogtreecommitdiff
path: root/src/map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.rs')
-rw-r--r--src/map.rs37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/map.rs b/src/map.rs
index ab436d1..fe51242 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -1,5 +1,6 @@
use ggez::filesystem::File;
use ggez::graphics::spritebatch::SpriteBatch;
+use ggez::nalgebra::Point2;
use xml::reader::XmlEvent::Characters;
use crate::constants;
@@ -7,10 +8,12 @@ use crate::layer::Layer;
use crate::tileset::Tileset;
use crate::xmlelements::XMLElements;
+#[derive(Clone)]
pub struct Map {
- pub width: usize,
- pub height: usize,
- pub layers: Vec<Layer>,
+ width: usize,
+ height: usize,
+ layers: Vec<Layer>,
+ spawns: Vec<(String, Point2<f32>)>,
}
impl Map {
@@ -28,7 +31,7 @@ impl Map {
.parse()
.unwrap();
- let layers = elements
+ let layers: Vec<Layer> = elements
.events
.iter()
.filter_map(|e| {
@@ -40,13 +43,35 @@ impl Map {
})
.collect();
+ let spawns = Map::get_spawn_points(&layers, tileset.get_spawn_tiles());
+
Map {
layers,
width,
height,
+ spawns,
}
}
+ fn get_spawn_points(
+ layers: &[Layer],
+ spawn_tiles: Vec<(String, usize)>,
+ ) -> Vec<(String, Point2<f32>)> {
+ let mut spawn_points = Vec::new();
+
+ for layer in layers.iter() {
+ for tile in layer.tiles.iter() {
+ for spawn_tile in spawn_tiles.iter() {
+ if spawn_tile.1 == tile.id {
+ spawn_points.push((spawn_tile.0.clone(), tile.destination));
+ }
+ }
+ }
+ }
+
+ spawn_points
+ }
+
pub fn draw(&self, spritebatch: &mut SpriteBatch) {
for layer in self.layers.iter() {
layer.draw(spritebatch);
@@ -59,6 +84,10 @@ impl Map {
}
}
+ pub fn get_spawns(&self) -> Vec<(String, Point2<f32>)> {
+ self.spawns.clone()
+ }
+
pub fn get_dimensions(&self) -> (f32, f32) {
(
(constants::TILE_WIDTH * constants::TILE_SCALE) * self.width as f32,