Centering camera on map.
This commit is contained in:
parent
6ef77524ac
commit
45a7323213
35
src/camera.c
35
src/camera.c
|
|
@ -26,4 +26,39 @@ void camera_update(void)
|
|||
game.camera.view_rect.x = game.camera.tracking_pos->x + game.camera.tracking_center_offset.x - game.camera.view_rect.w / 2;
|
||||
game.camera.view_rect.y = game.camera.tracking_pos->y + game.camera.tracking_center_offset.y - game.camera.view_rect.h / 2;
|
||||
}
|
||||
|
||||
if(game.map)
|
||||
{
|
||||
if(game.camera.view_rect.w > game.map->width * TILE_SIZE)
|
||||
{
|
||||
game.camera.view_rect.x = game.map->width * TILE_SIZE / 2 - game.camera.view_rect.w / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(game.camera.view_rect.x < 0)
|
||||
{
|
||||
game.camera.view_rect.x = 0;
|
||||
}
|
||||
else if(game.camera.view_rect.x + game.camera.view_rect.w > game.map->width * TILE_SIZE)
|
||||
{
|
||||
game.camera.view_rect.x = game.map->width * TILE_SIZE - game.camera.view_rect.w;
|
||||
}
|
||||
}
|
||||
|
||||
if(game.camera.view_rect.h > game.map->height * TILE_SIZE)
|
||||
{
|
||||
game.camera.view_rect.y = game.map->height * TILE_SIZE / 2 - game.camera.view_rect.h / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(game.camera.view_rect.y < 0)
|
||||
{
|
||||
game.camera.view_rect.y = 0;
|
||||
}
|
||||
else if(game.camera.view_rect.y + game.camera.view_rect.h > game.map->height * TILE_SIZE)
|
||||
{
|
||||
game.camera.view_rect.y = game.map->height * TILE_SIZE - game.camera.view_rect.h;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue