Nimbin[12]?SDL & Graphics / mapcreator / src/game/game.hpp

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz
src/game/game.hpp 1.3 KB · 75 lines raw
#pragma once

#include <SDL3/SDL.h>
#include <SDL3/SDL_mouse.h>


#include <memory>
#include <cassert>
#include <iostream>

#include "game/state_modify.hpp"
#include "game/state_playing.hpp"
#include "game/state_menu_main.hpp"

#include "audio/audio.hpp"

class Input;
class AnimatedCursor;


enum class NewGameState_e {
    NONE,
    NEW,
    LOAD
};

// Game class encapsulating SDL initialization and loop
class Game {
public:
    Game();
    Game(Game&&);
    ~Game();

    SDL_Rect      win_size = {0,0,800, 600};
    SDL_Window*   window   = nullptr;
    SDL_Renderer* renderer = nullptr;

    Audio* audio = nullptr;

    AnimatedCursor* cursor = nullptr;

    bool is_cheating = false;

    std::unique_ptr<StatePlaying> state_playing;
    GameState*    state_current = nullptr;
    GameState_e   state_current_e = GameState_e::STATE_MENU_MAIN;
    std::unique_ptr<GameState> state_temp;

    std::string   active_game_dir = "game_saves";

    bool draw_frames = false;


    Uint64 lastTicks;
    bool running;

    Input input;

    bool state_changed = false;

    void set_State(GameState_e state, NewGameState_e game_state_e = NewGameState_e::NONE);

    void Run();

    bool Save(const std::string &path) const;
    bool Load(const std::string &path);

private:
    void handle_Events();

    void Update();

    void Render();
};