Started project, implemented keyboard and controller movement

This commit is contained in:
Sarah Faey 2025-04-17 22:53:25 +02:00
parent b1f5d882f0
commit d8fa53801b
33 changed files with 931 additions and 73 deletions

View file

@ -1,24 +1,48 @@
// SPDX-FileCopyrightText: 2025 <copyright holder> <email>
// SPDX-License-Identifier: MIT
#ifndef GAME_H
#define GAME_H
/**
* @todo write docs
*/
#include <map>
#include <memory>
#include <SDL3/SDL.h>
#include "GameCommands/GameCommand.h"
#include "GameCommands/AxisCommand.h"
#include "Actors/MovingActor.h"
class Game
{
public:
/**
* Default constructor
*/
Game();
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?
/**
* Destructor
*/
~Game();
bool m_running = true;
bool m_ButtonInput = 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;
const float c_NormalizedDiagonal = 1 / sqrt(2);
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;
};