diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | src/animations.rs | 6 | ||||
-rw-r--r-- | src/tile.rs | 23 | ||||
-rw-r--r-- | src/tileset.rs | 20 |
4 files changed, 25 insertions, 27 deletions
@@ -5,3 +5,6 @@ * collision * fat binary (include-bytes!) * textbox (with dialog options) + +* impl EventHandler instead of Operable? +* npc movement 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 -} |