summaryrefslogtreecommitdiff
path: root/src/camera.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-07-05 08:59:22 -0500
committertom barrett <spalf0@gmail.com>2019-07-05 08:59:22 -0500
commitbfdaef7850b6ac17bb88f1b314236fb5014aac8e (patch)
tree748ceca98138b5783655ec181ea905a25a690934 /src/camera.rs
parent6589e5e3df63d5abf85313c4d21097432257f453 (diff)
now a cells struct whichs layers own, which takes from tileset tiles
Diffstat (limited to 'src/camera.rs')
-rw-r--r--src/camera.rs29
1 files changed, 14 insertions, 15 deletions
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<f32>,
- 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<f32>) {
- 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);
}
}
}