diff options
author | tom barrett <spalf0@gmail.com> | 2019-07-08 04:53:04 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-07-08 04:53:04 -0500 |
commit | 503361ce70615d7c4b66bd7e49d56c61259dab32 (patch) | |
tree | a252975aaa2b34f4fcac81d8fdb5b11f8d36cf0e | |
parent | de4e8c1f0b82627fd1980401ae63472f49c9d89c (diff) |
rotation now works
-rw-r--r-- | src/animations.rs | 2 | ||||
-rw-r--r-- | src/cell.rs | 20 | ||||
-rw-r--r-- | src/tileset.rs | 18 |
3 files changed, 17 insertions, 23 deletions
diff --git a/src/animations.rs b/src/animations.rs index be10f31..43f4326 100644 --- a/src/animations.rs +++ b/src/animations.rs @@ -46,6 +46,8 @@ impl Animation { spritebatch.add( DrawParam::default() .src(self.current.source) + .rotation(self.current.properties.rotation) + .offset(Point2::new(0.5, 0.5)) .dest(position) .scale(Vector2::new(constants::TILE_SCALE, constants::TILE_SCALE)), ); diff --git a/src/cell.rs b/src/cell.rs index 13d095f..9d257ff 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -27,27 +27,13 @@ impl Cell { pub fn new(text: &str, i: usize, tileset: &Tileset, dimensions: (usize, usize)) -> Cell { let id = text.parse::<usize>().unwrap(); - /* - 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)), - (true, false, true) => (tileset.get(id), convert_angle_to_rad(270.0)), - //(true, false, false) => (), - (false, true, true) => (tileset.get(id), convert_angle_to_rad(180.0)), - (false, true, false) => (flip(tileset.get(id)), 0.0), - //(false, false, true) => (), - //(false, false, false) => (), - _ => (tileset.get(id), 0.0), - }; - */ - 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 offset = (constants::TILE_WIDTH / 2.0) * constants::TILE_SCALE; let destination = Point2::new( - constants::TILE_WIDTH * constants::TILE_SCALE * x, //+ offset, - constants::TILE_HEIGHT * constants::TILE_SCALE * y, //+ offset, + (constants::TILE_WIDTH * constants::TILE_SCALE * x) + offset, + (constants::TILE_HEIGHT * constants::TILE_SCALE * y) + offset, ); Cell { diff --git a/src/tileset.rs b/src/tileset.rs index bb64c12..6a7ca42 100644 --- a/src/tileset.rs +++ b/src/tileset.rs @@ -64,13 +64,13 @@ impl Tileset { for (id, tile) in tiles.clone().into_iter() { for i in 1..8 { let (new_id, new_tile) = match i { - 1 => ((id | FLIP_H), tile.clone()), - 2 => ((id | FLIP_V), flip(tile.clone())), + 1 => ((id | FLIP_H), flip(tile.clone())), + 2 => ((id | FLIP_V), tile.clone()), 3 => ((id | FLIP_D), tile.clone()), - 4 => ((id | FLIP_D | FLIP_H), tile.clone()), - 5 => ((id | FLIP_D | FLIP_V), tile.clone()), - 6 => ((id | FLIP_H | FLIP_V), tile.clone()), - 7 => ((id | FLIP_A), tile.clone()), + 4 => ((id | FLIP_D | FLIP_H), rotate(tile.clone(), 90.0)), + 5 => ((id | FLIP_D | FLIP_V), rotate(tile.clone(), 270.0)), + 6 => ((id | FLIP_H | FLIP_V), rotate(tile.clone(), 180.0)), + 7 => ((id | FLIP_A), rotate(tile.clone(), 90.0)), _ => (0, Tile::default()), }; @@ -135,3 +135,9 @@ fn flip(tile: Tile) -> Tile { t.source.x -= t.source.w; t } + +fn rotate(tile: Tile, angle: f32) -> Tile { + let mut t = tile.clone(); + t.properties.rotation = convert_angle_to_rad(angle); + t +} |