diff options
author | tom barrett <spalf0@gmail.com> | 2019-07-13 04:51:26 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-07-13 04:51:26 -0500 |
commit | 9443ea856a706654916f0905d346c1e2c9d500c4 (patch) | |
tree | 027b69e10c482337cfc1109c58c50fdf32fa8c04 /src | |
parent | b4e83e63d46fdbc40f548bfa9bd95d7ed9912b8d (diff) |
less code
Diffstat (limited to 'src')
-rw-r--r-- | src/animations.rs | 6 | ||||
-rw-r--r-- | src/tile.rs | 23 | ||||
-rw-r--r-- | src/tileset.rs | 20 |
3 files changed, 22 insertions, 27 deletions
diff --git a/src/animations.rs b/src/animations.rs index 58b6bf2..b57f69b 100644 --- a/src/animations.rs +++ b/src/animations.rs @@ -5,7 +5,7 @@ use std::time::Instant; use crate::constants; use crate::entity::Action; -use crate::tile::Tile; +use crate::tile::{Tile, flip}; use crate::tileset::Tileset; #[derive(Debug, Clone, PartialEq)] @@ -80,8 +80,8 @@ impl Animations { available.insert(Action::MovingUpLeft, animation.clone()); available.insert(Action::MovingDownLeft, animation.clone()); - idle.flip(); - moving.flip(); + let idle = flip(idle); + let moving = flip(moving); let animation = Animation::new(vec![idle.clone()]); available.insert(Action::IdleRight, animation.clone()); diff --git a/src/tile.rs b/src/tile.rs index de67cdc..e651f4a 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -1,5 +1,6 @@ use ggez::graphics::Rect; use xml::reader::XmlEvent; +use std::f32::consts::PI; use crate::xmlelements::XMLElements; @@ -13,11 +14,6 @@ impl Tile { pub fn new(source: Rect, properties: Properties) -> Tile { Tile { source, properties } } - - pub fn flip(&mut self) { - self.source.x *= -1.0; - self.source.x -= self.source.w; - } } impl Default for Tile { @@ -79,3 +75,20 @@ impl Default for Properties { } } } + +pub fn convert_angle_to_rad(angle: f32) -> f32 { + angle * (PI / 180.0) +} + +pub fn flip(tile: Tile) -> Tile { + let mut t = tile.clone(); + t.source.x *= -1.0; + t.source.x -= t.source.w; + t +} + +pub fn rotate(tile: Tile, angle: f32) -> Tile { + let mut t = tile.clone(); + t.properties.rotation = convert_angle_to_rad(angle); + t +} diff --git a/src/tileset.rs b/src/tileset.rs index fe2f84b..5193d44 100644 --- a/src/tileset.rs +++ b/src/tileset.rs @@ -1,11 +1,10 @@ use ggez::filesystem::File; use ggez::graphics::Rect; use std::collections::HashMap; -use std::f32::consts::PI; use crate::animations::Animation; use crate::constants::{self, FLIP_A, FLIP_D, FLIP_H, FLIP_V}; -use crate::tile::{Properties, Tile}; +use crate::tile::{Properties, Tile, flip, rotate}; use crate::xmlelements::XMLElements; pub struct Tileset { @@ -135,20 +134,3 @@ impl Tileset { .clone() } } - -pub fn convert_angle_to_rad(angle: f32) -> f32 { - angle * (PI / 180.0) -} - -fn flip(tile: Tile) -> Tile { - let mut t = tile.clone(); - t.source.x *= -1.0; - 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 -} |