summaryrefslogtreecommitdiff
path: root/src/camera.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-06-19 04:45:46 -0500
committertom barrett <spalf0@gmail.com>2019-06-19 04:45:46 -0500
commit8693a266c2c9a8448b70d87d487ed211c439cbc4 (patch)
tree3330eeba26d6f5f65b7625c49215e54cd5394271 /src/camera.rs
parent0567e86e184684ace269edad903a740e6f2f4024 (diff)
camera now doesnt display unused map
Diffstat (limited to 'src/camera.rs')
-rw-r--r--src/camera.rs32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/camera.rs b/src/camera.rs
index 4ae0153..ed5a20a 100644
--- a/src/camera.rs
+++ b/src/camera.rs
@@ -1,23 +1,41 @@
use ggez::nalgebra::Point2;
use ggez::Context;
+use crate::constants;
+
pub struct Camera {
pub draw: Point2<f32>,
- height: f32,
- width: f32,
+ window_height: f32,
+ window_width: f32,
+ map_height: f32,
+ map_width: f32,
}
impl Camera {
- pub fn new(context: &mut Context) -> Camera {
+ pub fn new(context: &mut Context, dimensions: (f32, f32)) -> Camera {
Camera {
draw: Point2::new(0.0, 0.0),
- height: context.conf.window_mode.height,
- width: context.conf.window_mode.width,
+ window_height: context.conf.window_mode.height,
+ window_width: context.conf.window_mode.width,
+ map_width: dimensions.0,
+ map_height: dimensions.1,
}
}
pub fn give_center(&mut self, center: Point2<f32>) {
- self.draw.x = (self.width / 2.0) - center.x;
- self.draw.y = (self.height / 2.0) - center.y;
+ 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);
+
+ 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);
+ }
+
+ 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);
+ }
}
}