summaryrefslogtreecommitdiff
path: root/src/map.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-07-05 08:59:22 -0500
committertom barrett <spalf0@gmail.com>2019-07-05 08:59:22 -0500
commitbfdaef7850b6ac17bb88f1b314236fb5014aac8e (patch)
tree748ceca98138b5783655ec181ea905a25a690934 /src/map.rs
parent6589e5e3df63d5abf85313c4d21097432257f453 (diff)
now a cells struct whichs layers own, which takes from tileset tiles
Diffstat (limited to 'src/map.rs')
-rw-r--r--src/map.rs47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/map.rs b/src/map.rs
index a3ddfb3..7042f58 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -1,18 +1,18 @@
use ggez::filesystem::File;
use ggez::graphics::spritebatch::SpriteBatch;
use ggez::nalgebra::Point2;
+use std::collections::HashMap;
use xml::reader::XmlEvent::Characters;
use crate::constants;
use crate::entity::Operable;
use crate::layer::Layer;
-use crate::tileset::Tileset;
+use crate::tileset::{Tile, Tileset};
use crate::xmlelements::XMLElements;
#[derive(Clone)]
pub struct Map {
- width: usize,
- height: usize,
+ dimensions: (usize, usize),
layers: Vec<Layer>,
spawns: Vec<(String, Point2<f32>)>,
}
@@ -35,23 +35,25 @@ impl Map {
pub fn new(file: File, tileset: &Tileset) -> Map {
let elements = XMLElements::new(file);
- let width = elements
- .get_element_attribute("map", "width")
- .unwrap()
- .parse()
- .unwrap();
- let height = elements
- .get_element_attribute("map", "height")
- .unwrap()
- .parse()
- .unwrap();
+ let dimensions = (
+ elements
+ .get_element_attribute("map", "width")
+ .unwrap()
+ .parse()
+ .unwrap(),
+ elements
+ .get_element_attribute("map", "height")
+ .unwrap()
+ .parse()
+ .unwrap(),
+ );
let layers: Vec<Layer> = elements
.events
.iter()
.filter_map(|e| {
if let Characters(text) = e {
- Some(Layer::new(text, tileset, width, height))
+ Some(Layer::new(text, tileset, dimensions))
} else {
None
}
@@ -62,23 +64,22 @@ impl Map {
Map {
layers,
- width,
- height,
+ dimensions,
spawns,
}
}
fn get_spawn_points(
layers: &[Layer],
- spawn_tiles: Vec<(String, usize)>,
+ spawn_tiles: HashMap<usize, Tile>,
) -> 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));
+ for cell in layer.cells.iter() {
+ for (id, tile) in spawn_tiles.iter() {
+ if id == &cell.id {
+ spawn_points.push((tile.property.spawn.clone().unwrap(), cell.destination));
}
}
}
@@ -93,8 +94,8 @@ impl Map {
pub fn get_dimensions(&self) -> (f32, f32) {
(
- (constants::TILE_WIDTH * constants::TILE_SCALE) * self.width as f32,
- (constants::TILE_HEIGHT * constants::TILE_SCALE) * self.height as f32,
+ (constants::TILE_WIDTH * constants::TILE_SCALE) * self.dimensions.0 as f32,
+ (constants::TILE_HEIGHT * constants::TILE_SCALE) * self.dimensions.1 as f32,
)
}
}