diff --git a/Makefile.emcc b/Makefile.emcc index 486614a..98e82c7 100644 --- a/Makefile.emcc +++ b/Makefile.emcc @@ -5,7 +5,7 @@ CC = emcc CXX = emcc CXXFLAGS ?= -sUSE_SDL=2 -O3 -std=c++17 -Iinclude -fexceptions LDFLAGS ?= -sUSE_SDL=2 -O3 -fexceptions --embed-file=data.pak@data.pak -sMAX_WEBGL_VERSION=2 -TARGET = eulamadness.html +TARGET = index.html # System configuration include Makefile.srcs @@ -28,4 +28,4 @@ $(EXE): $(OBJS) $(CXX) $(CXXFLAGS) -c $< -o $@ clean: - -rm -rf $(OBJS) $(EXE) eulamadness.js eulamadness.wasm eulamadness.data dist + -rm -rf $(OBJS) $(EXE) index.js index.wasm index.data dist diff --git a/index.template.html b/index.template.html index 8b3cfb3..7ecb40e 100644 --- a/index.template.html +++ b/index.template.html @@ -18,7 +18,7 @@ - + diff --git a/src/AudioManager.cpp b/src/AudioManager.cpp index 0661273..72c6920 100644 --- a/src/AudioManager.cpp +++ b/src/AudioManager.cpp @@ -86,6 +86,8 @@ void TAudioManager::Paint(SDL_AudioStream* stream, std::uint32_t ticks) { } } + accumulator *= Volume_; + accumulator += 128; if (accumulator < 0) { accumulator = 0; @@ -103,7 +105,18 @@ void TAudioManager::Paint(SDL_AudioStream* stream, std::uint32_t ticks) { } } +void TAudioManager::SetVolume(float volume) { + if (volume > 1) { + volume = 1; + } else if (volume < 0) { + volume = 0; + } + Volume_ = volume; +} +float TAudioManager::Volume() const { + return Volume_; +} TAudioManager::TSound* TAudioManager::Load(const std::string& path) { auto it = Sounds_.find(path); diff --git a/src/AudioManager.h b/src/AudioManager.h index 9a11887..8746ae6 100644 --- a/src/AudioManager.h +++ b/src/AudioManager.h @@ -15,6 +15,8 @@ public: void Run(); void Play(const std::string& sound); void Paint(SDL_AudioStream* stream, std::uint32_t ticks); + void SetVolume(float volume); + float Volume() const; private: struct TSound { @@ -34,6 +36,7 @@ private: private: TFileManager& FileManager_; + float Volume_ = 1.0; TSoundChannel Channels_[16]; std::unordered_map Sounds_; SDL_AudioDeviceID Device_; diff --git a/src/Main.cpp b/src/Main.cpp index b0b3838..18991ff 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -39,6 +39,7 @@ static void InitApp(void) { app->EntityManager().RegisterEntity("TorchEntity"); app->EntityManager().RegisterEntity("GrenadeEntity"); + app->AudioManager().SetVolume(.3); app->EntityManager().AddToDeferred("IntroMenu"); app->EntityManager().Reset(); } diff --git a/src/RoomEntity.cpp b/src/RoomEntity.cpp index 466255a..6fe6ad2 100644 --- a/src/RoomEntity.cpp +++ b/src/RoomEntity.cpp @@ -1200,7 +1200,7 @@ void THero::Draw() const { } if (DisplayEnd_) { - App_->FontManager().Draw(NGame::TFontManager::Red, {4, 4}, "You are dead! Press X"); + App_->FontManager().Draw(NGame::TFontManager::Red, {4, 4}, "Press [Any] key to continue"); } if (FadeAmount_) { @@ -1323,6 +1323,14 @@ void TMainMenu::Input(SDL_Event* event) { App_->State().Variable("Grenades").SetInt(3); App_->EntityManager().AddToDeferred("RoomEntity"); App_->EntityManager().Reset(); + } else if (event->key.keysym.sym == SDLK_UP) { + App_->AudioManager().SetVolume(App_->AudioManager().Volume() + 0.1); + } else if (event->key.keysym.sym == SDLK_DOWN) { + App_->AudioManager().SetVolume(App_->AudioManager().Volume() - 0.1); + } else if (event->key.keysym.sym == SDLK_LEFT) { + App_->AudioManager().SetVolume(App_->AudioManager().Volume() - 0.01); + } else if (event->key.keysym.sym == SDLK_RIGHT) { + App_->AudioManager().SetVolume(App_->AudioManager().Volume() + 0.01); } break; } @@ -1334,7 +1342,17 @@ void TMainMenu::Update(std::uint32_t delta) { void TMainMenu::Draw() const { RenderManager_.SetLayer(NGame::TRenderManager::Interface); - App_->FontManager().Draw(NGame::TFontManager::Gold, {}, "Press X to start a game"); + App_->FontManager().Draw(NGame::TFontManager::White, {50, 50}, "EULAMadness"); + App_->FontManager().Draw(NGame::TFontManager::Swamp, {50, 60}, "Prototype"); + + App_->FontManager().Draw(NGame::TFontManager::Gold, {50, 100}, "Instruction: WASD or Arrow keys to [Move]"); + App_->FontManager().Draw(NGame::TFontManager::Gold, {50, 110}, " Z to [Jump]"); + App_->FontManager().Draw(NGame::TFontManager::Gold, {50, 120}, " X to throw [Grenade]"); + App_->FontManager().Draw(NGame::TFontManager::Gold, {50, 130}, " Down and Z to [Jump Down] from platform"); + + App_->FontManager().Draw(NGame::TFontManager::Gold, {50, 170}, "Press X to start a game"); + App_->FontManager().Draw(NGame::TFontManager::Gold, {50, 180}, "Press Arrow keys to change volume [" + std::to_string(int(App_->AudioManager().Volume() * 100)) + "]"); + } void TMainMenu::Alarm(NGame::TAlarm::TId id) { @@ -1407,26 +1425,35 @@ void TEulaMenu::Draw() const { RenderManager_.SetLayer(NGame::TRenderManager::Interface); NGame::Vec2i position = {50, 50}; - std::string text; + std::string goodText; + std::string badText; + std::string neutralText; if (Choice_.empty()) { - text = "There is nothing that you can do"; - text += "\n\nPress C to ingore"; - App_->FontManager().Draw(NGame::TFontManager::Red, position, text); + badText = "There is nothing that you can do"; + badText += "\n\nPress C to ingore"; + App_->FontManager().Draw(NGame::TFontManager::Red, position, badText); } else { if (Choice_ == "FallDamage") { - text = "Gain 30 seconds, but there will be\nfall damage"; + goodText = "Gain 30 seconds..."; + badText = "...but there will be fall damage"; } else if (Choice_ == "InstantMines") { - text = "Gain 30 seconds, but mines will explode\ninstantly"; + goodText = "Gain 30 seconds..."; + badText = "...but mines will explode instantly"; } else if (Choice_ == "LimitedGrenades") { - text = "Gain 30 seconds, but grenades will\nno longer replenish"; + goodText = "Gain 30 seconds..."; + badText = "...but grenades will no longer replenish"; } else if (Choice_ == "DarkLevel") { - text = "Gain 30 seconds, but the cave is now\nshrouded in darkness"; + goodText = "Gain 30 seconds..."; + badText = "...but the cave is now shrouded in darkness"; } else if (Choice_ == "NoCompas") { - text = "Gain 30 seconds, but you lose your compass"; + goodText = "Gain 30 seconds..."; + badText = "...but you lose your compass"; } - text += "\n\nPress X to accept or C to ingore"; - App_->FontManager().Draw(NGame::TFontManager::Gold, position, text); + neutralText = "Press X to accept or C to ingore"; + App_->FontManager().Draw(NGame::TFontManager::Green, position, goodText); + App_->FontManager().Draw(NGame::TFontManager::Red, position + NGame::Vec2i{0, 12}, badText); + App_->FontManager().Draw(NGame::TFontManager::Gold, position + NGame::Vec2i{0, 40}, neutralText); } } @@ -1460,7 +1487,11 @@ void TIntroMenu::Update(std::uint32_t delta) { void TIntroMenu::Draw() const { RenderManager_.SetLayer(NGame::TRenderManager::Interface); - App_->FontManager().Draw(NGame::TFontManager::Gold, {}, "Made by an idiot. Press X to continue"); + App_->FontManager().Draw(NGame::TFontManager::White, {50, 50}, "EULAMadness"); + App_->FontManager().Draw(NGame::TFontManager::Swamp, {50, 60}, "Prototype"); + + App_->FontManager().Draw(NGame::TFontManager::Gold, {50, 100}, "Press X to continue"); + App_->FontManager().Draw(NGame::TFontManager::Swamp, {50, 200}, "made by blankhex. 2025"); } void TIntroMenu::Alarm(NGame::TAlarm::TId id) {