[Added] Headerfiles
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#ifndef ASSET_SERVICE_H
|
||||
#define ASSET_SERVICE_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "raylib.h"
|
||||
|
||||
class AssetService
|
||||
{
|
||||
private:
|
||||
AssetService() {
|
||||
setAssets();
|
||||
};
|
||||
~AssetService() = default;
|
||||
|
||||
std::string assetDir;
|
||||
std::vector<Font> fonts;
|
||||
std::vector<Sound> sounds;
|
||||
std::vector<Music> music;
|
||||
public:
|
||||
AssetService(const AssetService&) = delete;
|
||||
AssetService& operator=(const AssetService&) = delete;
|
||||
|
||||
static AssetService& getInstance() {
|
||||
static AssetService instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::vector<Font> getFonts() {
|
||||
return fonts;
|
||||
}
|
||||
|
||||
std::vector<Sound> getSounds() {
|
||||
return sounds;
|
||||
}
|
||||
|
||||
std::vector<Music> getMusic() {
|
||||
return music;
|
||||
}
|
||||
|
||||
void setAssets();
|
||||
|
||||
Font loadFont(std::string filename, int fontSize);
|
||||
Font loadFont(std::string filename);
|
||||
Music loadMusic(std::string filename, bool loops);
|
||||
Sound loadSound(std::string filename);
|
||||
|
||||
void setAssetDir(std::string assetDir);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef MAIN_SCREEN_H
|
||||
#define MAIN_SCREEN_H
|
||||
|
||||
#include "Screen.h"
|
||||
#include "raylib.h"
|
||||
#include <string>
|
||||
|
||||
class MainScreen : public Screen {
|
||||
private:
|
||||
Music bg;
|
||||
Font font1;
|
||||
Font font2;
|
||||
std::string assetDir;
|
||||
Vector2 dimTitle;
|
||||
Vector2 dimSub;
|
||||
Vector2 dimHead;
|
||||
|
||||
void logic() override;
|
||||
void draw() override;
|
||||
public:
|
||||
MainScreen();
|
||||
~MainScreen();
|
||||
|
||||
void step() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
class Screen {
|
||||
private:
|
||||
|
||||
/**
|
||||
* All the logic that concerns the screen currently visible to the player
|
||||
*/
|
||||
virtual void logic();
|
||||
/**
|
||||
* Draws everything for the current screen
|
||||
*/
|
||||
virtual void draw();
|
||||
public:
|
||||
Screen();
|
||||
~Screen();
|
||||
|
||||
|
||||
/**
|
||||
* One step of the game loop
|
||||
*/
|
||||
virtual void step();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef SCREENSTATE_H
|
||||
#define SCREENSTATE_H
|
||||
|
||||
enum class ScreenState {
|
||||
TITLE,
|
||||
MAIN,
|
||||
TUTORIAL,
|
||||
GAME,
|
||||
PAUSE,
|
||||
GAMEOVER,
|
||||
VICTORY
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,81 @@
|
||||
#ifndef STATE_SERVICE_H
|
||||
#define STATE_SERVICE_H
|
||||
|
||||
#include "Screen.h"
|
||||
#include "ScreenState.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
class StateService
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<Screen> currentScreen;
|
||||
|
||||
static StateService* instance;
|
||||
// StateService() {}
|
||||
|
||||
// StateService() = default;
|
||||
// friend StateService* StateService::getInstance();
|
||||
StateService()
|
||||
{
|
||||
std::cout << "Singleton instance created."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
// Private destructor to prevent external deletion
|
||||
~StateService()
|
||||
{
|
||||
std::cout << "Singleton instance destroyed."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
public:
|
||||
StateService(const StateService&) = delete;
|
||||
StateService& operator=(const StateService&) = delete;
|
||||
// ~StateService() = default;
|
||||
// StateService(const StateService &) = delete;
|
||||
// StateService &operator=(const StateService &) = delete;
|
||||
|
||||
// StateService& myStateService = StateService::instance();
|
||||
// StateService(const StateService&) = delete;
|
||||
// StateService& operator=(const StateService&) = delete;
|
||||
|
||||
// static StateService* getInstance();
|
||||
|
||||
// static std::shared_ptr<StateService> getInstance() {
|
||||
// static std::shared_ptr<StateService> instance = std::make_shared<StateService>();
|
||||
// return instance;
|
||||
// }
|
||||
static StateService& getInstance()
|
||||
{
|
||||
if (instance == nullptr) {
|
||||
instance = new StateService();
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
|
||||
// static StateService* getInstance();
|
||||
|
||||
// {
|
||||
// if (!instance)
|
||||
// {
|
||||
// instance = std::make_unique<StateService>(); // This works because of the friend declaration
|
||||
// }
|
||||
// return instance.get(); // Return the raw pointer of the unique_ptr
|
||||
// }
|
||||
|
||||
void setScreen(ScreenState screen);
|
||||
Screen *getScreen();
|
||||
|
||||
void gameloop();
|
||||
};
|
||||
|
||||
// StateService* StateService::instance = nullptr;
|
||||
|
||||
// std::unique_ptr<StateService> StateService::instance = nullptr;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef TITLE_SCREEN_H
|
||||
#define TITLE_SCREEN_H
|
||||
|
||||
#include "Screen.h"
|
||||
#include "raylib.h"
|
||||
#include <string>
|
||||
|
||||
class TitleScreen : public Screen {
|
||||
private:
|
||||
Music bg;
|
||||
Font font1;
|
||||
Font font2;
|
||||
std::string assetDir;
|
||||
Vector2 dimTitle;
|
||||
Vector2 dimSub;
|
||||
Vector2 dimHead;
|
||||
|
||||
void logic() override;
|
||||
void draw() override;
|
||||
public:
|
||||
TitleScreen();
|
||||
~TitleScreen();
|
||||
|
||||
void step() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user