Added display scale per platform and camera mode.

This commit is contained in:
Ulysse Cura 2026-11-28 11:31:47 +01:00
parent b5185d103c
commit e5e358a33f
4 changed files with 15 additions and 4 deletions

View File

@ -8,8 +8,8 @@ void camera_init(void)
game.camera.view_rect = (rect_t) { game.camera.view_rect = (rect_t) {
.x = 0, .x = 0,
.y = 0, .y = 0,
.w = DISPLAY_WIDTH / 2, .w = DISPLAY_WIDTH / DISPLAY_SCALE,
.h = DISPLAY_HEIGHT / 2 .h = DISPLAY_HEIGHT / DISPLAY_SCALE
}; };
game.camera.tracking_pos = NULL; game.camera.tracking_pos = NULL;
@ -17,17 +17,19 @@ void camera_init(void)
.x = 0, .x = 0,
.y = 0 .y = 0
}; };
game.camera.mode = CAMERA_TRACKING;
} }
void camera_update(void) void camera_update(void)
{ {
if(game.camera.tracking_pos) if(game.camera.mode & CAMERA_TRACKING)
{ {
game.camera.view_rect.x = (int)game.camera.tracking_pos->x + game.camera.tracking_center_offset.x - game.camera.view_rect.w / 2; game.camera.view_rect.x = (int)game.camera.tracking_pos->x + game.camera.tracking_center_offset.x - game.camera.view_rect.w / 2;
game.camera.view_rect.y = (int)game.camera.tracking_pos->y + game.camera.tracking_center_offset.y - game.camera.view_rect.h / 2; game.camera.view_rect.y = (int)game.camera.tracking_pos->y + game.camera.tracking_center_offset.y - game.camera.view_rect.h / 2;
} }
if(game.map) if(game.camera.mode & CAMERA_BOUND_MAP)
{ {
if(game.camera.view_rect.w > game.map->width * TILE_SIZE) if(game.camera.view_rect.w > game.map->width * TILE_SIZE)
{ {

View File

@ -3,10 +3,17 @@
#include "vector2d.h" #include "vector2d.h"
typedef enum camera_mode_t {
CAMERA_STATIC = 0x0000,
CAMERA_TRACKING = 0x0001,
CAMERA_BOUND_MAP = 0x0010,
} camera_mode_t;
typedef struct camera_t { typedef struct camera_t {
rect_t view_rect; rect_t view_rect;
fvector2d_t *tracking_pos; fvector2d_t *tracking_pos;
vector2d_t tracking_center_offset; vector2d_t tracking_center_offset;
camera_mode_t mode;
} camera_t; } camera_t;
void camera_init(void); void camera_init(void);

View File

@ -13,6 +13,7 @@
#define DISPLAY_WIDTH DWIDTH #define DISPLAY_WIDTH DWIDTH
#define DISPLAY_HEIGHT DHEIGHT #define DISPLAY_HEIGHT DHEIGHT
#define DISPLAY_SCALE 1
typedef int display_t; typedef int display_t;

View File

@ -13,6 +13,7 @@
#define DISPLAY_WIDTH 720 #define DISPLAY_WIDTH 720
#define DISPLAY_HEIGHT 480 #define DISPLAY_HEIGHT 480
#define DISPLAY_SCALE 2
typedef struct display_t { typedef struct display_t {
SDL_Window *window; SDL_Window *window;