diff --git a/Crawler/CharacterMenuWindow.cpp b/Crawler/CharacterMenuWindow.cpp new file mode 100644 index 00000000..043381ba --- /dev/null +++ b/Crawler/CharacterMenuWindow.cpp @@ -0,0 +1,46 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2018 - 2023 OneLoneCoder.com + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions or derivations of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions or derivative works in binary form must reproduce the above +copyright notice. This list of conditions and the following disclaimer must be +reproduced in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without specific +prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +Portions of this software are copyright © 2023 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. +*/ +#pragma endregion +#include "Menu.h" +#include "MenuComponent.h" +#include "Crawler.h" + +INCLUDE_game + +void Menu::InitializeCharacterMenuWindow(){ + Menu*characterMenuWindow=CreateMenu(CHARACTER_MENU,CENTERED,game->GetScreenSize()-vf2d{52,52}); +} \ No newline at end of file diff --git a/Crawler/ConnectionPoint.h b/Crawler/ConnectionPoint.h index b7c5d9a8..974e36eb 100644 --- a/Crawler/ConnectionPoint.h +++ b/Crawler/ConnectionPoint.h @@ -40,14 +40,15 @@ All rights reserved. struct ConnectionPoint{ geom2d::rectrect; + std::string type; std::string name; std::string map; std::string unlockCondition; std::arrayneighbors; //Indices into the connectionPoint array. std::vectorspawns; bool levelDataExists=false; - inline ConnectionPoint(geom2d::rectrect,std::string name,std::string map,std::string unlockCondition,std::vectorspawns) - :rect(rect),name(name),map(map),unlockCondition(unlockCondition),spawns(spawns){ + inline ConnectionPoint(geom2d::rectrect,std::string type,std::string name,std::string map,std::string unlockCondition,std::vectorspawns) + :rect(rect),type(type),name(name),map(map),unlockCondition(unlockCondition),spawns(spawns){ neighbors.fill(-1); } bool IsNeighbor(ConnectionPoint&testPoint); diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index bef96cb0..7ecdd014 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -86,6 +86,7 @@ InputGroup Crawler::KEY_UP; InputGroup Crawler::KEY_DOWN; InputGroup Crawler::KEY_ATTACK; InputGroup Crawler::KEY_CONFIRM; +InputGroup Crawler::KEY_MENU; float Crawler::SIZE_CHANGE_SPEED=1; @@ -213,7 +214,7 @@ bool Crawler::OnUserUpdate(float fElapsedTime){ RenderMenu(); RenderFadeout(); RenderVersionInfo(); - return true; + return !gameEnd; } bool Crawler::LeftHeld(){ @@ -1933,6 +1934,7 @@ void Crawler::InitializeDefaultKeybinds(){ KEY_DOWN.AddKeybind({KEY,S}); KEY_CONFIRM.AddKeybind({MOUSE,Mouse::LEFT}); KEY_CONFIRM.AddKeybind({KEY,ENTER}); + KEY_MENU.AddKeybind({KEY,ESCAPE}); } void Crawler::SetBossNameDisplay(std::string name,float time){ @@ -2000,10 +2002,8 @@ void Crawler::RenderMenu(){ Menu::stack.back()->Update(this); } if(Menu::stack.size()>0){ - if(Menu::cover){ - FillRectDecal({0,0},WINDOW_SIZE,{0,0,0,uint8_t(255*0.4)}); - } for(Menu*menu:Menu::stack){ + if(menu->cover)FillRectDecal({0,0},WINDOW_SIZE,{0,0,0,uint8_t(255*0.4)}); menu->Draw(this); } } @@ -2216,4 +2216,8 @@ void Crawler::RenderFadeout(){ bool Crawler::GamePaused(){ return fadeOutDuration>0; +} + +void Crawler::EndGame(){ + gameEnd=true; } \ No newline at end of file diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index 23295e82..d5824e02 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -65,6 +65,7 @@ public: static InputGroup KEY_RIGHT; static InputGroup KEY_UP; static InputGroup KEY_DOWN; + static InputGroup KEY_MENU; static float SIZE_CHANGE_SPEED; float levelTime; Camera2D camera; @@ -107,7 +108,7 @@ private: float fadeOutTotalTime=0; float fadeInDuration=0; States::State transitionState=States::State::GAME_RUN; - + bool gameEnd=false; std::vectormonstersToBeSpawned; void ValidateGameStatus(); @@ -195,6 +196,7 @@ public: void ClearLoadoutItem(int slot); void RenderFadeout(); bool GamePaused(); + void EndGame(); struct TileGroupData{ vi2d tilePos; diff --git a/Crawler/Crawler.tiled-project b/Crawler/Crawler.tiled-project index fe25f51f..68bd7e44 100644 --- a/Crawler/Crawler.tiled-project +++ b/Crawler/Crawler.tiled-project @@ -294,6 +294,12 @@ "type": "string", "value": "CAMPAIGN_1_1" }, + { + "name": "Type", + "propertyType": "StageType", + "type": "string", + "value": "DUNGEON" + }, { "name": "Unlock Condition", "propertyType": "Level", @@ -308,6 +314,19 @@ "object" ] }, + { + "id": 26, + "name": "StageType", + "storageType": "string", + "type": "enum", + "values": [ + "DUNGEON", + "BOSS", + "STORY", + "SHOP" + ], + "valuesAsFlags": false + }, { "color": "#ffffaa00", "drawFill": true, diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index e10554d5..f98d357b 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -366,6 +366,10 @@ + + + + @@ -393,6 +397,10 @@ + + + + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 4d50d115..2021686f 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -464,6 +464,12 @@ Source Files\Game States + + Source Files\Interface + + + Source Files\Interface + diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index 172afe1c..5e5a0626 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -65,7 +65,6 @@ std::vectorMenu::unhandledComponents; ////////////////////////////////////////////////////////////////////////////////////////////////// MenuType Menu::lastMenuTypeCreated; std::string Menu::lastRegisteredComponent; -bool Menu::cover; INCLUDE_game INCLUDE_GFX @@ -96,6 +95,8 @@ void Menu::InitializeMenus(){ InitializeOverworldMapLevelWindow(); InitializeItemLoadoutWindow(); InitializeLevelCompleteWindow(); + InitializeOverworldMenuWindow(); + InitializeCharacterMenuWindow(); for(MenuType type=TEST;typecover=cover; stack.push_back(menus[menu]); } diff --git a/Crawler/Menu.h b/Crawler/Menu.h index 5c189274..1afc6334 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -57,6 +57,8 @@ enum MenuType{ OVERWORLD_LEVEL_SELECT, ITEM_LOADOUT, LEVEL_COMPLETE, + OVERWORLD_MENU, + CHARACTER_MENU, /////////////////////////////////////////////////////////// /*DO NOT REMOVE!!*/ENUM_END//////////////////////////////// /////////////////////////////////////////////////////////// @@ -133,6 +135,8 @@ private: static void InitializeOverworldMapLevelWindow(); static void InitializeItemLoadoutWindow(); static void InitializeLevelCompleteWindow(); + static void InitializeOverworldMenuWindow(); + static void InitializeCharacterMenuWindow(); void KeyboardButtonNavigation(Crawler*game,vf2d menuPos); static void DrawScaledWindowBackground(Crawler*game,vf2d menuPos,vf2d size,Pixel renderColor); @@ -145,7 +149,7 @@ private: Pixel GetRenderColor(); static bool MOUSE_NAVIGATION; - static bool cover; //A black cover for when a menu pops up to fade out the stuff behind it. + bool cover; //A black cover for when a menu pops up to fade out the stuff behind it. }; template diff --git a/Crawler/OverworldMenuWindow.cpp b/Crawler/OverworldMenuWindow.cpp new file mode 100644 index 00000000..08a1b32d --- /dev/null +++ b/Crawler/OverworldMenuWindow.cpp @@ -0,0 +1,58 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2018 - 2023 OneLoneCoder.com + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions or derivations of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions or derivative works in binary form must reproduce the above +copyright notice. This list of conditions and the following disclaimer must be +reproduced in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without specific +prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +Portions of this software are copyright © 2023 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. +*/ +#pragma endregion +#include "Menu.h" +#include "MenuComponent.h" +#include "Crawler.h" + +INCLUDE_game + +void Menu::InitializeOverworldMenuWindow(){ + Menu*overworldMenuWindow=CreateMenu(OVERWORLD_MENU,CENTERED,vi2d{96,164}); + + MenuComponent*resumeButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*0},{88,24}},"Resume",[](MenuFuncData data){Menu::CloseMenu();return true;}); + MenuComponent*characterButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*1},{88,24}},"Character",[](MenuFuncData data){Menu::OpenMenu(CHARACTER_MENU);return true;}); + MenuComponent*inventoryButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*2},{88,24}},"Inventory",[](MenuFuncData data){/*Menu::OpenMenu(INVENTORY_MENU);*/return true;}); + MenuComponent*settingsButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*3},{88,24}},"Settings",[](MenuFuncData data){/*Menu::OpenMenu(SETTINGS_MENU);*/return true;}); + MenuComponent*quitButton=NEW MenuComponent(OVERWORLD_MENU,{{4,12+28*4},{88,24}},"Quit Game",[](MenuFuncData data){game->EndGame();return true;}); + + overworldMenuWindow->AddComponent("Resume Button",resumeButton); + overworldMenuWindow->AddComponent("Character Button",characterButton); + overworldMenuWindow->AddComponent("Inventory Button",inventoryButton); + overworldMenuWindow->AddComponent("Settings Button",settingsButton); + overworldMenuWindow->AddComponent("Quit Button",quitButton); +} \ No newline at end of file diff --git a/Crawler/State_OverworldMap.cpp b/Crawler/State_OverworldMap.cpp index 752bd994..27cff8af 100644 --- a/Crawler/State_OverworldMap.cpp +++ b/Crawler/State_OverworldMap.cpp @@ -85,34 +85,41 @@ void State_OverworldMap::OnUserUpdate(Crawler*game){ } } - for(ConnectionPoint&cp:connections){ - if(game->GetMouse(Mouse::LEFT).bPressed&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)){ - for(int neighborInd:currentConnectionPoint->neighbors){ - if(neighborInd==-1)continue; - ConnectionPoint&neighbor=ConnectionPointFromIndex(neighborInd); - if(Unlock::IsUnlocked(neighbor.unlockCondition)&&&cp==&neighbor){ - currentConnectionPoint=&neighbor; - playerTargetPos=currentConnectionPoint->rect.pos+currentConnectionPoint->rect.size/2+vf2d{0,16}; - float angleTo=util::angleTo(game->GetPlayer()->GetPos(),playerTargetPos); - if(angleTo>=-3*PI/4&&angleTo<-PI/4){ - game->GetPlayer()->UpdateWalkingAnimation(UP); - }else - if(angleTo=-PI/4){ - game->GetPlayer()->UpdateWalkingAnimation(RIGHT); - }else - if(angleTo>=PI/4&&angleTo<3*PI/4){ - game->GetPlayer()->UpdateWalkingAnimation(DOWN); - }else{ - game->GetPlayer()->UpdateWalkingAnimation(LEFT); + if(Crawler::KEY_MENU.Pressed()){ + Menu::OpenMenu(OVERWORLD_MENU); + } + + #pragma region Handle Connection Point Clicking and Movement + for(ConnectionPoint&cp:connections){ + if(game->GetMouse(Mouse::LEFT).bPressed&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)){ + for(int neighborInd:currentConnectionPoint->neighbors){ + if(neighborInd==-1)continue; + ConnectionPoint&neighbor=ConnectionPointFromIndex(neighborInd); + if(Unlock::IsUnlocked(neighbor.unlockCondition)&&&cp==&neighbor){ + currentConnectionPoint=&neighbor; + playerTargetPos=currentConnectionPoint->rect.pos+currentConnectionPoint->rect.size/2+vf2d{0,16}; + float angleTo=util::angleTo(game->GetPlayer()->GetPos(),playerTargetPos); + if(angleTo>=-3*PI/4&&angleTo<-PI/4){ + game->GetPlayer()->UpdateWalkingAnimation(UP); + }else + if(angleTo=-PI/4){ + game->GetPlayer()->UpdateWalkingAnimation(RIGHT); + }else + if(angleTo>=PI/4&&angleTo<3*PI/4){ + game->GetPlayer()->UpdateWalkingAnimation(DOWN); + }else{ + game->GetPlayer()->UpdateWalkingAnimation(LEFT); + } + Component(OVERWORLD_LEVEL_SELECT,"Stage Label")->SetLabel(currentConnectionPoint->name); + Component(OVERWORLD_LEVEL_SELECT,"Spawns List")->UpdateSpawns(currentConnectionPoint->spawns); + Component(OVERWORLD_LEVEL_SELECT,"Enter Button")->Enable(currentConnectionPoint->levelDataExists); + Component(OVERWORLD_LEVEL_SELECT,"Change Loadout Button")->Enable(!(currentConnectionPoint->type=="STORY"||currentConnectionPoint->type=="SHOP")); + break; } - Component(OVERWORLD_LEVEL_SELECT,"Stage Label")->SetLabel(currentConnectionPoint->name); - Component(OVERWORLD_LEVEL_SELECT,"Spawns List")->UpdateSpawns(currentConnectionPoint->spawns); - Component(OVERWORLD_LEVEL_SELECT,"Enter Button")->Enable(currentConnectionPoint->levelDataExists); - break; } } } - } + #pragma endregion }; void State_OverworldMap::Draw(Crawler*game){ currentTime+=game->GetElapsedTime(); diff --git a/Crawler/TMXParser.h b/Crawler/TMXParser.h index bec8d4f2..deb96233 100644 --- a/Crawler/TMXParser.h +++ b/Crawler/TMXParser.h @@ -249,8 +249,6 @@ class TMXParser{ return parsedMapInfo; } void TMXParser::ParseTag(std::string tag) { - - auto ReadNextTag=[&](){ XMLTag newTag; //First character is a '<' so we discard it. @@ -342,9 +340,6 @@ class TMXParser{ parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2}; } else if (newTag.tag=="object"&&newTag.data["type"]=="Monster") { - //XMLTag monsterTag=ReadNextTag(); - //XMLTag spawnerLinkTag=ReadNextTag(); - //newTag.data["value"]=monsterTag.GetInteger("value"); //Value now contains which monster name this spawn represents. monsterTag=newTag; monsterPropertyTagCount=0; } else @@ -458,7 +453,7 @@ class TMXParser{ for(auto key:stagePlates){ StagePlate&plate=key.second; idToIndexMap[plate.tag.GetInteger("id")]=int(State_OverworldMap::connections.size()); - ConnectionPoint newConnection={{{plate.tag.GetFloat("x"),plate.tag.GetFloat("y")},{plate.tag.GetFloat("width"),plate.tag.GetFloat("height")}},plate.tag.data["name"],plate.properties["Map"].value,plate.properties["Unlock Condition"].value,{}}; + ConnectionPoint newConnection={{{plate.tag.GetFloat("x"),plate.tag.GetFloat("y")},{plate.tag.GetFloat("width"),plate.tag.GetFloat("height")}},plate.properties["Type"].value,plate.tag.data["name"],plate.properties["Map"].value,plate.properties["Unlock Condition"].value,{}}; int iterationCount=0; for(auto key2:plate.properties){ if(key2.first.starts_with("Connection ")){ diff --git a/Crawler/Version.h b/Crawler/Version.h index 547647fc..90101429 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 3321 +#define VERSION_BUILD 3326 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/Campaigns/World_Map.tmx b/Crawler/assets/Campaigns/World_Map.tmx index 8c611bab..7a6ce804 100644 --- a/Crawler/assets/Campaigns/World_Map.tmx +++ b/Crawler/assets/Campaigns/World_Map.tmx @@ -560,6 +560,7 @@ + @@ -567,6 +568,7 @@ + @@ -574,6 +576,7 @@ + @@ -583,6 +586,7 @@ + @@ -590,12 +594,14 @@ + + @@ -604,6 +610,7 @@ +