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/camera.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/camera.rs') diff --git a/src/camera.rs b/src/camera.rs index ed5a20a..07745e5 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -5,37 +5,36 @@ use crate::constants; pub struct Camera { pub draw: Point2, - window_height: f32, - window_width: f32, - map_height: f32, - map_width: f32, + window_dimensions: (f32, f32), + map_dimensions: (f32, f32), } impl Camera { - pub fn new(context: &mut Context, dimensions: (f32, f32)) -> Camera { + pub fn new(context: &mut Context, map_dimensions: (f32, f32)) -> Camera { Camera { draw: Point2::new(0.0, 0.0), - window_height: context.conf.window_mode.height, - window_width: context.conf.window_mode.width, - map_width: dimensions.0, - map_height: dimensions.1, + window_dimensions: ( + context.conf.window_mode.width, + context.conf.window_mode.height, + ), + map_dimensions, } } pub fn give_center(&mut self, center: Point2) { - self.draw.x = ((self.window_width / 2.0) - center.x) - (constants::TILE_WIDTH); - self.draw.y = ((self.window_height / 2.0) - center.y) - (constants::TILE_HEIGHT); + self.draw.x = ((self.window_dimensions.0 / 2.0) - center.x) - (constants::TILE_WIDTH); + self.draw.y = ((self.window_dimensions.1 / 2.0) - center.y) - (constants::TILE_HEIGHT); if self.draw.x > 0.0 { self.draw.x = 0.0; - } else if self.draw.x - self.window_width < -1.0 * self.map_width { - self.draw.x = -1.0 * (self.map_width - self.window_width); + } else if self.draw.x - self.window_dimensions.0 < -1.0 * self.map_dimensions.0 { + self.draw.x = -1.0 * (self.map_dimensions.0 - self.window_dimensions.0); } if self.draw.y > 0.0 { self.draw.y = 0.0; - } else if self.draw.y - self.window_height < -1.0 * self.map_height { - self.draw.y = -1.0 * (self.map_height - self.window_height); + } else if self.draw.y - self.window_dimensions.1 < -1.0 * self.map_dimensions.1 { + self.draw.y = -1.0 * (self.map_dimensions.1 - self.window_dimensions.1); } } } -- cgit v1.2.3