Files
dae16-VerhulstBram-GameProject/Game/Game.cpp

109 lines
2.3 KiB
C++

#include "pch.h"
#include "Game.h"
#include "utils.h"
Game::Game(const Window& window)
: BaseGame { window }
{
Initialize();
}
Game::~Game() {
Cleanup();
}
void Game::Initialize() {
m_WorldLevel = WorldLevel();
}
void Game::Cleanup() {
}
void Game::Update(float elapsedSec) {
const Uint8 *pStates = SDL_GetKeyboardState( nullptr );
if ( pStates[SDL_SCANCODE_RIGHT] ) {
m_CameraOffset.x += 100 * elapsedSec;
}
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();
}
void Game::ProcessKeyDownEvent(const SDL_KeyboardEvent& e) {
//std::cout << "KEYDOWN event: " << e.keysym.sym << std::endl;
}
void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
//std::cout << "KEYUP event: " << e.keysym.sym << std::endl;
//switch ( e.keysym.sym )
//{
//case SDLK_LEFT:
// //std::cout << "Left arrow key released\n";
// break;
//case SDLK_RIGHT:
// //std::cout << "`Right arrow key released\n";
// break;
//case SDLK_1:
//case SDLK_KP_1:
// //std::cout << "Key 1 released\n";
// break;
//}
}
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
//std::cout << "MOUSEMOTION event: " << e.x << ", " << e.y << std::endl;
}
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
//std::cout << "MOUSEBUTTONDOWN event: ";
//switch ( e.button )
//{
//case SDL_BUTTON_LEFT:
// std::cout << " left button " << std::endl;
// break;
//case SDL_BUTTON_RIGHT:
// std::cout << " right button " << std::endl;
// break;
//case SDL_BUTTON_MIDDLE:
// std::cout << " middle button " << std::endl;
// break;
//}
}
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
//std::cout << "MOUSEBUTTONUP event: ";
//switch ( e.button )
//{
//case SDL_BUTTON_LEFT:
// std::cout << " left button " << std::endl;
// break;
//case SDL_BUTTON_RIGHT:
// std::cout << " right button " << std::endl;
// break;
//case SDL_BUTTON_MIDDLE:
// std::cout << " middle button " << std::endl;
// break;
//}
}
void Game::ClearBackground() const {
glClearColor(0.0f, 0.0f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}