From 49b07a29ab42b2d550becfd0de8da4231341b706 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Sun, 16 Jun 2019 10:33:29 -0500 Subject: layers now supported --- src/main.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index bb85c0a..953d326 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,8 @@ use ggez::graphics::{self, spritebatch::SpriteBatch, DrawParam, FilterMode, Imag use ggez::nalgebra::{Point2, Vector2}; use ggez::{Context, ContextBuilder, GameResult}; use pax_romana::constants; -use pax_romana::map::{Map, Tileset}; +use pax_romana::map::Map; +use pax_romana::tileset::Tileset; struct State { map: Map, @@ -34,17 +35,19 @@ impl EventHandler for State { fn draw(&mut self, context: &mut Context) -> GameResult { graphics::clear(context, graphics::BLACK); - for x in 0..self.map.width { - for y in 0..self.map.height { - let draw_param = DrawParam::default() - .src(self.tileset.tiles[self.map.data[x + (y * self.map.height)]]) - .dest(Point2::new( - self.tileset.tile_width * constants::TILE_SCALE * x as f32, - self.tileset.tile_height * constants::TILE_SCALE * y as f32, - )) - .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE)); + for layer in self.map.layers.iter() { + for x in 0..self.map.width { + for y in 0..self.map.height { + let draw_param = DrawParam::default() + .src(self.tileset.tiles[layer.data[x + (y * self.map.height)]]) + .dest(Point2::new( + self.tileset.tile_width * constants::TILE_SCALE * x as f32, + self.tileset.tile_height * constants::TILE_SCALE * y as f32, + )) + .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE)); - self.spritebatch.add(draw_param); + self.spritebatch.add(draw_param); + } } } -- cgit v1.2.3