diff options
| author | tom barrett <spalf0@gmail.com> | 2019-06-18 02:29:24 -0500 | 
|---|---|---|
| committer | tom barrett <spalf0@gmail.com> | 2019-06-18 02:29:24 -0500 | 
| commit | 2ad96b7f882ff962f67a13c7c56a46df86cfe6e3 (patch) | |
| tree | 2bab6cc41f5b0888548dcc3d9a7fa02ef55645b6 /src/map.rs | |
| parent | b4bd866cfadb1eae80f9d116364cab029a28f79b (diff) | |
added camera struct, moved map drawing to map struct, now draws a character that moves
Diffstat (limited to 'src/map.rs')
| -rw-r--r-- | src/map.rs | 23 | 
1 files changed, 23 insertions, 0 deletions
| @@ -1,7 +1,12 @@  use ggez::filesystem::File; +use ggez::graphics::{spritebatch::SpriteBatch, DrawParam}; +use ggez::nalgebra::{Point2, Vector2};  use std::io::BufReader;  use xml::reader::{EventReader, XmlEvent}; +use crate::constants; +use crate::tileset::Tileset; +  pub struct Map {      pub width: usize,      pub height: usize, @@ -39,6 +44,24 @@ impl Map {              height: height.unwrap(),          }      } + +    pub fn draw(&mut self, spritebatch: &mut SpriteBatch, tileset: &Tileset) { +        for layer in self.layers.iter() { +            for x in 0..self.width { +                for y in 0..self.height { +                    let draw_param = DrawParam::default() +                        .src(tileset.tiles[layer.data[x + (y * self.height)]]) +                        .dest(Point2::new( +                            tileset.tile_width * constants::TILE_SCALE * x as f32, +                            tileset.tile_height * constants::TILE_SCALE * y as f32, +                        )) +                        .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE)); + +                    spritebatch.add(draw_param); +                } +            } +        } +    }  }  pub struct Layer { | 
