FINAL: v1
This commit is contained in:
@@ -4,12 +4,19 @@
|
||||
#include <renderer/texture.hpp>
|
||||
#include <renderer/font.hpp>
|
||||
#include <object/sound.hpp>
|
||||
#include <game/gamemanager.hpp>
|
||||
#include <game/agame/enemy.hpp>
|
||||
#include <game/agame/trash.hpp>
|
||||
|
||||
namespace Game::AGame {
|
||||
GAME_ENTITY(Background)
|
||||
public:
|
||||
void onWindowResized(int newWidth, int newHeight) override;
|
||||
private:
|
||||
Object::Sound mSound;
|
||||
float mEnemySpawnTimer = 0.f;
|
||||
float mTimeToSpawn = 5.f;
|
||||
int mW, mH;
|
||||
std::shared_ptr<Game::Renderer::Texture> mEnemyTex;
|
||||
std::shared_ptr<Game::Renderer::Texture> mTrashTex;
|
||||
END_GAME_ENTITY()
|
||||
}
|
||||
12
include/game/agame/enemy.hpp
Normal file
12
include/game/agame/enemy.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <game/gamemanager.hpp>
|
||||
#include <object/entity.hpp>
|
||||
#include <renderer/texture.hpp>
|
||||
#include <renderer/font.hpp>
|
||||
#include <object/sound.hpp>
|
||||
|
||||
namespace Game::AGame {
|
||||
GAME_ENTITY(Enemy)
|
||||
END_GAME_ENTITY()
|
||||
}
|
||||
@@ -10,5 +10,6 @@ GAME_ENTITY(Player)
|
||||
private:
|
||||
Object::Sound mSound;
|
||||
float mSpeed = 200.f; // Pixels per second
|
||||
float mHealth = 100.f;
|
||||
END_GAME_ENTITY()
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <shared_mutex>
|
||||
#include <random>
|
||||
#include <cstdlib>
|
||||
|
||||
#define DISABLE_COPY(Class) \
|
||||
Class(const Class&) = delete; \
|
||||
@@ -46,4 +49,19 @@
|
||||
#define TARGET_FPS 60
|
||||
#define TARGET_UPDATE_RATE 120
|
||||
#define ENABLE_LOW_LATENCY_VSYNC 1
|
||||
#define VSYNC_FPS_OFFSET 2
|
||||
#define VSYNC_FPS_OFFSET 2
|
||||
|
||||
class Utils {
|
||||
public:
|
||||
static Utils& getUtils() { static Utils instance; return instance; }
|
||||
// Random in range 32 bits
|
||||
int rirng32(int a, int b) {
|
||||
std::lock_guard lock(mMutex);
|
||||
std::mt19937 mGen(mRd());
|
||||
std::uniform_int_distribution<> distr(a, b);
|
||||
return distr(mGen);
|
||||
}
|
||||
private:
|
||||
mutable std::shared_mutex mMutex;
|
||||
std::random_device mRd;
|
||||
};
|
||||
@@ -27,7 +27,6 @@ namespace Game::Window {
|
||||
int getTargetFPS() { return mTargetFPS; }
|
||||
|
||||
static SDL_Window* getSDLWindowBackend() { std::scoped_lock lock(sMutex); return sWindowBackend; }
|
||||
|
||||
Renderer::Renderer* getRenderer() { std::scoped_lock lock(mMutex); return &mRenderer; }
|
||||
|
||||
private:
|
||||
@@ -39,6 +38,8 @@ namespace Game::Window {
|
||||
Game::GameManager mGameManager;
|
||||
std::jthread mGameThread;
|
||||
bool mRunning;
|
||||
int mLastWindowWidth = 0;
|
||||
int mLastWindowHeight = 0;
|
||||
int mTargetFPS = TARGET_FPS;
|
||||
int mEffectiveFrameCap = TARGET_FPS;
|
||||
#if DEBUG
|
||||
|
||||
Reference in New Issue
Block a user