51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
#ifndef GAME_H
|
|
#define GAME_H
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <SDL3/SDL.h>
|
|
#include "GameCommands/GameCommand.h"
|
|
#include "GameCommands/AxisCommand.h"
|
|
#include "Actors/MovingActor.h"
|
|
#include "DataStructures/DirectionButtonStatus.h"
|
|
|
|
class Game
|
|
{
|
|
public:
|
|
Game(SDL_Window *window, SDL_Renderer *renderer);
|
|
~Game() {};
|
|
void Run();
|
|
void HandleMovement();
|
|
void HandleKeyboardInput(const SDL_Event &event);
|
|
void HandleGamepadButton(const SDL_Event &event);
|
|
void HandleGamepadAxis(const SDL_Event &event);
|
|
void AddGamepad(SDL_JoystickID id);
|
|
void RemoveGamepad(SDL_JoystickID id);
|
|
void EndGame();
|
|
private:
|
|
const float c_GamepadAxisDeadzone = 0.2; //TODO: make this a setting?
|
|
|
|
bool m_running = true;
|
|
uint64_t m_TickCount;
|
|
std::map<SDL_Scancode, GameCommand*> m_KeyboardCommandMap;
|
|
std::map<SDL_GamepadButton, GameCommand*> m_Gamepad1ButtonCommandMap;
|
|
std::map<SDL_GamepadButton, GameCommand*> m_Gamepad2ButtonCommandMap;
|
|
std::map<SDL_GamepadAxis, AxisCommand*> m_Gamepad1AxisCommandMap;
|
|
std::map<SDL_GamepadAxis, AxisCommand*> m_Gamepad2AxisCommandMap;
|
|
|
|
std::shared_ptr<MovingActor> m_Player1;
|
|
std::shared_ptr<MovingActor> m_Player2;
|
|
SDL_FPoint m_Player1DirectionInput;
|
|
SDL_FPoint m_Player2DirectionInput;
|
|
DirectionButtonStatus m_Player1DirectionButtonStatus;
|
|
DirectionButtonStatus m_Player2DirectionButtonStatus;
|
|
|
|
std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> m_Window;
|
|
std::unique_ptr<SDL_Renderer, decltype(&SDL_DestroyRenderer)> m_Renderer;
|
|
std::unique_ptr<SDL_Gamepad, decltype(&SDL_CloseGamepad)> m_Gamepad1;
|
|
//std::unique_ptr<SDL_Gamepad, decltype(&SDL_CloseGamepad)> m_Gamepad2;
|
|
|
|
};
|
|
|
|
#endif // GAME_H
|
|
|