From bfdaef7850b6ac17bb88f1b314236fb5014aac8e Mon Sep 17 00:00:00 2001 From: tom barrett Date: Fri, 5 Jul 2019 08:59:22 -0500 Subject: now a cells struct whichs layers own, which takes from tileset tiles --- src/tile.rs | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) (limited to 'src/tile.rs') diff --git a/src/tile.rs b/src/tile.rs index b00f55e..13d095f 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -1,52 +1,33 @@ use ggez::graphics::spritebatch::SpriteBatch; use ggez::nalgebra::Point2; -use crate::animations::{convert_angle_to_rad, flip, Animation, Frame}; +use crate::animations::Animation; use crate::constants; use crate::entity::Operable; use crate::tileset::Tileset; #[derive(Debug, Clone)] -pub struct Tile { +pub struct Cell { pub id: usize, pub animation: Animation, pub destination: Point2, } -impl Operable for Tile { +impl Operable for Cell { fn update(&mut self) { self.animation.update(); } fn draw(&self, spritebatch: &mut SpriteBatch) { self.animation.draw(spritebatch, self.destination); - /* - DrawParam::default() - .src(self.animation.current.source) - .dest(self.destination) - .offset(Point2::new(0.5, 0.5)) - //.rotation(self.rotation) - .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE)), - ); - */ } } -impl Tile { - pub fn new(text: &str, i: usize, tileset: &Tileset, width: usize, height: usize) -> Tile { +impl Cell { + pub fn new(text: &str, i: usize, tileset: &Tileset, dimensions: (usize, usize)) -> Cell { let id = text.parse::().unwrap(); /* - let flip_d = (id & constants::FLIP_DIAGONAL_FLAG) == constants::FLIP_DIAGONAL_FLAG; - let flip_h = (id & constants::FLIP_HORIZONTAL_FLAG) == constants::FLIP_HORIZONTAL_FLAG; - let flip_v = (id & constants::FLIP_VERTICAL_FLAG) == constants::FLIP_VERTICAL_FLAG; - - let id = if flip_h | flip_v | flip_d { - id & !constants::ALL_FLIP_FLAGS - } else { - id - }; - let (source, rotation) = match (flip_d, flip_h, flip_v) { (true, true, true) => (flip(tileset.get(id)), convert_angle_to_rad(90.0)), (true, true, false) => (tileset.get(id), convert_angle_to_rad(90.0)), @@ -60,8 +41,8 @@ impl Tile { }; */ - let x = i as f32 % width as f32; - let y = (i as f32 / height as f32).floor(); + let x = i as f32 % dimensions.0 as f32; + let y = (i as f32 / dimensions.1 as f32).floor(); //let offset = (constants::TILE_WIDTH / 2.0) * constants::TILE_SCALE; let destination = Point2::new( @@ -69,14 +50,7 @@ impl Tile { constants::TILE_HEIGHT * constants::TILE_SCALE * y, //+ offset, ); - //let mut animation = Animation::new(Frame::new(source, None, rotation)); - /* - let frame = tileset.get_frame(id); - let mut animation = Animation::default(); - animation.give_frames(tileset.get_frames(id)); - */ - - Tile { + Cell { id, animation: tileset.get_animation(id), destination, -- cgit v1.2.3