Added the Grid, Camera, Level system

Basic player
Started (Barely) on the TextureManager
And other fixes
This commit is contained in:
Bram Verhulst
2024-03-11 03:29:44 +01:00
parent f7c2262e10
commit d6bb3add26
35 changed files with 991 additions and 62 deletions

View File

@@ -1,10 +1,12 @@
#include "pch.h"
#include "Game.h"
#include "colors.h"
#include "utils.h"
#include "WorldLevel.h"
Game::Game(const Window& window)
: BaseGame { window }
: BaseGame { window }, m_Camera(Camera()), m_WorldLevel(WorldLevel(&m_Camera))
{
Initialize();
}
@@ -14,34 +16,42 @@ Game::~Game() {
}
void Game::Initialize() {
m_WorldLevel = WorldLevel();
m_Camera.SetPosition(Point2f{GetViewPort().width / 2, GetViewPort().height / 2});
}
void Game::Cleanup() {
}
void Game::Update(float elapsedSec) {
const Uint8 *pStates = SDL_GetKeyboardState( nullptr );
if ( pStates[SDL_SCANCODE_RIGHT] ) {
m_CameraOffset.x += 100 * elapsedSec;
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
// if (pStates[SDL_SCANCODE_RIGHT]) {
// m_CameraOffset.x += 200 * elapsedSec;
// }
// if (pStates[SDL_SCANCODE_LEFT]) {
// m_CameraOffset.x -= 200 * elapsedSec;
// }
// if (pStates[SDL_SCANCODE_UP]) {
// m_CameraOffset.y += 200 * elapsedSec;
// }
// if (pStates[SDL_SCANCODE_DOWN]) {
// m_CameraOffset.y -= 200 * elapsedSec;
// }
if(m_IsMouseDown) {
Point2f newCameraPos = m_MousePos + m_MouseOffset;
m_Camera.SetPosition(newCameraPos);
} else {
m_MouseOffset = m_Camera.GetPosition();
}
if ( pStates[SDL_SCANCODE_LEFT] ) {
m_CameraOffset.x -= 100 * elapsedSec;
}
}
void Game::Draw() const {
ClearBackground();
glPushMatrix();
{
glTranslatef(m_CameraOffset.x , m_CameraOffset.y, 0);
m_WorldLevel.Draw();
utils::SetColor(Color4f{1.0f, 0.0f, 0.0f, 1.0f});
utils::FillEllipse(0,0,20,20);
}
glPopMatrix();
utils::ClearBackground(Color4f(0.0f, 0.0f, 0.3f, 1.0f));
//m_Camera.BeginRendering();
m_WorldLevel.Draw();
//m_Camera.EndRendering();
}
void Game::ProcessKeyDownEvent(const SDL_KeyboardEvent& e) {
@@ -66,10 +76,15 @@ void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
}
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
//std::cout << "MOUSEMOTION event: " << e.x << ", " << e.y << std::endl;
m_MousePos = Point2f { float(e.x), float(e.y) };
m_WorldLevel.MouseMove(m_MousePos);
}
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
m_IsMouseDown = true;
m_MouseOffset = Point2f(m_Camera.GetPosition() - m_MousePos);
//std::cout << "MOUSEBUTTONDOWN event: ";
//switch ( e.button )
//{
@@ -87,6 +102,7 @@ void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
}
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
m_IsMouseDown = false;
//std::cout << "MOUSEBUTTONUP event: ";
//switch ( e.button )
//{
@@ -101,8 +117,3 @@ void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
// break;
//}
}
void Game::ClearBackground() const {
glClearColor(0.0f, 0.0f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}