[Added] Services for assets and audio, main screen, simplified drawing, [Updated] Dockerfile, so the libraries get their own folder
This commit is contained in:
+10
-22
@@ -29,42 +29,30 @@ USER dev
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
RUN g++ --version
|
||||
|
||||
RUN git clone https://github.com/emscripten-core/emsdk.git && \
|
||||
cd emsdk && \
|
||||
RUN git clone https://github.com/emscripten-core/emsdk.git libs/emsdk && \
|
||||
cd libs/emsdk && \
|
||||
./emsdk install latest && \
|
||||
./emsdk activate latest && \
|
||||
cd ..
|
||||
cd ../..
|
||||
|
||||
RUN echo 'source "/app/emsdk/emsdk_env.sh"' >> $HOME/.bash_profile
|
||||
RUN echo 'source "/app/libs/emsdk/emsdk_env.sh"' >> $HOME/.bash_profile
|
||||
# RUN source "/app/emsdk/emsdk_env.sh"
|
||||
|
||||
RUN git clone https://github.com/raysan5/raylib.git raylib \
|
||||
&& cd raylib \
|
||||
RUN git clone https://github.com/raysan5/raylib.git libs/raylib \
|
||||
&& cd libs/raylib \
|
||||
&& mkdir build && cd build \
|
||||
&& cmake -DBUILD_SHARED_LIBS=OFF -DRAYLIB_STATIC=ON .. \
|
||||
&& make \
|
||||
&& sudo make install \
|
||||
&& cd ..
|
||||
&& cd ../..
|
||||
|
||||
# RUN mkdir dist
|
||||
# && cmake -DBUILD_SHARED_LIBS=ON .. \
|
||||
|
||||
ENV LD_LIBRARY_PATH=/app/raylib/build/raylib
|
||||
ENV LD_LIBRARY_PATH=/app/libs/raylib/build/raylib
|
||||
|
||||
# RUN cd raylib/src
|
||||
# # Builds raylib for WebAssembly usage
|
||||
# RUN emcc -c rcore.c -Os -Wall -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2
|
||||
# RUN emcc -c rshapes.c -Os -Wall -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2
|
||||
# RUN emcc -c rtextures.c -Os -Wall -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2
|
||||
# RUN emcc -c rtext.c -Os -Wall -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2
|
||||
# RUN emcc -c rmodels.c -Os -Wall -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2
|
||||
# RUN emcc -c utils.c -Os -Wall -DPLATFORM_WEB
|
||||
# RUN emcc -c raudio.c -Os -Wall -DPLATFORM_WEB
|
||||
# RUN emar rcs libraylib.a rcore.o rshapes.o rtextures.o rtext.o rmodels.o utils.o raudio.o
|
||||
# RUN cd ../..
|
||||
|
||||
RUN cd raylib/src && \
|
||||
source /app/emsdk/emsdk_env.sh && \
|
||||
RUN cd libs/raylib/src && \
|
||||
source /app/libs/emsdk/emsdk_env.sh && \
|
||||
emcc -c rcore.c -Os -Wall -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2 && \
|
||||
emcc -c rshapes.c -Os -Wall -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2 && \
|
||||
emcc -c rtextures.c -Os -Wall -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2 && \
|
||||
|
||||
Binary file not shown.
+19
-31
@@ -1,52 +1,40 @@
|
||||
#ifndef ASSET_SERVICE_H
|
||||
#define ASSET_SERVICE_H
|
||||
|
||||
#include "raylib.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "raylib.h"
|
||||
#include <unordered_map>
|
||||
#include "EFont.h"
|
||||
#include "EMusic.h"
|
||||
#include "Service.h"
|
||||
|
||||
class AssetService
|
||||
class AssetService: public Service<AssetService>
|
||||
{
|
||||
private:
|
||||
AssetService() {
|
||||
setAssets();
|
||||
};
|
||||
~AssetService() = default;
|
||||
/** Friend to allow access to the constructor */
|
||||
friend class Service<AssetService>;
|
||||
|
||||
std::string assetDir;
|
||||
std::vector<Font> fonts;
|
||||
std::unordered_map<EFont, std::string> 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;
|
||||
}
|
||||
std::unordered_map<EMusic, Music> 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);
|
||||
std::string getFontUrl(EFont font);
|
||||
protected:
|
||||
AssetService();
|
||||
|
||||
void setAssetDir(std::string assetDir);
|
||||
public:
|
||||
void setAssetDir(std::string assetDir){this->assetDir = assetDir;}
|
||||
|
||||
Font getFont(EFont font, int fontSize);
|
||||
Music getMusic(EMusic music) {
|
||||
return this->music[music];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef AUDIO_SERVICE_H
|
||||
#define AUDIO_SERVICE_H
|
||||
|
||||
#include "raylib.h"
|
||||
#include "EMusic.h"
|
||||
#include "Service.h"
|
||||
#include <optional>
|
||||
|
||||
class AudioService : public Service<AudioService>
|
||||
{
|
||||
private:
|
||||
/** Friend to allow access to the destructor */
|
||||
friend class Service<AudioService>;
|
||||
std::optional<Music> music;
|
||||
EMusic currentTrack;
|
||||
|
||||
protected:
|
||||
~AudioService();
|
||||
|
||||
public:
|
||||
void setMusic(EMusic music);
|
||||
std::optional<Music> getMusic(){return music;}
|
||||
EMusic getCurrentTrack(){return currentTrack;}
|
||||
void playMusic();
|
||||
void pauseMusic();
|
||||
void stopMusic();
|
||||
|
||||
void playSound();
|
||||
void stopSounds();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef EFONT_H
|
||||
#define EFONT_H
|
||||
|
||||
/**
|
||||
* All available fonts
|
||||
*/
|
||||
enum class EFont {
|
||||
GTEK,
|
||||
OXIN,
|
||||
RECKONER_BOLD,
|
||||
RECKONER,
|
||||
SANSATION,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef EMUSIC_H
|
||||
#define EMUSIC_H
|
||||
|
||||
enum class EMusic {
|
||||
NONE,
|
||||
MAIN,
|
||||
GAME,
|
||||
GAME_OVER
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef ESCREEN_H
|
||||
#define ESCREEN_H
|
||||
|
||||
/**
|
||||
* All possible screens that the game can be displaying
|
||||
*/
|
||||
enum class EScreen {
|
||||
TITLE,
|
||||
MAIN,
|
||||
TUTORIAL,
|
||||
GAME,
|
||||
PAUSE,
|
||||
GAMEOVER,
|
||||
VICTORY
|
||||
};
|
||||
|
||||
#endif
|
||||
+2
-10
@@ -7,21 +7,13 @@
|
||||
|
||||
class MainScreen : public Screen {
|
||||
private:
|
||||
Music bg;
|
||||
Font font1;
|
||||
Font font2;
|
||||
std::string assetDir;
|
||||
Vector2 dimTitle;
|
||||
Vector2 dimSub;
|
||||
Vector2 dimHead;
|
||||
int hoveredButton = 0;
|
||||
|
||||
void logic() override;
|
||||
void draw() override;
|
||||
public:
|
||||
MainScreen();
|
||||
~MainScreen();
|
||||
|
||||
void step() override;
|
||||
void logic() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
+16
-13
@@ -1,26 +1,29 @@
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
#include <vector>
|
||||
#include "Text.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();
|
||||
void handleMusic();
|
||||
|
||||
protected:
|
||||
std::vector<Text> text;
|
||||
|
||||
public:
|
||||
Screen();
|
||||
~Screen();
|
||||
|
||||
Screen(){}
|
||||
~Screen(){}
|
||||
|
||||
/**
|
||||
* One step of the game loop
|
||||
* Execute all logic for this frame
|
||||
*/
|
||||
virtual void step();
|
||||
virtual void logic() = 0;
|
||||
/**
|
||||
* Draw frame to the screen
|
||||
*/
|
||||
void draw();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef SCREENSTATE_H
|
||||
#define SCREENSTATE_H
|
||||
|
||||
enum class ScreenState {
|
||||
TITLE,
|
||||
MAIN,
|
||||
TUTORIAL,
|
||||
GAME,
|
||||
PAUSE,
|
||||
GAMEOVER,
|
||||
VICTORY
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef SERVICE_H
|
||||
#define SERVICE_H
|
||||
|
||||
template <typename T>
|
||||
class Service
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
static T* instance;
|
||||
Service() {}
|
||||
|
||||
public:
|
||||
Service(const Service &) = delete;
|
||||
Service &operator=(const Service &) = delete;
|
||||
|
||||
static T& getInstance()
|
||||
{
|
||||
static T instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
+12
-60
@@ -2,80 +2,32 @@
|
||||
#define STATE_SERVICE_H
|
||||
|
||||
#include "Screen.h"
|
||||
#include "ScreenState.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include "EScreen.h"
|
||||
#include "Service.h"
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
class StateService
|
||||
class StateService : public Service<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);
|
||||
void setScreen(EScreen screen);
|
||||
Screen *getScreen();
|
||||
|
||||
void gameloop();
|
||||
/**
|
||||
* Start the game loop
|
||||
*/
|
||||
void startGame();
|
||||
/**
|
||||
* One step of the gameloop
|
||||
*/
|
||||
void step();
|
||||
};
|
||||
|
||||
// StateService* StateService::instance = nullptr;
|
||||
|
||||
// std::unique_ptr<StateService> StateService::instance = nullptr;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef TEXT_H
|
||||
#define TEXT_H
|
||||
|
||||
#include "raylib.h"
|
||||
#include "EFont.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "AssetService.h"
|
||||
|
||||
class Text {
|
||||
private:
|
||||
std::string text;
|
||||
Font font;
|
||||
int fontSize;
|
||||
int spacing;
|
||||
Color color;
|
||||
Vector2 position;
|
||||
|
||||
public:
|
||||
Text(std::string text, EFont font, int fontSize = 30, int spacing = 0, Color color = WHITE, Vector2 position = {100,100});
|
||||
~Text();
|
||||
|
||||
Vector2 getDimensions();
|
||||
|
||||
void setPosition(Vector2 position) {
|
||||
this->position = position;
|
||||
}
|
||||
|
||||
void setColor(Color color) {
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
std::string getText() {
|
||||
return this->text;
|
||||
}
|
||||
|
||||
void setText(std::string text) {
|
||||
this->text = text;
|
||||
}
|
||||
|
||||
void draw();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,25 +3,22 @@
|
||||
|
||||
#include "Screen.h"
|
||||
#include "raylib.h"
|
||||
#include "Text.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TitleScreen : public Screen {
|
||||
private:
|
||||
Music bg;
|
||||
Font font1;
|
||||
Font font2;
|
||||
std::string assetDir;
|
||||
Vector2 dimTitle;
|
||||
Vector2 dimSub;
|
||||
Vector2 dimHead;
|
||||
// std::vector<Text> text;
|
||||
|
||||
void logic() override;
|
||||
void draw() override;
|
||||
public:
|
||||
TitleScreen();
|
||||
~TitleScreen();
|
||||
|
||||
void step() override;
|
||||
// void step() override;
|
||||
void logic() override;
|
||||
// void draw() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "Text.h"
|
||||
|
||||
Text::Text(std::string text, EFont font, int fontSize, int spacing, Color color, Vector2 position)
|
||||
{
|
||||
Font fnt = AssetService::getInstance().getFont(font, fontSize);
|
||||
|
||||
this->text = text;
|
||||
this->font = fnt;
|
||||
this->fontSize = fontSize;
|
||||
this->spacing = spacing;
|
||||
this->color = color;
|
||||
this->position = position;
|
||||
}
|
||||
|
||||
Text::~Text()
|
||||
{
|
||||
// Causes double free for some reason
|
||||
// UnloadFont(this->font);
|
||||
}
|
||||
|
||||
Vector2 Text::getDimensions()
|
||||
{
|
||||
return MeasureTextEx(font, text.c_str(), (float)fontSize, (float)spacing);
|
||||
}
|
||||
|
||||
void Text::draw()
|
||||
{
|
||||
DrawTextEx(font, text.c_str(), position, fontSize, spacing, color);
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
int main(void)
|
||||
{
|
||||
StateService& stateService = StateService::getInstance();
|
||||
stateService.gameloop();
|
||||
stateService.startGame();
|
||||
// std::cout << "StateService instance: " << service << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
+43
-36
@@ -1,46 +1,53 @@
|
||||
#include "MainScreen.h"
|
||||
#include "AssetService.h"
|
||||
#include "AudioService.h"
|
||||
#include <iostream>
|
||||
|
||||
MainScreen::MainScreen() {
|
||||
assetDir = "assets";
|
||||
font1 = LoadFontEx((assetDir+"/Fonts/Reckoner_Bold.ttf").c_str(), 100,0,0);
|
||||
SetTextureFilter(font1.texture, TEXTURE_FILTER_BILINEAR);
|
||||
font2 = LoadFont((assetDir+"/Fonts/Sansation.ttf").c_str());
|
||||
SetTextureFilter(font2.texture, TEXTURE_FILTER_BILINEAR);
|
||||
dimTitle = MeasureTextEx(font1, "Jelly sadsdsdsdrescue", 100,0);
|
||||
dimSub = MeasureTextEx(font2, "Press Entsder to continue", 30,0);
|
||||
dimHead = MeasureTextEx(font2, "Made by Ian Vink", 20,0);
|
||||
bg = LoadMusicStream((assetDir+"/Audio/Music/Crash_WarpRoomTheme.ogg").c_str());
|
||||
bg.looping = true;
|
||||
SetMasterVolume(1.0f);
|
||||
SetMusicVolume(bg,1.0f);
|
||||
PlayMusicStream(bg);
|
||||
MainScreen::MainScreen()
|
||||
{
|
||||
const int TOP_GAP = 100;
|
||||
const int BOTTOM_GAP = 50;
|
||||
const int AMNT_OF_BUTTONS = 4;
|
||||
const int TOTAL_SPACE = GetScreenHeight() - (TOP_GAP + BOTTOM_GAP);
|
||||
const int SPACE_PER_ITEM = TOTAL_SPACE / AMNT_OF_BUTTONS;
|
||||
|
||||
for (int i = 0; i < AMNT_OF_BUTTONS; i++)
|
||||
{
|
||||
Text txt = Text("new game", EFont::GTEK, 30, 0, WHITE);
|
||||
text.push_back(txt);
|
||||
}
|
||||
|
||||
text[0].setColor(RED);
|
||||
text[1].setText("load game");
|
||||
text[2].setText("tutorial");
|
||||
text[3].setText("quit");
|
||||
|
||||
for (int i = 0; i < AMNT_OF_BUTTONS; i++)
|
||||
{
|
||||
text[i].setPosition({(float)(GetScreenWidth() - text[i].getDimensions().x) / 2.0f, (float)TOP_GAP + SPACE_PER_ITEM * i});
|
||||
}
|
||||
|
||||
/** Will be ignored if already active (like when coming from the TitleScreen) */
|
||||
AudioService::getInstance().setMusic(EMusic::MAIN);
|
||||
AudioService::getInstance().playMusic();
|
||||
}
|
||||
|
||||
MainScreen::~MainScreen() {
|
||||
UnloadMusicStream(bg);
|
||||
UnloadFont(font1);
|
||||
UnloadFont(font2);
|
||||
MainScreen::~MainScreen()
|
||||
{
|
||||
}
|
||||
|
||||
void MainScreen::step() {
|
||||
draw();
|
||||
logic();
|
||||
}
|
||||
void MainScreen::logic()
|
||||
{
|
||||
if (IsKeyPressed(KEY_DOWN) || IsKeyPressed(KEY_UP))
|
||||
{
|
||||
text[hoveredButton].setColor(WHITE);
|
||||
/** Move up or down depending on the pressed button. +4 is used so that -1 becomes 3 (the last button) */
|
||||
hoveredButton = ((hoveredButton - (IsKeyPressed(KEY_DOWN) ? -1 : 1)) + 4) % 4;
|
||||
text[hoveredButton].setColor(RED);
|
||||
}
|
||||
|
||||
void MainScreen::logic() {
|
||||
// if(IsKeyPressed(KEY_ENTER)) {
|
||||
// std::cout << "Next screen!" << std::endl;
|
||||
// }
|
||||
}
|
||||
|
||||
void MainScreen::draw() {
|
||||
UpdateMusicStream(bg);
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
DrawTextEx(font2,"Made by Ian Vink", {((float)GetScreenWidth()-dimHead.x)/1.2f, (float(GetScreenHeight()-dimHead.y)/6.0f)}, 20, 0, WHITE);
|
||||
DrawTextEx(font1,"Jelly rescue", {((float)GetScreenWidth()-dimTitle.x)/2.0f, (float(GetScreenHeight()-dimTitle.y)/2.0f)}, 100,0, {255,25,25,255});
|
||||
DrawTextEx(font2,"Press Enter to continue", {((float)GetScreenWidth()-dimSub.x)/2.0f, (float(GetScreenHeight()-dimSub.y)/1.5f)}, 30, 0, WHITE);
|
||||
EndDrawing();
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
std::cout << text[hoveredButton].getText() << std::endl;
|
||||
}
|
||||
}
|
||||
+21
-16
@@ -1,22 +1,27 @@
|
||||
#include "Screen.h"
|
||||
#include <iostream>
|
||||
|
||||
Screen::Screen() {
|
||||
#include "AudioService.h"
|
||||
#include <optional>
|
||||
|
||||
void Screen::handleMusic()
|
||||
{
|
||||
std::optional<Music> music = AudioService::getInstance().getMusic();
|
||||
if(music.has_value()) {
|
||||
UpdateMusicStream(music.value());
|
||||
}
|
||||
}
|
||||
|
||||
Screen::~Screen() {
|
||||
void Screen::draw()
|
||||
{
|
||||
handleMusic();
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
}
|
||||
|
||||
void Screen::step() {
|
||||
|
||||
}
|
||||
|
||||
void Screen::logic() {
|
||||
|
||||
}
|
||||
|
||||
void Screen::draw() {
|
||||
std::cout << "DURAWU" << std::endl;
|
||||
if (text.size() > 0)
|
||||
{
|
||||
for (int t = 0; t < text.size(); t++)
|
||||
{
|
||||
text[t].draw();
|
||||
}
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
+41
-36
@@ -1,48 +1,53 @@
|
||||
#include "TitleScreen.h"
|
||||
#include "AssetService.h"
|
||||
#include "StateService.h"
|
||||
#include "EFont.h"
|
||||
#include "AudioService.h"
|
||||
#include <iostream>
|
||||
|
||||
TitleScreen::TitleScreen() {
|
||||
assetDir = "assets";
|
||||
font1 = LoadFontEx((assetDir+"/Fonts/Reckoner_Bold.ttf").c_str(), 100,0,0);
|
||||
SetTextureFilter(font1.texture, TEXTURE_FILTER_BILINEAR);
|
||||
font2 = LoadFont((assetDir+"/Fonts/Sansation.ttf").c_str());
|
||||
SetTextureFilter(font2.texture, TEXTURE_FILTER_BILINEAR);
|
||||
dimTitle = MeasureTextEx(font1, "Jelly rescue", 100,0);
|
||||
dimSub = MeasureTextEx(font2, "Press Enter to continue", 30,0);
|
||||
dimHead = MeasureTextEx(font2, "Made by Ian Vink", 20,0);
|
||||
bg = LoadMusicStream((assetDir+"/Audio/Music/Crash_WarpRoomTheme.ogg").c_str());
|
||||
bg.looping = true;
|
||||
SetMasterVolume(1.0f);
|
||||
SetMusicVolume(bg,1.0f);
|
||||
PlayMusicStream(bg);
|
||||
TitleScreen::TitleScreen()
|
||||
{
|
||||
Text textAbout = Text("Made by Ian Vink", EFont::SANSATION, 20,0, WHITE);
|
||||
textAbout.setPosition({
|
||||
(float)(GetScreenWidth()-textAbout.getDimensions().x)/1.2f,
|
||||
(float)(GetScreenHeight()-textAbout.getDimensions().y)/6.0f
|
||||
});
|
||||
Text textCenter = Text("Jelly rescue", EFont::RECKONER_BOLD, 100, 0, {255,25,25,255});
|
||||
textCenter.setPosition({
|
||||
(float)(GetScreenWidth()-textCenter.getDimensions().x)/2.0f,
|
||||
(float)(GetScreenHeight()-textCenter.getDimensions().y)/2.0f
|
||||
});
|
||||
Text testSub = Text("Press Enter", EFont::SANSATION, 30, 0, WHITE);
|
||||
testSub.setPosition({
|
||||
(float)(GetScreenWidth()-testSub.getDimensions().x)/2.0f,
|
||||
(float)(GetScreenHeight()-testSub.getDimensions().y)/1.5f
|
||||
});
|
||||
|
||||
text.push_back(textAbout);
|
||||
text.push_back(textCenter);
|
||||
text.push_back(testSub);
|
||||
|
||||
|
||||
AudioService::getInstance().setMusic(EMusic::MAIN);
|
||||
AudioService::getInstance().playMusic();
|
||||
|
||||
// bg = LoadMusicStream("assets/Audio/Music/Crash_WarpRoomTheme.ogg");
|
||||
// bg.looping = true;
|
||||
// SetMasterVolume(1.0f);
|
||||
// SetMusicVolume(bg, 1.0f);
|
||||
// PlayMusicStream(bg);
|
||||
}
|
||||
|
||||
TitleScreen::~TitleScreen() {
|
||||
UnloadMusicStream(bg);
|
||||
UnloadFont(font1);
|
||||
UnloadFont(font2);
|
||||
TitleScreen::~TitleScreen()
|
||||
{
|
||||
// UnloadMusicStream(bg);
|
||||
}
|
||||
|
||||
void TitleScreen::step() {
|
||||
draw();
|
||||
logic();
|
||||
}
|
||||
|
||||
void TitleScreen::logic() {
|
||||
if(IsKeyPressed(KEY_ENTER)) {
|
||||
StateService::getInstance().setScreen(ScreenState::MAIN);
|
||||
void TitleScreen::logic()
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
StateService::getInstance().setScreen(EScreen::MAIN);
|
||||
// std::cout << "Next screen!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void TitleScreen::draw() {
|
||||
UpdateMusicStream(bg);
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
DrawTextEx(font2,"Made by Ian Vink", {((float)GetScreenWidth()-dimHead.x)/1.2f, (float(GetScreenHeight()-dimHead.y)/6.0f)}, 20, 0, WHITE);
|
||||
DrawTextEx(font1,"Jelly rescue", {((float)GetScreenWidth()-dimTitle.x)/2.0f, (float(GetScreenHeight()-dimTitle.y)/2.0f)}, 100,0, {255,25,25,255});
|
||||
DrawTextEx(font2,"Press Enter to continue", {((float)GetScreenWidth()-dimSub.x)/2.0f, (float(GetScreenHeight()-dimSub.y)/1.5f)}, 30, 0, WHITE);
|
||||
EndDrawing();
|
||||
}
|
||||
@@ -1,33 +1,41 @@
|
||||
#include "AssetService.h"
|
||||
#include <iostream>
|
||||
|
||||
void AssetService::setAssetDir(std::string newDir) {
|
||||
assetDir = newDir;
|
||||
}
|
||||
|
||||
void AssetService::setAssets() {
|
||||
AssetService::AssetService()
|
||||
{
|
||||
setAssetDir("assets/");
|
||||
|
||||
fonts.push_back(loadFont("Fonts/Gtek.ttf"));
|
||||
fonts.push_back(loadFont("Fonts/Oxin.ttf"));
|
||||
fonts.push_back(loadFont("Fonts/Reckoner_Bold.ttf"));
|
||||
fonts.push_back(loadFont("Fonts/Reckoner.ttf"));
|
||||
fonts.push_back(loadFont("Fonts/Sansation.ttf"));
|
||||
|
||||
music.push_back(loadMusic("Audio/Music/Crash_WarpRoomTheme.ogg", true));
|
||||
setAssets();
|
||||
}
|
||||
|
||||
Font AssetService::loadFont(std::string filename, int fontSize) {
|
||||
Font font = LoadFontEx((assetDir + filename).c_str(), fontSize,0,0);
|
||||
return font;
|
||||
|
||||
void AssetService::setAssets()
|
||||
{
|
||||
fonts[EFont::GTEK] = "Fonts/Gtek.ttf";
|
||||
fonts[EFont::OXIN] = "Fonts/Oxin.ttf";
|
||||
fonts[EFont::RECKONER_BOLD] = "Fonts/Reckoner_Bold.ttf";
|
||||
fonts[EFont::RECKONER] = "Fonts/Reckoner.ttf";
|
||||
fonts[EFont::SANSATION] = "Fonts/Sansation.ttf";
|
||||
|
||||
music[EMusic::MAIN] = loadMusic("Audio/Music/Crash_WarpRoomTheme.ogg", true);
|
||||
music[EMusic::GAME] = loadMusic("Audio/Music/GameTheme_2.ogg", true);
|
||||
music[EMusic::GAME_OVER] = loadMusic("Audio/Music/gameOverTheme.ogg", false);
|
||||
}
|
||||
|
||||
Font AssetService::loadFont(std::string filename) {
|
||||
Font font = LoadFont((assetDir + filename).c_str());
|
||||
return font;
|
||||
Font AssetService::getFont(EFont font, int fontSize)
|
||||
{
|
||||
std::string fontUrl = getFontUrl(font);
|
||||
Font fnt = LoadFontEx(fontUrl.c_str(), fontSize, 0, 0);
|
||||
SetTextureFilter(fnt.texture, TEXTURE_FILTER_BILINEAR);
|
||||
return fnt;
|
||||
}
|
||||
|
||||
Music AssetService::loadMusic(std::string filename, bool loops) {
|
||||
std::string AssetService::getFontUrl(EFont font)
|
||||
{
|
||||
return assetDir + fonts[font];
|
||||
}
|
||||
|
||||
Music AssetService::loadMusic(std::string filename, bool loops)
|
||||
{
|
||||
Music music = LoadMusicStream((assetDir + filename).c_str());
|
||||
music.looping = loops;
|
||||
return music;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "AudioService.h"
|
||||
#include "AssetService.h"
|
||||
|
||||
AudioService::~AudioService()
|
||||
{
|
||||
if (!music.has_value())
|
||||
return;
|
||||
UnloadMusicStream(music.value());
|
||||
}
|
||||
|
||||
void AudioService::setMusic(EMusic music)
|
||||
{
|
||||
if (currentTrack == music)
|
||||
return;
|
||||
|
||||
this->currentTrack = music;
|
||||
this->music = AssetService::getInstance().getMusic(music);
|
||||
}
|
||||
|
||||
void AudioService::playMusic()
|
||||
{
|
||||
if (!music.has_value())
|
||||
return;
|
||||
PlayMusicStream(music.value());
|
||||
}
|
||||
|
||||
void AudioService::pauseMusic()
|
||||
{
|
||||
if (!music.has_value())
|
||||
return;
|
||||
PauseMusicStream(music.value());
|
||||
}
|
||||
|
||||
void AudioService::stopMusic()
|
||||
{
|
||||
if (music.has_value())
|
||||
{
|
||||
StopMusicStream(music.value());
|
||||
}
|
||||
this->currentTrack = EMusic::NONE;
|
||||
}
|
||||
|
||||
void AudioService::playSound()
|
||||
{
|
||||
}
|
||||
|
||||
void AudioService::stopSounds()
|
||||
{
|
||||
}
|
||||
@@ -3,48 +3,50 @@
|
||||
#include "TitleScreen.h"
|
||||
#include "MainScreen.h"
|
||||
|
||||
StateService* StateService::instance = nullptr;
|
||||
|
||||
void StateService::setScreen(ScreenState state)
|
||||
void StateService::setScreen(EScreen state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case ScreenState::TITLE:
|
||||
case EScreen::TITLE:
|
||||
currentScreen = std::make_unique<TitleScreen>();
|
||||
break;
|
||||
case ScreenState::MAIN:
|
||||
case EScreen::MAIN:
|
||||
currentScreen = std::make_unique<MainScreen>();
|
||||
break;
|
||||
default:
|
||||
currentScreen = std::make_unique<TitleScreen>(); // Default case
|
||||
currentScreen = std::make_unique<TitleScreen>();
|
||||
}
|
||||
// currentScreen = screen;
|
||||
}
|
||||
|
||||
Screen* StateService::getScreen()
|
||||
Screen *StateService::getScreen()
|
||||
{
|
||||
return currentScreen.get();
|
||||
}
|
||||
|
||||
void StateService::gameloop()
|
||||
void StateService::startGame()
|
||||
{
|
||||
InitAudioDevice();
|
||||
InitWindow(640, 544, "Jelly Rescue");
|
||||
SetTargetFPS(60);
|
||||
|
||||
setScreen(ScreenState::TITLE);
|
||||
setScreen(EScreen::TITLE);
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(currentScreen->step, 0, 1);
|
||||
emscripten_set_main_loop(step, 0, 1);
|
||||
#else
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
currentScreen->step();
|
||||
// UpdateDrawFrame();
|
||||
step();
|
||||
}
|
||||
#endif
|
||||
|
||||
CloseWindow();
|
||||
CloseAudioDevice();
|
||||
}
|
||||
|
||||
void StateService::step()
|
||||
{
|
||||
currentScreen->draw();
|
||||
currentScreen->logic();
|
||||
}
|
||||
Reference in New Issue
Block a user