diff --git a/include/Background.h b/include/entities/Background.h similarity index 69% rename from include/Background.h rename to include/entities/Background.h index 573ebe3..dc9ad8b 100644 --- a/include/Background.h +++ b/include/entities/Background.h @@ -2,11 +2,11 @@ #define BACKGROUND_H #include "raylib.h" -#include "EBackground.h" +#include "enums/EBackground.h" #include -#include "TextureWrapper.h" -#include "AssetService.h" -#include "StateService.h" +#include "entities/TextureWrapper.h" +#include "services/AssetService.h" +#include "services/StateService.h" class Background { public: @@ -14,8 +14,9 @@ class Background { } Background(EBackground background){ - Texture2D texture = AssetService::getInstance().getBackground(background); - TextureWrapper wrapper = TextureWrapper(texture, StateService::getInstance().getScreenSize(), {0,0}); + // Texture2D texture = AssetService::getInstance().getBackground(background); + TextureWrapper wrapper = TextureWrapper(AssetService::getInstance().getBackground(background), StateService::getInstance().getScreenSize(), {0,0}); + wrapper.setSourceRect({0,0,wrapper.getSize().x, wrapper.getSize().y}); textures.push_back(wrapper); } Background(std::vector backgrounds){ diff --git a/include/Game.h b/include/entities/Game.h similarity index 90% rename from include/Game.h rename to include/entities/Game.h index c8f6759..19eb456 100644 --- a/include/Game.h +++ b/include/entities/Game.h @@ -1,9 +1,10 @@ #ifndef GAME_H #define GAME_H -#include "Map.h" -#include "Background.h" -#include "StateService.h" +#include "entities/Map.h" +#include "entities/Background.h" +#include "services/StateService.h" +#include "services/AudioService.h" class Game { @@ -16,7 +17,7 @@ public: wrapper2.setSourceRect({0,200,wrapper2.getSize().x, 200+wrapper2.getSize().y}); TextureWrapper wrapper3 = TextureWrapper(AssetService::getInstance().getBackground(EBackground::GAME3), {1792.0f,(float)GetScreenHeight()}, {wrapper1.getSize().x+wrapper2.getSize().x,0.0}); wrapper3.setSourceRect({64,200,64+wrapper3.getSize().x, 200+wrapper3.getSize().y}); - + std::vector wrappers; wrappers.push_back(wrapper1); wrappers.push_back(wrapper2); @@ -31,6 +32,9 @@ public: camera.rotation = 0.0f; camera.zoom = 1.0f; this->camera = camera; + + AudioService::getInstance().setMusic(EMusic::GAME); + AudioService::getInstance().playMusic(); } ~Game() { diff --git a/include/Map.h b/include/entities/Map.h similarity index 100% rename from include/Map.h rename to include/entities/Map.h diff --git a/include/Text.h b/include/entities/Text.h similarity index 93% rename from include/Text.h rename to include/entities/Text.h index 6d65e64..887108e 100644 --- a/include/Text.h +++ b/include/entities/Text.h @@ -2,10 +2,10 @@ #define TEXT_H #include "raylib.h" -#include "EFont.h" +#include "enums/EFont.h" #include #include -#include "AssetService.h" +#include "services/AssetService.h" class Text { private: diff --git a/include/TextureWrapper.h b/include/entities/TextureWrapper.h similarity index 92% rename from include/TextureWrapper.h rename to include/entities/TextureWrapper.h index 26c381b..a8d3c8f 100644 --- a/include/TextureWrapper.h +++ b/include/entities/TextureWrapper.h @@ -5,7 +5,7 @@ class TextureWrapper { public: - TextureWrapper(Texture2D texture, Vector2 size = {32,32}, Vector2 position = {0,0}, Rectangle sourceRect = {0,0,100,100}) { + TextureWrapper(Texture2D texture, Vector2 size = {32,32}, Vector2 position = {0,0}, Rectangle sourceRect = {0,0,32,32}) { this->texture = texture; this->size = size; this->position = position; diff --git a/include/EBackground.h b/include/enums/EBackground.h similarity index 100% rename from include/EBackground.h rename to include/enums/EBackground.h diff --git a/include/EFont.h b/include/enums/EFont.h similarity index 100% rename from include/EFont.h rename to include/enums/EFont.h diff --git a/include/enums/EMap.h b/include/enums/EMap.h new file mode 100644 index 0000000..c9f64c1 --- /dev/null +++ b/include/enums/EMap.h @@ -0,0 +1,10 @@ +#ifndef EMAP_H +#define EMAP_H + +enum class EMap { + TEXTURE, + COLLISION +}; + + +#endif \ No newline at end of file diff --git a/include/EMusic.h b/include/enums/EMusic.h similarity index 100% rename from include/EMusic.h rename to include/enums/EMusic.h diff --git a/include/EScreen.h b/include/enums/EScreen.h similarity index 100% rename from include/EScreen.h rename to include/enums/EScreen.h diff --git a/include/GameScreen.h b/include/screens/GameScreen.h similarity index 78% rename from include/GameScreen.h rename to include/screens/GameScreen.h index 9fb2645..eb0847d 100644 --- a/include/GameScreen.h +++ b/include/screens/GameScreen.h @@ -1,8 +1,8 @@ #ifndef GAME_SCREEN_H #define GAME_SCREEN_H -#include "Screen.h" -#include "Game.h" +#include "screens/Screen.h" +#include "entities/Game.h" class GameScreen: public Screen { diff --git a/include/MainScreen.h b/include/screens/MainScreen.h similarity index 85% rename from include/MainScreen.h rename to include/screens/MainScreen.h index 9e8f624..11e061b 100644 --- a/include/MainScreen.h +++ b/include/screens/MainScreen.h @@ -1,9 +1,9 @@ #ifndef MAIN_SCREEN_H #define MAIN_SCREEN_H -#include "Screen.h" +#include "screens/Screen.h" #include -#include "Text.h" +#include "entities/Text.h" class MainScreen : public Screen { private: diff --git a/include/Screen.h b/include/screens/Screen.h similarity index 100% rename from include/Screen.h rename to include/screens/Screen.h diff --git a/include/TitleScreen.h b/include/screens/TitleScreen.h similarity index 81% rename from include/TitleScreen.h rename to include/screens/TitleScreen.h index 31d5896..e04ba18 100644 --- a/include/TitleScreen.h +++ b/include/screens/TitleScreen.h @@ -1,9 +1,9 @@ #ifndef TITLE_SCREEN_H #define TITLE_SCREEN_H -#include "Screen.h" +#include "screens/Screen.h" #include "raylib.h" -#include "Text.h" +#include "entities/Text.h" class TitleScreen : public Screen { private: diff --git a/include/TutorialScreen.h b/include/screens/TutorialScreen.h similarity index 76% rename from include/TutorialScreen.h rename to include/screens/TutorialScreen.h index b974ef0..3a96fe5 100644 --- a/include/TutorialScreen.h +++ b/include/screens/TutorialScreen.h @@ -1,9 +1,9 @@ #ifndef TUTORIAL_SCREEN_H #define TUTORIAL_SCREEN_H -#include "Screen.h" -#include "Background.h" -#include "Text.h" +#include "screens/Screen.h" +#include "entities/Background.h" +#include "entities/Text.h" class TutorialScreen : public Screen { diff --git a/include/AssetService.h b/include/services/AssetService.h similarity index 79% rename from include/AssetService.h rename to include/services/AssetService.h index 3177fa6..c6f405e 100644 --- a/include/AssetService.h +++ b/include/services/AssetService.h @@ -5,31 +5,14 @@ #include #include #include -#include "EFont.h" -#include "EMusic.h" -#include "EBackground.h" -#include "Service.h" +#include "enums/EFont.h" +#include "enums/EMusic.h" +#include "enums/EBackground.h" +#include "enums/EMap.h" +#include "services/Service.h" class AssetService: public Service { -private: - /** Friend to allow access to the constructor */ - friend class Service; - - std::string assetDir; - std::unordered_map fonts; - std::vector sounds; - std::unordered_map music; - std::unordered_map backgrounds; - - void setAssets(); - - Music loadMusic(std::string filename, bool loops); - Sound loadSound(std::string filename); - std::string getFontUrl(EFont font); -protected: - AssetService(); - public: void setAssetDir(std::string assetDir){this->assetDir = assetDir;} @@ -41,6 +24,29 @@ public: return this->backgrounds[background]; } Texture2D loadTexture(std::string filename); + std::string getMapUrl(EMap map) { + return this->assetDir + this->maps[map]; + } + +protected: + AssetService(); + +private: + /** Friend to allow access to the constructor */ + friend class Service; + + std::string assetDir; + std::unordered_map fonts; + std::vector sounds; + std::unordered_map music; + std::unordered_map backgrounds; + std::unordered_map maps; + + void setAssets(); + + Music loadMusic(std::string filename, bool loops); + Sound loadSound(std::string filename); + std::string getFontUrl(EFont font); }; #endif \ No newline at end of file diff --git a/include/AudioService.h b/include/services/AudioService.h similarity index 89% rename from include/AudioService.h rename to include/services/AudioService.h index 68a697a..d065b67 100644 --- a/include/AudioService.h +++ b/include/services/AudioService.h @@ -2,18 +2,12 @@ #define AUDIO_SERVICE_H #include "raylib.h" -#include "EMusic.h" -#include "Service.h" +#include "enums/EMusic.h" +#include "services/Service.h" #include class AudioService : public Service { -private: - std::optional music; - EMusic currentTrack = EMusic::NONE; - -protected: - public: void setMusic(EMusic music); std::optional getMusic(){return music;} @@ -24,6 +18,13 @@ public: void playSound(); void stopSounds(); + +protected: + +private: + std::optional music; + EMusic currentTrack = EMusic::NONE; + }; #endif \ No newline at end of file diff --git a/include/services/InputService.h b/include/services/InputService.h new file mode 100644 index 0000000..dd7e289 --- /dev/null +++ b/include/services/InputService.h @@ -0,0 +1,89 @@ +#ifndef INPUT_SERVICE_H +#define INPUT_SERVICE_H + +#include "Service.h" +#include "raylib.h" +#include +#include +#include + +/** + * Tracks all user input, which is then retrieved by the screens + */ +class InputService : public Service +{ +public: + /** + * Setting up the keys to watch, so that only the keys that might get pressed are being watched + */ + void setKeysToWatch(std::vector keysToWatch, std::vector mouseButtonsToWatch) + { + this->watchedKeys.clear(); + this->keysPressed.clear(); + + for (int i = 0; i < keysToWatch.size(); i++) + { + this->watchedKeys.insert(keysToWatch[i]); + this->keysPressed[keysToWatch[i]] = false; + } + + setMouseButtonsToWatch(mouseButtonsToWatch); + } + + /** + * Checks if a button has been pressed + * The flow: + * 1. Screen constructor: Announce which keys to watch + * 2. StateService loop: Check keys, store the result + * 3. Screen logic: If pressed, execute logic + */ + void checkKeys() + { + for (auto key : watchedKeys) + { + keysPressed[key] = false; + if (IsKeyPressed(key)) + { + keysPressed[key] = true; + } + } + for (auto button : watchedMouseButtons) + { + mouseButtonsPressed[button] = false; + if (IsMouseButtonPressed(button)) + { + mouseButtonsPressed[button] = true; + } + } + } + + bool isKeyPressed(KeyboardKey key) + { + return keysPressed[key]; + } + + bool isMouseButtonPressed(MouseButton button) + { + return mouseButtonsPressed[button]; + } + +private: + std::unordered_set watchedKeys; + std::unordered_map keysPressed; + std::unordered_set watchedMouseButtons; + std::unordered_map mouseButtonsPressed; + + void setMouseButtonsToWatch(std::vector mouseButtonsToWatch) + { + this->watchedMouseButtons.clear(); + this->mouseButtonsPressed.clear(); + + for (int i = 0; i < mouseButtonsToWatch.size(); i++) + { + this->watchedMouseButtons.insert(mouseButtonsToWatch[i]); + this->mouseButtonsPressed[mouseButtonsToWatch[i]] = false; + } + } +}; + +#endif \ No newline at end of file diff --git a/include/Service.h b/include/services/Service.h similarity index 98% rename from include/Service.h rename to include/services/Service.h index 9f2e4ef..e76e147 100644 --- a/include/Service.h +++ b/include/services/Service.h @@ -4,11 +4,6 @@ template class Service { -private: -protected: - static T* instance; - Service() {} - public: Service(const Service &) = delete; Service &operator=(const Service &) = delete; @@ -18,6 +13,13 @@ public: static T instance; return instance; } + +protected: + static T* instance; + Service() {} + +private: + }; #endif \ No newline at end of file diff --git a/include/StateService.h b/include/services/StateService.h similarity index 60% rename from include/StateService.h rename to include/services/StateService.h index 121c492..01960b6 100644 --- a/include/StateService.h +++ b/include/services/StateService.h @@ -1,11 +1,11 @@ #ifndef STATE_SERVICE_H #define STATE_SERVICE_H -#include "Screen.h" #include #include -#include "EScreen.h" -#include "Service.h" +#include "services/Service.h" +#include "screens/Screen.h" +#include "enums/EScreen.h" #include "raylib.h" #if defined(PLATFORM_WEB) @@ -17,6 +17,32 @@ */ class StateService : public Service { +public: + Vector2 getScreenSize() + { + return screenSize; + } + void setScreenSize(Vector2 screenSize) + { + this->screenSize = screenSize; + } + void setScreen(EScreen screen); + Screen *getScreen(); + /** + * Start the game loop + */ + void startGame(); + + static void staticStep() + { + if (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + { + std::cout << "Input!" << std::endl; + } + // Access the singleton instance and call step + getInstance().step(); + } + private: std::unique_ptr currentScreen; @@ -30,20 +56,6 @@ private: void step(); void handleMusic(); - -public: - Vector2 getScreenSize(){ - return screenSize; - } - void setScreenSize(Vector2 screenSize) { - this->screenSize = screenSize; - } - void setScreen(EScreen screen); - Screen *getScreen(); - /** - * Start the game loop - */ - void startGame(); }; #endif \ No newline at end of file diff --git a/scripts/build_wasm.sh b/scripts/build_wasm.sh index 8e2a1cc..e921bfc 100755 --- a/scripts/build_wasm.sh +++ b/scripts/build_wasm.sh @@ -1,5 +1,15 @@ #!/bin/bash -emcc -o dist/game.js src/main.cpp -Os -Wall /app/raylib/src/libraylib.a -I. -I/app/raylib/build/raylib/include -L. -L$LD_LIBRARY_PATH -s USE_GLFW=3 -s --preload-file assets@/assets -DPLATFORM_WEB +# emcc src/main.cpp -o dist/game.js -Wno-missing-braces -I/app/libs/raylib/build/raylib/include -L/app/libs/raylib/src /app/libs/raylib/src/libraylib.a -s USE_GLFW=3 -DPLATFORM_WEB + + +emcc $(find src/ -name "*.cpp") -o dist/game.js -Wno-missing-braces -I./include -I/app/libs/raylib/build/raylib/include -L/app/libs/raylib/src /app/libs/raylib/src/libraylib.a -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=268435456 -s MAXIMUM_MEMORY=4294967296 -s --preload-file assets@/assets -s USE_GLFW=3 -DPLATFORM_WEB +# -I./include +# -L$LD_LIBRARY_PATH +# -I. +# -L. +# -s --preload-file assets@/assets +# /app/libs/raylib/src/libraylib.a +# -Os -Wall # --shell-file /app/raylib/src/shell.html cd dist python3 -m http.server 8080; \ No newline at end of file diff --git a/src/entities/Background.cpp b/src/entities/Background.cpp index a3fc549..e31acfe 100644 --- a/src/entities/Background.cpp +++ b/src/entities/Background.cpp @@ -1,6 +1,6 @@ -#include "Background.h" +#include "entities/Background.h" -#include "AssetService.h" +#include "services/AssetService.h" // Background::Background(EBackground background) // { diff --git a/src/entities/Map.cpp b/src/entities/Map.cpp index d13d29d..07224b9 100644 --- a/src/entities/Map.cpp +++ b/src/entities/Map.cpp @@ -1,9 +1,9 @@ -#include "Map.h" +#include "entities/Map.h" #include #include #include #include -#include "AssetService.h" +#include "services/AssetService.h" Map::Map() { @@ -14,7 +14,7 @@ Map::Map() void Map::loadMap() { std::vector tempMap; - std::ifstream openfile("assets/Maps/map1.txt"); + std::ifstream openfile(AssetService::getInstance().getMapUrl(EMap::TEXTURE)); map.clear(); diff --git a/src/entities/Text.cpp b/src/entities/Text.cpp index e1bf782..226cdf3 100644 --- a/src/entities/Text.cpp +++ b/src/entities/Text.cpp @@ -1,4 +1,4 @@ -#include "Text.h" +#include "entities/Text.h" Text::Text(std::string text, EFont font, int fontSize, int spacing, Color color, Vector2 position) { diff --git a/src/main.cpp b/src/main.cpp index 4ed8675..e252ab4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,66 @@ #include "raylib.h" -#include "Screen.h" -#include "TitleScreen.h" -#include "StateService.h" -#include +// #include "screens/Screen.h" +// #include "screens/TitleScreen.h" +#include "services/StateService.h" +// #include +// #if defined(PLATFORM_WEB) +// #include +// #endif -int main(void) +// void step(); +// static void gameloop(); + +int main() { StateService& stateService = StateService::getInstance(); stateService.setScreenSize({640,544}); stateService.startGame(); // std::cout << "StateService instance: " << service << std::endl; - + +// InitWindow(640, 544, "Jelly Rescue"); +// // SetTargetFPS(60); + +// // setScreen(EScreen::TITLE); + +// #if defined(PLATFORM_WEB) +// emscripten_set_main_loop(step, 0, 1); +// #else + +// while (!WindowShouldClose()) +// { +// step(); +// } +// #endif + +// CloseWindow(); + return 0; -} \ No newline at end of file +} + +// static void gameloop() +// { +// // InitAudioDevice(); +// InitWindow(640, 544, "Jelly Rescue"); +// // SetTargetFPS(60); + +// // setScreen(EScreen::TITLE); + +// #if defined(PLATFORM_WEB) +// emscripten_set_main_loop(step, 0, 1); +// #else + +// while (!WindowShouldClose()) +// { +// step(); +// } +// #endif + +// CloseWindow(); +// // CloseAudioDevice(); +// } + +// void step() +// { +// ClearBackground(BLACK); +// } \ No newline at end of file diff --git a/src/screens/GameScreen.cpp b/src/screens/GameScreen.cpp index aa64886..d3d445a 100644 --- a/src/screens/GameScreen.cpp +++ b/src/screens/GameScreen.cpp @@ -1,6 +1,6 @@ -#include "GameScreen.h" -#include "Map.h" -#include "StateService.h" +#include "screens/GameScreen.h" +#include "entities/Map.h" +#include "services/StateService.h" GameScreen::GameScreen() { diff --git a/src/screens/MainScreen.cpp b/src/screens/MainScreen.cpp index a8e7523..77f6293 100644 --- a/src/screens/MainScreen.cpp +++ b/src/screens/MainScreen.cpp @@ -1,7 +1,8 @@ -#include "MainScreen.h" -#include "AudioService.h" -#include "StateService.h" +#include "screens/MainScreen.h" +#include "services/AudioService.h" +#include "services/StateService.h" #include "raylib.h" +#include "services/InputService.h" MainScreen::MainScreen() { @@ -33,6 +34,8 @@ MainScreen::MainScreen() AudioService::getInstance().setMusic(EMusic::MAIN); AudioService::getInstance().playMusic(); } + + InputService::getInstance().setKeysToWatch({KEY_ENTER, KEY_UP, KEY_DOWN}, {MOUSE_BUTTON_LEFT}); } void MainScreen::logic() @@ -78,18 +81,18 @@ void MainScreen::mouseLogic() void MainScreen::keyboardLogic() { - if (IsKeyPressed(KEY_DOWN) || IsKeyPressed(KEY_UP)) + if (InputService::getInstance().isKeyPressed(KEY_DOWN) || InputService::getInstance().isKeyPressed(KEY_UP)) { buttons[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; + hoveredButton = ((hoveredButton - (InputService::getInstance().isKeyPressed(KEY_DOWN) ? -1 : 1)) + 4) % 4; buttons[hoveredButton].setColor(RED); } } void MainScreen::clickLogic() { - if (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + if (InputService::getInstance().isKeyPressed(KEY_ENTER) || InputService::getInstance().isMouseButtonPressed(MOUSE_BUTTON_LEFT)) { std::string selectedButton = buttons[hoveredButton].getText(); diff --git a/src/screens/Screen.cpp b/src/screens/Screen.cpp index 2793dff..a9cf5ff 100644 --- a/src/screens/Screen.cpp +++ b/src/screens/Screen.cpp @@ -1,7 +1,4 @@ -#include "Screen.h" -#include "AudioService.h" -#include - +#include "screens/Screen.h" // void Screen::draw() // { diff --git a/src/screens/TitleScreen.cpp b/src/screens/TitleScreen.cpp index dd517a6..98e7f35 100644 --- a/src/screens/TitleScreen.cpp +++ b/src/screens/TitleScreen.cpp @@ -1,9 +1,10 @@ -#include "TitleScreen.h" -#include "AssetService.h" -#include "StateService.h" -#include "EFont.h" -#include "AudioService.h" +#include "screens/TitleScreen.h" +#include "services/AssetService.h" +#include "services/StateService.h" +#include "enums/EFont.h" +#include "services/AudioService.h" #include +#include "services/InputService.h" TitleScreen::TitleScreen() { @@ -27,14 +28,16 @@ TitleScreen::TitleScreen() AudioService::getInstance().setMusic(EMusic::MAIN); AudioService::getInstance().playMusic(); } + + InputService::getInstance().setKeysToWatch({KEY_ENTER}, {MOUSE_BUTTON_LEFT}); } void TitleScreen::logic() { - if (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + // std::cout << "Next screen!" << std::endl; + if (InputService::getInstance().isKeyPressed(KEY_ENTER) || InputService::getInstance().isMouseButtonPressed(MOUSE_BUTTON_LEFT)) { StateService::getInstance().setScreen(EScreen::MAIN); - // std::cout << "Next screen!" << std::endl; } } diff --git a/src/screens/TutorialScreen.cpp b/src/screens/TutorialScreen.cpp index 2ddf6d0..86b7ea5 100644 --- a/src/screens/TutorialScreen.cpp +++ b/src/screens/TutorialScreen.cpp @@ -1,8 +1,9 @@ -#include "TutorialScreen.h" +#include "screens/TutorialScreen.h" -#include "StateService.h" -#include "EFont.h" -#include "EScreen.h" +#include "services/StateService.h" +#include "enums/EFont.h" +#include "enums/EScreen.h" +#include "services/InputService.h" TutorialScreen::TutorialScreen() { Text textBack = Text("Press Enter to go back", EFont::SANSATION, 30, 0, RED); @@ -11,11 +12,13 @@ TutorialScreen::TutorialScreen() { this->text.push_back(textBack); this->background = Background(EBackground::TUTORIAL); + + InputService::getInstance().setKeysToWatch({KEY_ENTER}, {MOUSE_BUTTON_LEFT}); } void TutorialScreen::logic() { - if (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + if ( InputService::getInstance().isKeyPressed(KEY_ENTER) || InputService::getInstance().isMouseButtonPressed(MOUSE_BUTTON_LEFT)) { StateService::getInstance().setScreen(EScreen::MAIN); } diff --git a/src/services/AssetService.cpp b/src/services/AssetService.cpp index cc2ae54..d6f6ce9 100644 --- a/src/services/AssetService.cpp +++ b/src/services/AssetService.cpp @@ -1,5 +1,5 @@ -#include "AssetService.h" - +#include "services/AssetService.h" +#include AssetService::AssetService() { setAssetDir("assets/"); @@ -25,6 +25,9 @@ void AssetService::setAssets() backgrounds[EBackground::GAME2] = loadTexture("Textures/GameBackground_2.jpg"); backgrounds[EBackground::GAME3] = loadTexture("Textures/GameBackground_3.png"); backgrounds[EBackground::VICTORY] = loadTexture("Textures/VictoryScreenBackground.png"); + + maps[EMap::TEXTURE] = "Maps/map1.txt"; + maps[EMap::COLLISION] = "Maps/colmap1.txt"; } Font AssetService::getFont(EFont font, int fontSize) diff --git a/src/services/AudioService.cpp b/src/services/AudioService.cpp index 1d8db1d..64737c8 100644 --- a/src/services/AudioService.cpp +++ b/src/services/AudioService.cpp @@ -1,5 +1,5 @@ -#include "AudioService.h" -#include "AssetService.h" +#include "services/AudioService.h" +#include "services/AssetService.h" // AudioService::~AudioService() // { diff --git a/src/services/StateService.cpp b/src/services/StateService.cpp index 99cf07b..a37b200 100644 --- a/src/services/StateService.cpp +++ b/src/services/StateService.cpp @@ -1,11 +1,12 @@ -#include "StateService.h" +#include "services/StateService.h" #include "raylib.h" -#include "TitleScreen.h" -#include "MainScreen.h" -#include "TutorialScreen.h" -#include "GameScreen.h" +#include "screens/TitleScreen.h" +#include "screens/MainScreen.h" +#include "screens/TutorialScreen.h" +#include "screens/GameScreen.h" #include -#include "AudioService.h" +#include "services/AudioService.h" +#include "services/InputService.h" void StateService::setScreen(EScreen state) { @@ -38,16 +39,30 @@ Screen *StateService::getScreen() void StateService::startGame() { + // if(!instance) + // return; InitAudioDevice(); + // InitWindow(640,544, "Jelly Rescue"); InitWindow(screenSize.x, screenSize.y, "Jelly Rescue"); SetTargetFPS(60); + // #if defined(PLATFORM_WEB) + // emscripten_set_keypress_callback(EMSCRIPTEN_EVENT_TARGET_CANVAS, nullptr, 1, staticStep); + // #endif + + // #if defined(PLATFORM_WEB) + // emscripten_set_focusin_callback(EMSCRIPTEN_EVENT_TARGET_CANVAS, nullptr, 1, [](const EmscriptenFocusEvent* event) { + // std::cout << "Canvas Focused!" << std::endl; + // }); + // #endif + setScreen(EScreen::TITLE); #if defined(PLATFORM_WEB) - emscripten_set_main_loop(step, 0, 1); + emscripten_set_main_loop(StateService::staticStep, 0, 1); #else + // while (!WindowShouldClose() && instance->gameRunning) while (!WindowShouldClose() && gameRunning) { step(); @@ -69,7 +84,18 @@ void StateService::handleMusic() void StateService::step() { + InputService::getInstance().checkKeys(); + handleMusic(); currentScreen->draw(); currentScreen->logic(); + // if (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + // { + // setScreen(EScreen::MAIN); + // } + // if(instance) { + // instance->handleMusic(); + // instance->currentScreen->draw(); + // instance->currentScreen->logic(); + // } }