diff options
Diffstat (limited to 'client/src/world')
-rw-r--r-- | client/src/world/helper.rs | 1 | ||||
-rw-r--r-- | client/src/world/map.rs | 26 | ||||
-rw-r--r-- | client/src/world/mod.rs | 4 | ||||
-rw-r--r-- | client/src/world/tee.rs | 5 |
4 files changed, 21 insertions, 15 deletions
diff --git a/client/src/world/helper.rs b/client/src/world/helper.rs index fab452a..cb34a9f 100644 --- a/client/src/world/helper.rs +++ b/client/src/world/helper.rs @@ -1,6 +1,7 @@ use std::fmt::Display; #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] +#[repr(C)] pub struct Color { pub a: u8, pub r: u8, diff --git a/client/src/world/map.rs b/client/src/world/map.rs index c72bfa9..c6355f2 100644 --- a/client/src/world/map.rs +++ b/client/src/world/map.rs @@ -23,11 +23,14 @@ pub struct Layer { pub image: Option<usize>, pub tiles: Array2<Tile>, pub kind: LayerTilemapType, + pub offset: (i32, i32), } pub struct Map { pub layers: Vec<Layer>, pub tilesets: HashMap<Option<usize>, Array2<Color>>, + pub name: String, + pub crc: i32, } impl Map { @@ -35,10 +38,12 @@ impl Map { Self { layers: Vec::new(), tilesets: HashMap::new(), + crc: 0, + name: String::from("twclient dummy map"), } } - pub fn load(file: File) -> Result<Self, Error> { + pub fn load(file: File, name: &str, crc: i32) -> Result<Self, Error> { info!("loading map"); let datafile = datafile::Reader::new(file).unwrap(); let mut map = mapfile::Reader::from_datafile(datafile); @@ -47,17 +52,10 @@ impl Map { for group_idx in map.group_indices() { let group = map.group(group_idx).unwrap(); - if group.parallax_x != 100 - || group.parallax_y != 100 - || group.offset_x != 0 - || group.offset_y != 0 - || group.clipping.is_some() - { + if group.parallax_x != 100 || group.parallax_y != 100 || group.clipping.is_some() { warn!( - "skipping layer: {}: off_x:{} off_y:{} parallax_x:{} parallax_y:{} clipping:{:?}", + "skipping layer: {}: parallax_x:{} parallax_y:{} clipping:{:?}", pretty::AlmostString::new(&group.name), - group.offset_x, - group.offset_y, group.parallax_x, group.parallax_y, group.clipping, @@ -88,6 +86,7 @@ impl Map { image: normal.image, kind: tilemap.type_, tiles, + offset: (group.offset_x, group.offset_y), }); } } @@ -146,6 +145,11 @@ impl Map { layers.len(), tilesets.len() ); - Ok(Self { tilesets, layers }) + Ok(Self { + tilesets, + layers, + crc, + name: String::from(name), + }) } } diff --git a/client/src/world/mod.rs b/client/src/world/mod.rs index 8a16016..7b25a53 100644 --- a/client/src/world/mod.rs +++ b/client/src/world/mod.rs @@ -2,9 +2,9 @@ use self::{map::Map, tee::Tees}; use crate::client::{helper::get_map_path, ClientMesgOut}; use std::fs::File; +pub mod helper; pub mod map; pub mod tee; -pub mod helper; pub use gamenet::enums; @@ -26,7 +26,7 @@ impl World { match m { ClientMesgOut::MapChange { name, crc } => { let file = File::open(get_map_path(name.as_str(), *crc)).unwrap(); - self.map = Map::load(file).unwrap(); + self.map = Map::load(file, name.as_str(), *crc).unwrap(); } _ => (), } diff --git a/client/src/world/tee.rs b/client/src/world/tee.rs index 5458fe6..6b33f48 100644 --- a/client/src/world/tee.rs +++ b/client/src/world/tee.rs @@ -1,4 +1,4 @@ -use std::collections::BTreeMap; +use std::{collections::BTreeMap, f32::consts::PI}; use super::helper::Color; use crate::client::ClientMesgOut; @@ -28,7 +28,7 @@ pub struct Tee { pub attack_tick: i32, pub tick: i32, - pub angle: i32, + pub angle: f32, pub x: i32, pub y: i32, pub vel_x: i32, @@ -126,6 +126,7 @@ impl Tees { e.x = c.character_core.x; e.y = c.character_core.y; + e.angle = c.character_core.angle as f32 / 1600.0 * 2.0 * PI; e.vel_x = c.character_core.vel_x; e.vel_y = c.character_core.vel_y; |