2D_Engine/Camera.hpp

51 lines
1.4 KiB
C++

/********************\
| Copyright 2024, |
| Ulysse Cura |
\********************/
////////////////////////////////////////////////////////////////////////
// //
// Programme de la caméra, sert a avoir un rectangle et de pouvoir //
// la gérer correctement en fonction de la taille de la map... etc... //
// //
////////////////////////////////////////////////////////////////////////
#ifndef CAMERA_HPP
#define CAMERA_HPP
#include <SDL2/SDL.h> // SDL_Rect
#include "Game.hpp" // Game::...
#include "TileMap.hpp" // TileMap::...
struct Camera {
Camera(int xpos, int ypos, int width, int height)
{
camR.x = xpos;
camR.y = ypos;
camR.w = width;
camR.h = height;
}
Camera(int xpos, int ypos, int width, int height, int z) : zoom(z)
{
camR.x = xpos;
camR.y = ypos;
camR.w = width;
camR.h = height;
}
// Verifie si la caméra ne dépasse pas de la map
void update()
{
if(camR.x < 0) camR.x = 0;
if(camR.y < 0) camR.y = 0;
if(camR.x > Game::tileMap.worldWidth - camR.w) camR.x = Game::tileMap.worldWidth - camR.w;
if(camR.y > Game::tileMap.worldHeight - camR.h) camR.y = Game::tileMap.worldHeight - camR.h;
}
SDL_Rect camR;
int zoom; // TODO Zoom pas encore pris en charge
};
#endif