blob: 3461df1ad1dc96ebbc62891aea611f34f6c1397c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
use ggez::conf::Conf;
use glam::*;
use crate::constants;
pub struct Camera {
pub draw: glam::Vec2,
window_dimensions: (f32, f32),
map_dimensions: (f32, f32),
}
impl Camera {
pub fn new(map_dimensions: (f32, f32)) -> Camera {
let conf = Conf::new();
Camera {
draw: glam::Vec2::new(0.0, 0.0),
window_dimensions: (conf.window_mode.width, conf.window_mode.height),
map_dimensions,
}
}
pub fn give_center(&mut self, center: glam::Vec2) {
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_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_dimensions.1 < -1.0 * self.map_dimensions.1 {
self.draw.y = -1.0 * (self.map_dimensions.1 - self.window_dimensions.1);
}
}
}
|