Entropie git · main
git clone https://git.christianimmanuel.de/games/Entropie.gitwget https://git.christianimmanuel.de/games/Entropie/archive/Entropie.tar.gzcamera.c raw
#include "camera.h"
extern int MAP_WIDTH;
extern int MAP_HEIGHT;
extern const int TILE_SIZE;
void setCamera(Camera* camera) {
// Calculate camera offset
camera->offset_x = camera->center_x - (camera->view_w / 2);
camera->offset_y = camera->center_y - (camera->view_h / 2);
// Calculate bounds in terms of tiles
camera->min_x = (int)(camera->offset_x / TILE_SIZE);
camera->max_x = (int)((camera->offset_x + camera->view_w) / TILE_SIZE);
camera->min_y = (int)(camera->offset_y / TILE_SIZE);
camera->max_y = (int)((camera->offset_y + camera->view_h) / TILE_SIZE);
// Ensure bounds are within map limits
camera->min_x = (camera->min_x < 0) ? 0 : camera->min_x;
camera->max_x = (camera->max_x >= MAP_WIDTH) ? MAP_WIDTH - 1 : camera->max_x;
camera->min_y = (camera->min_y < 0) ? 0 : camera->min_y;
camera->max_y = (camera->max_y >= MAP_HEIGHT) ? MAP_HEIGHT - 1 : camera->max_y;
}