mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 14:41:49 +01:00
101 lines
2.5 KiB
C++
101 lines
2.5 KiB
C++
#include "pch.h"
|
|
#include "Game.h"
|
|
|
|
#include <ostream>
|
|
|
|
#include "colors.h"
|
|
#include "utils.h"
|
|
#include "Levels/World/WorldLevel.h"
|
|
|
|
|
|
Rectf Game::VIEWPORT {};
|
|
|
|
Game::Game(const Window& window)
|
|
: BaseGame { window }, m_Camera(Camera()), m_WorldLevel(WorldLevel(&m_Camera, GetViewPort())),
|
|
m_MainMenuLevel(MainMenuLevel(&m_Camera)), m_pCurrentLevel(&m_WorldLevel) {
|
|
Initialize();
|
|
Game::VIEWPORT = GetViewPort(); //TODO: See if this can be removed
|
|
}
|
|
|
|
Game::~Game() {
|
|
Cleanup();
|
|
}
|
|
|
|
void Game::Initialize() {
|
|
m_Camera.SetPosition(Vector2f { -GetViewPort().width / 2, -GetViewPort().height / 2 });
|
|
}
|
|
|
|
void Game::Cleanup() {
|
|
}
|
|
|
|
void Game::Update(float elapsedSec) {
|
|
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
|
|
|
|
if (m_IsRightMouseDown) {
|
|
const Vector2f newCameraPos = Vector2f { m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y };
|
|
m_Camera.SetPosition(Vector2f { -newCameraPos.x, -newCameraPos.y });
|
|
}
|
|
else {
|
|
m_MouseOffset = m_Camera.GetPosition();
|
|
}
|
|
|
|
m_pCurrentLevel->Update(elapsedSec);
|
|
}
|
|
|
|
|
|
void Game::Draw() const {
|
|
utils::ClearBackground(Color4f(0.0f, 0.0f, 0.3f, 1.0f));
|
|
m_pCurrentLevel->Draw();
|
|
}
|
|
|
|
void Game::ProcessKeyDownEvent(const SDL_KeyboardEvent& e) {
|
|
//std::cout << "KEYDOWN event: " << e.keysym.sym << std::endl;
|
|
}
|
|
|
|
void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
|
|
}
|
|
|
|
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
|
|
m_MousePos = Vector2f { float(e.x), float(e.y) };
|
|
m_pCurrentLevel->MouseMove(Vector2f { float(e.x), float(e.y) });
|
|
|
|
|
|
|
|
}
|
|
|
|
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
|
|
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT;
|
|
m_MouseOffset = Vector2f { -m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y };
|
|
}
|
|
|
|
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
|
|
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT ? false : m_IsRightMouseDown;
|
|
//std::cout << "MOUSEBUTTONUP event: ";
|
|
//switch ( e.button )
|
|
//{
|
|
//case SDL_BUTTON_LEFT:
|
|
// std::cout << " left button " << std::endl;
|
|
// break;
|
|
//case SDL_BUTTON_RIGHT:k
|
|
// std::cout << " right button " << std::endl;
|
|
// break;
|
|
//case SDL_BUTTON_MIDDLE:
|
|
// std::cout << " middle button " << std::endl;
|
|
// break;
|
|
//}
|
|
}
|
|
void Game::ProcessMouseWheelEvent(const SDL_MouseWheelEvent& e) {
|
|
Vector2f scroll = Vector2f { 0, 0 };
|
|
if (e.y > 0) {
|
|
scroll = Vector2f { 0, 1 };
|
|
}
|
|
else if (e.y < 0) {
|
|
scroll = Vector2f { 0, -1 };
|
|
}
|
|
//camera zoom
|
|
m_Camera.SetScale((m_Camera.GetScale() - e.preciseY * 0.1f));
|
|
}
|
|
void Game::ProcessImGui() {
|
|
m_pCurrentLevel->ProcessImGui();
|
|
}
|