30 lines
714 B
C
30 lines
714 B
C
#include "camera.h"
|
|
|
|
#include "game.h"
|
|
#include "display.h"
|
|
|
|
void camera_init(void)
|
|
{
|
|
game.camera.view_rect = (rect_t) {
|
|
.x = 0.0f,
|
|
.y = 0.0f,
|
|
.w = DISPLAY_WIDTH / 2,
|
|
.h = DISPLAY_HEIGHT / 2
|
|
};
|
|
|
|
game.camera.tracking_pos = NULL;
|
|
game.camera.tracking_center_offset = (fvector2d_t) {
|
|
.x = 0.0f,
|
|
.y = 0.0f
|
|
};
|
|
}
|
|
|
|
void camera_update(void)
|
|
{
|
|
if(game.camera.tracking_pos)
|
|
{
|
|
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;
|
|
}
|
|
}
|