Commit 3293120e authored by Luke Jones's avatar Luke Jones

Center camera on player/input target

Signed-off-by: 's avatarLuke Jones <jones_ld@protonmail.com>
parent 201f2081
Pipeline #69317964 passed with stage
in 3 minutes and 43 seconds
......@@ -107,7 +107,7 @@
"x":0,
"y":0
}],
"nextlayerid":9,
"nextlayerid":11,
"nextobjectid":10,
"orientation":"orthogonal",
"renderorder":"right-down",
......
......@@ -92,7 +92,7 @@ pub fn main() {
// An SDL context is needed before we can procceed
let mut sdl_ctx = sdl2::init().unwrap();
// TODO: initialize a settings store here, then load settings
let mut game = game::Game::new(&mut sdl_ctx, 900, 900);
let mut game = game::Game::new(&mut sdl_ctx, 800, 600);
let mut timestep = TimeStep::new();
let mut lag = 0.0;
......
......@@ -45,20 +45,23 @@ impl Camera {
}
pub fn update_position(&mut self, position: Vec2d<i32>) {
let mut new_x = position.x() / 2;
let mut new_y = position.y() / 2;
dbg!(&new_x);
let mut new_x =
position.x() - self.screen_extents_in_world.width() as i32 / 2;
let mut new_y =
position.y() - self.screen_extents_in_world.height() as i32 / 2;
if new_x < 0 {
new_x = 0
// Bounds
if new_x < self.world_extents.left() {
new_x = self.world_extents.left();
} else if new_x + self.screen_extents_in_world.width() as i32
> self.world_extents.width() as i32
> self.world_extents.right()
{
new_x = self.world_extents.width() as i32
- self.screen_extents_in_world.width() as i32
}
if new_y < 0 {
new_y = 0
if new_y < self.world_extents.y() {
new_y = self.world_extents.y()
} else if new_y + self.screen_extents_in_world.height() as i32
> self.world_extents.height() as i32
{
......@@ -68,7 +71,6 @@ impl Camera {
self.screen_extents_in_world.set_x(new_x);
self.screen_extents_in_world.set_y(new_y);
dbg!(&self.screen_extents_in_world);
}
pub fn world_to_screen(&self, world: Vec2d<i32>) -> Vec2d<i32> {
......
......@@ -122,7 +122,7 @@ impl World {
self.cam.set(
canvas.viewport(),
Rect::new(0, 0, pixel_width, pixel_height),
Rect::new(0, 0, 300, 300),
Rect::new(0, 0, 400, 300),
);
self.level_change = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment