diff --git a/assets/PBData b/assets/PBData index 238c6d1..5e75890 100644 --- a/assets/PBData +++ b/assets/PBData @@ -1 +1 @@ -48889 2147483647 2147483647 2147483647 109086 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 \ No newline at end of file +2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 0.7 0.6 OneLoneHam Yellow \ No newline at end of file diff --git a/assets/longbutton2.png b/assets/longbutton2.png new file mode 100644 index 0000000..d66dbdc Binary files /dev/null and b/assets/longbutton2.png differ diff --git a/assets/longhighlight_button2.png b/assets/longhighlight_button2.png new file mode 100644 index 0000000..b2ee2af Binary files /dev/null and b/assets/longhighlight_button2.png differ diff --git a/src/HamsterAI.cpp b/src/HamsterAI.cpp index 9087ecb..c81b20a 100644 --- a/src/HamsterAI.cpp +++ b/src/HamsterAI.cpp @@ -148,4 +148,8 @@ const HamsterAI::ActionOptRef HamsterAI::PeekNextAction(){ void HamsterAI::OnBoost(const vi2d pos){ recordedActions.emplace_back(pos,Action::BOOST); +} + +const bool HamsterAI::IsRecording(){ + return recordingMode; } \ No newline at end of file diff --git a/src/HamsterAI.h b/src/HamsterAI.h index 40c4d69..00d9d98 100644 --- a/src/HamsterAI.h +++ b/src/HamsterAI.h @@ -82,6 +82,7 @@ public: static void Update(const float fElapsedTime); static void DrawOverlay(); + static const bool IsRecording(); private: static bool recordingMode; static std::vectorrecordedActions; diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index da06f8a..5622687 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -24,8 +24,51 @@ HamsterGame::HamsterGame(const std::string&appName){ bool HamsterGame::OnUserCreate(){ CreateLayer(); EnableLayer(1U,true); + for(const std::string&map:mapNameList){ + mapPBs[map]=std::numeric_limits::max(); + } LoadPBs(); audio.SetBackgroundPlay(true); + + #ifdef __EMSCRIPTEN__ + emscripten_idb_async_load("hamster",Game().bgmVolLabel.c_str(),&Game().bgmVol,[](void*arg,void*data,int length){ + std::string rawMetadata=(char*)data; + std::cout<=Game().mapNameList.size())break; - int readVal; - file>>readVal; - mapPBs[Game().mapNameList[readCounter]]=readVal; - readCounter++; + #ifdef __EMSCRIPTEN__ + for(int i{0};const std::string&mapName:Game().mapNameList){ + mapPBs[mapName]=UNPLAYED; + emscripten_idb_async_load("hamster",Game().mapNameList[i].c_str(),&Game().mapNameList[i],[](void*arg,void*data,int length){ + std::string rawMetadata=(char*)data; + std::cout<>Game().bgmVol; + std::cout<>Game().sfxVol; + std::cout<>Game().playerName; + std::cout<>Game().hamsterColor; + std::cout<>readVal; + mapPBs[Game().mapNameList[readCounter]]=readVal; + } } - file.close(); - #endif - i++; - } + readCounter++; + } + file.close(); + #endif } const HamsterGame::GameMode HamsterGame::GetGameMode(){ diff --git a/src/HamsterGame.h b/src/HamsterGame.h index e9aa16b..59b2d04 100644 --- a/src/HamsterGame.h +++ b/src/HamsterGame.h @@ -112,6 +112,8 @@ public: const std::string PopNextMap(); void ProcessMap(); void QuitGame(); + std::string playerName{"OneLoneHamster"}; + void SaveOptions(); private: void UpdateGame(const float fElapsedTime); void DrawGame(); @@ -173,6 +175,7 @@ private: "Grand Prix I", "Grand Prix II", "Grand Prix III", + "Marathon", }; std::string emscripten_temp_val{"123456"}; std::vectorhamsterColorNames{ @@ -195,4 +198,11 @@ private: int totalOperationsCount{}; int operationsProgress{}; bool gameIsRunning{true}; -}; \ No newline at end of file + std::string bgmVolLabel{"bgmVol"}; + std::string sfxVolLabel{"sfxVol"}; + std::string playerNameLabel{"playerName"}; + std::string hamsterColorLabel{"hamsterColor"}; + float bgmVol{0.7f}; + float sfxVol{0.7f}; + std::string hamsterColor{hamsterColorNames[0]}; +}; diff --git a/src/Menu.cpp b/src/Menu.cpp index 57b35d0..c59acf9 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -42,6 +42,7 @@ All rights reserved. #include "Hamster.h" void Menu::UpdateAndDraw(HamsterGame&game,const float fElapsedTime){ + if(HamsterGame::Game().IsTextEntryEnabled()||ignoreInputs)goto Drawing; menuTransitionRefreshTimer-=fElapsedTime; for(int i{0};const Button&b:menuButtons){ @@ -74,6 +75,7 @@ void Menu::UpdateAndDraw(HamsterGame&game,const float fElapsedTime){ } } + Drawing: game.EnableLayer(0U,menuTimer>0.f); switch(currentMenu){ @@ -109,6 +111,7 @@ void Menu::UpdateAndDraw(HamsterGame&game,const float fElapsedTime){ Draw(game,currentMenu,game.SCREEN_FRAME.pos); } game.border.Update(fElapsedTime); + ignoreInputs=false; } void Menu::Transition(const TransitionType type,const MenuType gotoMenu,const float transitionTime){ if(menuTimer>0.f)return; @@ -121,22 +124,54 @@ std::vectorMenu::GetMenuButtons(const MenuType type){ std::vectorbuttons; switch(type){ case MAIN_MENU:{ - buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,-32.f},"Grand Prix","button.png","highlight_button.png",Pixel{165,208,96},Pixel{37,134,139},[this](){Transition(SHIFT_LEFT,GRAND_PRIX,0.5f);}); - buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,0.f},"Single Race","button.png","highlight_button.png",Pixel{165,208,96},Pixel{37,134,139},[this](){Transition(SHIFT_UP,SINGLE_RACE,0.5f);}); - buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,32.f},"Options","button.png","highlight_button.png",Pixel{165,208,96},Pixel{37,134,139},[this](){Transition(SHIFT_RIGHT,OPTIONS,0.5f);}); - buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,64.f},"Quit","button.png","highlight_button.png",Pixel{165,208,96},Pixel{37,134,139},[this](){Transition(SHIFT_DOWN,QUIT,0.5f);}); + buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,-32.f},"Grand Prix","button.png","highlight_button.png",Pixel{165,208,96},Pixel{37,134,139},[this](Button&self){Transition(SHIFT_LEFT,GRAND_PRIX,0.5f);}); + buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,0.f},"Single Race","button.png","highlight_button.png",Pixel{165,208,96},Pixel{37,134,139},[this](Button&self){Transition(SHIFT_UP,SINGLE_RACE,0.5f);}); + buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,32.f},"Options","button.png","highlight_button.png",Pixel{165,208,96},Pixel{37,134,139},[this](Button&self){Transition(SHIFT_RIGHT,OPTIONS,0.5f);}); + buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,64.f},"Quit","button.png","highlight_button.png",Pixel{165,208,96},Pixel{37,134,139},[this](Button&self){Transition(SHIFT_DOWN,QUIT,0.5f);}); }break; case GRAND_PRIX:{ //Add more buttons up here! - buttons.emplace_back(vf2d{54.f,HamsterGame::SCREEN_FRAME.size.y-24.f},"< Back","button3.png","highlight_button3.png",Pixel{145,199,255},Pixel{145,199,255},[this](){Transition(SHIFT_RIGHT,MAIN_MENU,0.5f);}); + buttons.emplace_back(vf2d{54.f,HamsterGame::SCREEN_FRAME.size.y-24.f},"< Back","button3.png","highlight_button3.png",Pixel{145,199,255},Pixel{145,199,255},[this](Button&self){Transition(SHIFT_RIGHT,MAIN_MENU,0.5f);}); }break; case SINGLE_RACE:{ //Add more buttons up here! - buttons.emplace_back(vf2d{54.f,HamsterGame::SCREEN_FRAME.size.y-24.f},"< Back","button4.png","highlight_button4.png",Pixel{220,185,155},Pixel{180,140,152},[this](){Transition(SHIFT_DOWN,MAIN_MENU,0.5f);}); + buttons.emplace_back(vf2d{54.f,HamsterGame::SCREEN_FRAME.size.y-24.f},"< Back","button4.png","highlight_button4.png",Pixel{220,185,155},Pixel{180,140,152},[this](Button&self){Transition(SHIFT_DOWN,MAIN_MENU,0.5f);}); }break; case OPTIONS:{ - //Add more buttons up here! - buttons.emplace_back(vf2d{54.f,HamsterGame::SCREEN_FRAME.size.y-24.f},"< Back","button2.png","highlight_button2.png",Pixel{114,109,163},Pixel{79,81,128},[this](){Transition(SHIFT_LEFT,MAIN_MENU,0.5f);}); + buttons.emplace_back(HamsterGame::SCREEN_FRAME.size/2+vf2d{0.f,-32.f},std::format("BGM: {}",int(round(HamsterGame::Game().bgmVol*100))),"button2.png","highlight_button2.png",Pixel{114,109,163},Pixel{79,81,128},[this](Button&self){ + HamsterGame::Game().bgmVol=((int(round(HamsterGame::Game().bgmVol*100))+10)%110)/100.f; + self.buttonText=std::format("BGM: {}",int(round(HamsterGame::Game().bgmVol*100))); + HamsterGame::Game().emscripten_temp_val=std::to_string(HamsterGame::Game().bgmVol); + #ifdef __EMSCRIPTEN__ + emscripten_idb_async_store("hamster",HamsterGame::Game().bgmVolLabel.c_str(),HamsterGame::Game().emscripten_temp_val.data(),HamsterGame::Game().emscripten_temp_val.length(),0,[](void*args){ + std::cout<<"Success!"<onClick) +Menu::Button::Button(const vf2d pos,const std::string&buttonText,const std::string&buttonImg,const std::string&highlightButtonImg,const Pixel textCol,const Pixel highlightTextCol,const std::functiononClick) :pos(pos),buttonText(buttonText),buttonImg(buttonImg),highlightButtonImg(highlightButtonImg),onClick(onClick),textCol(textCol),highlightTextCol(highlightTextCol){} const bool Menu::Button::IsHovered(const vf2d&offset)const{ @@ -303,7 +342,14 @@ const bool Menu::Button::IsHovered(const vf2d&offset)const{ void Menu::Button::Draw(HamsterGame&game,const vf2d&offset,std::optional>selectedButton)const{ if(selectedButton.has_value()&&&selectedButton.value().get()==this){ game.DrawRotatedDecal(pos+offset,game.GetGFX(highlightButtonImg).Decal(),0.f,game.GetGFX(highlightButtonImg).Sprite()->Size()/2); - game.DrawRotatedStringPropDecal(pos+offset,buttonText,0.f,game.GetTextSizeProp(buttonText)/2,highlightTextCol); + if(game.IsTextEntryEnabled()&&buttonText.starts_with("Player Name")){ + std::string blinkingCursor{" "}; + if(fmod(game.GetRuntime(),1.f)<0.5f)blinkingCursor="|"; + game.DrawRotatedStringPropDecal(pos+offset,std::format("Player Name: {}{}",game.TextEntryGetString(),blinkingCursor),0.f,game.GetTextSizeProp(buttonText)/2,highlightTextCol); + std::string helpText{"Press or to finish name entry."}; + const vf2d helpTextSize{game.GetTextSizeProp(helpText)}; + game.DrawShadowRotatedStringPropDecal(pos+offset+vf2d{0,12.f},helpText,0.f,helpTextSize/2); + }else game.DrawRotatedStringPropDecal(pos+offset,buttonText,0.f,game.GetTextSizeProp(buttonText)/2,highlightTextCol); }else{ game.DrawRotatedDecal(pos+offset,game.GetGFX(buttonImg).Decal(),0.f,game.GetGFX(buttonImg).Sprite()->Size()/2); game.DrawRotatedStringPropDecal(pos+offset,buttonText,0.f,game.GetTextSizeProp(buttonText)/2,textCol); @@ -311,5 +357,26 @@ void Menu::Button::Draw(HamsterGame&game,const vf2d&offset,std::optionalonClick; + std::functiononClick; public: - Button(const vf2d pos,const std::string&buttonText,const std::string&buttonImg,const std::string&highlightButtonImg,const Pixel textCol,const Pixel highlightTextCol,const std::functiononClick={}); + std::string buttonText; + Button(const vf2d pos,const std::string&buttonText,const std::string&buttonImg,const std::string&highlightButtonImg,const Pixel textCol,const Pixel highlightTextCol,const std::functiononClick={}); const bool IsHovered(const vf2d&offset)const; void OnClick(); void Draw(HamsterGame&game,const vf2d&pos,std::optional>selectedButton={})const; @@ -103,8 +103,10 @@ class Menu{ void DrawTransition(HamsterGame&game); void OnMenuTransition(); std::vector