2D_Engine/Camera.hpp

45 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::...
#include "Vector2D.hpp" // Vector2D class
struct Camera {
Camera(int width, int height)
{
camR.w = width;
camR.h = height;
}
// Update camera
void update()
{
camR.x = static_cast<int>(centerPos.x - (static_cast<float>(camR.w) / 2.0f));
camR.y = static_cast<int>(centerPos.y - (static_cast<float>(camR.h) / 2.0f));
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;
}
Vector2D<float> centerPos;
SDL_Rect camR;
};
#endif