chore: uodate breakout, constant, game.cpp and hpp

This commit is contained in:
Krzysztof Rudnicki 2023-07-11 18:18:44 +02:00
parent d857bf7016
commit ce05bca9c4
4 changed files with 42 additions and 14 deletions

View File

@ -9,6 +9,7 @@
#include "../dependencies/include/glad/glad.h"
#include "./game.hpp"
#include "./resourceManager.hpp"
#include "./constants.hpp"
// GLFW function declarations
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
@ -150,7 +151,7 @@ void key_callback_sad(int key) {
void key_callback(GLFWwindow *window, int key, int /*scancode*/, int action,
int /*mode*/) {
// Define the array type for keys
const int MAX_KEYS_TRACKED = 1024;
const int MAX_KEYS_TRACKED = constants::MAX_KEYS_TRACKED;
using KeyArray = std::array<bool, MAX_KEYS_TRACKED>;
exit_window(window, key, action);
if (key >= 0 && key < MAX_KEYS_TRACKED) {

10
breakout/constants.hpp Normal file
View File

@ -0,0 +1,10 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef BREAKOUT_CONSTANTS_HPP_
#define BREAKOUT_CONSTANTS_HPP_
namespace constants {
constexpr int MAX_KEYS_TRACKED { 1024 };
constexpr int GAME_WINDOW_SIZE_ALLIGNMENT { 8 };
}
#endif // BREAKOUT_CONSTANTS_HPP_

View File

@ -3,14 +3,17 @@
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_CPP
#include "../breakout/game.hpp"
Game::Game(unsigned int width, unsigned int height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height) {}
Game::Game(GameWindowSize size)
: State(GAME_ACTIVE), Keys(), Width(size.width), Height(size.height) {
}
void Game::Init() {}
void Game::Update(double dt) {}
void Game::Update(double deltaTime) {}
void Game::ProcessInput(double dt) {}
void Game::ProcessInput(double deltaTime) {}
void Game::Render() {}

View File

@ -1,30 +1,44 @@
// Copyright [2023] Krzysztof Rudnicki
#ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_HPP
#define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_HPP
#include <array>
#ifndef BREAKOUT_GAME_HPP_
#define BREAKOUT_GAME_HPP_
#include <GLFW/glfw3.h>
#include <array>
#include "../dependencies/include/glad/glad.h"
#include "./constants.hpp"
struct GameWindowSize {
unsigned int width;
unsigned int height;
} __attribute__((aligned(constants::GAME_WINDOW_SIZE_ALLIGNMENT)));
// Represents the current state of the game
enum GameState { GAME_ACTIVE, GAME_MENU, GAME_WIN };
class Game {
public:
private:
// game state
GameState State;
std::array<bool, 1024> Keys;
std::array<bool, constants::MAX_KEYS_TRACKED> Keys;
unsigned int Width, Height;
public:
// constructor/destructor
Game(unsigned int width, unsigned int height);
explicit Game(GameWindowSize size);
~Game() = default;
// rule of five
Game(const Game& other) = delete;
Game& operator=(const Game& other) = delete;
Game(Game&& other) noexcept = delete;
Game& operator=(Game&& other) noexcept = delete;
// initialize game state (load all shaders/textures/levels)
void Init();
// game loop
void ProcessInput(double dt);
void Update(double dt);
void ProcessInput(double deltaTime);
void Update(double deltaTime);
void Render();
};
#endif // HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_GAME_HPP
#endif // BREAKOUT_GAME_HPP_