diff options
author | tom barrett <spalf0@gmail.com> | 2019-06-27 10:00:42 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-06-27 10:00:42 -0500 |
commit | a76efb8444af9d4a0ee558e72903c67bc2cff5d3 (patch) | |
tree | b93849385e23e51466658502fe0a8a3064405ba5 /src/layer.rs | |
parent | 93d0a0eb6a5c35ad8b82f368c5251d9690c508f9 (diff) | |
parent | ee8d055be8326eb1561900bcca6acd9e38071f4a (diff) |
Merge branch 'master' into feature/dude
Diffstat (limited to 'src/layer.rs')
-rw-r--r-- | src/layer.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/layer.rs b/src/layer.rs new file mode 100644 index 0000000..c9f32e8 --- /dev/null +++ b/src/layer.rs @@ -0,0 +1,37 @@ +use ggez::graphics::spritebatch::SpriteBatch; + +use crate::tile::Tile; +use crate::tileset::Tileset; + +pub struct Layer { + pub tiles: Vec<Tile>, + pub width: usize, + pub height: usize, +} + +impl Layer { + pub fn new(text: &str, tileset: &Tileset, width: usize, height: usize) -> Layer { + Layer { + tiles: text + .replace("\n", "") + .split(',') + .enumerate() + .map(|(i, s)| Tile::new(s, i, tileset, width, height)) + .collect(), + width, + height, + } + } + + pub fn update(&mut self) { + for tile in self.tiles.iter_mut() { + tile.update(); + } + } + + pub fn draw(&self, spritebatch: &mut SpriteBatch) { + for tile in self.tiles.iter() { + tile.draw(spritebatch); + } + } +} |