90 lines
2.0 KiB
C++
90 lines
2.0 KiB
C++
//
|
|
// Created by sfd on 2025/4/9.
|
|
//
|
|
|
|
#ifndef GAME_H
|
|
#define GAME_H
|
|
#include <map>
|
|
#include <SDL_render.h>
|
|
#include <SDL_ttf.h>
|
|
#include <string>
|
|
|
|
#include "Object.h"
|
|
#include "Scence/Scence.h"
|
|
|
|
|
|
class Game {
|
|
public:
|
|
static Game& getInstance();
|
|
~Game();
|
|
|
|
void init();
|
|
void run();
|
|
void changeScence(Scence* scence);
|
|
|
|
void handleEvents(SDL_Event &e);
|
|
void update(float deltatime);
|
|
void render();
|
|
void bgUpdate(float deltatime);
|
|
void renderBackground();
|
|
|
|
SDL_Window* getWindow() const { return window; }
|
|
SDL_Renderer* getRenderer() const { return renderer; }
|
|
int getWindowWidth() const { return windowWidth; }
|
|
int getWindowHeight() const { return windowHeight; }
|
|
|
|
//renderText
|
|
SDL_Point renderTextCenter(std::string text, float posY, bool isTitle = false, SDL_Color color = {255, 255, 255, 255});
|
|
void renderTextPos(std::string text, SDL_Point p, bool isLeft = true, SDL_Color color = {255, 255, 255, 255});
|
|
|
|
|
|
|
|
void insertIntoScoreBoard(int score, std::string name);
|
|
//getter
|
|
int getFinalScore() const { return finalScore; }
|
|
|
|
std::multimap<int, std::string, std::greater<int>> &getScoreBoard() { return scoreBoard; };
|
|
//setter
|
|
void setFinalScore(int finalScore) { this->finalScore = finalScore; }
|
|
|
|
void saveData();
|
|
void loadData();
|
|
|
|
private:
|
|
Game();
|
|
Game(const Game&) = delete;
|
|
Game& operator=(const Game&) = delete;
|
|
|
|
void clean();
|
|
|
|
bool running = true;
|
|
SDL_bool isFullScreen = SDL_FALSE;
|
|
Scence* currentScence = nullptr;
|
|
SDL_Window* window = nullptr;
|
|
SDL_Renderer* renderer = nullptr;
|
|
|
|
int windowWidth = 800;
|
|
int windowHeight = 600;
|
|
|
|
int finalScore = 0;
|
|
|
|
TTF_Font *titleFont = nullptr;
|
|
TTF_Font *messageFont = nullptr;
|
|
|
|
|
|
int FPS = 60;
|
|
float frameTime;
|
|
float deltaTime = 0; // s
|
|
|
|
Background nearBackground;
|
|
Background farBackground;
|
|
|
|
|
|
|
|
std::multimap<int, std::string, std::greater<int>> scoreBoard;
|
|
|
|
};
|
|
|
|
|
|
#endif //GAME_H
|