diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 436cd7a..a8ef353 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 5a1e567..07c583d 100644 --- a/main.cpp +++ b/main.cpp @@ -267,6 +267,7 @@ class Entity{ int damageReduction=0; //A percentage of how much damage to reduce. bool smart=false; bool dumb=false; + int atb=0; //When this value reaches 1000, it's this entity's turn. Object* obj; std::vector moveSet; //Used for initializing players. @@ -299,6 +300,18 @@ class Encounter{ int id; Encounter(int id,vd2d pos,std::array playerPos,std::vectorobjs,int chance=25) :id(id),pos(pos),objs(objs),chance(chance),playerPos(playerPos){} + bool IsEncounterAlive() { + for (int i=0;iHP>0) { + return true; + } + } + return false; + } + bool IsInRange(vd2d pos) { + vd2d diff=pos-this->pos; + return diff.x>=0&&diff.x<=WIDTH&&diff.y>=0&&diff.y<=HEIGHT; + } }; @@ -369,6 +382,8 @@ public: int ENCOUNTER_OFFSET = 0; std::vectorENCOUNTER_LIST; Encounter*EDITING_ENCOUNTER=nullptr; + Encounter*BATTLE_ENCOUNTER=nullptr; + int BATTLE_STATE=BattleState::MOVE_CAMERA; bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things. @@ -644,24 +659,42 @@ goes on a very long time, I hope you can understand this is only for testing pur }break; case GameState::GAME_WORLD:{ if (PlayerCanMove()) { + bool moved=false; if (UpHeld()) { if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,-1})) { UpdatePlayerTrail({0,-1}); + moved=true; } } if (DownHeld()) { if (PARTY_MEMBER_OBJ[0]->SmoothMove({0,1})) { UpdatePlayerTrail({0,1}); + moved=true; } } if (LeftHeld()) { if (PARTY_MEMBER_OBJ[0]->SmoothMove({-1,0})) { UpdatePlayerTrail({-1,0}); + moved=true; } } if (RightHeld()) { if (PARTY_MEMBER_OBJ[0]->SmoothMove({1,0})) { UpdatePlayerTrail({1,0}); + moved=true; + } + } + if (moved) { + vi2d cameraOffset={WIDTH/2,HEIGHT/2}; + cameraPos=PARTY_MEMBER_OBJ[0]->GetPos()-cameraOffset; + } + if (moved&&BATTLE_ENCOUNTER==nullptr) { + for (int i=0;iencounters.size();i++) { + if (CURRENT_MAP->encounters[i]->IsEncounterAlive()&&CURRENT_MAP->encounters[i]->IsInRange(PARTY_MEMBER_OBJ[0]->GetPos())) { + BATTLE_STATE=BattleState::MOVE_CAMERA; + BATTLE_ENCOUNTER=CURRENT_MAP->encounters[i]; + break; + } } } } @@ -1716,7 +1749,7 @@ goes on a very long time, I hope you can understand this is only for testing pur } bool PlayerCanMove(){ - return !IsTextEntryEnabled()&&!messageBoxVisible&&PARTY_MEMBER_OBJ[0]!=nullptr; + return BATTLE_ENCOUNTER==nullptr&&!IsTextEntryEnabled()&&!messageBoxVisible&&PARTY_MEMBER_OBJ[0]!=nullptr; } void DisplayMessageBox(std::string targetText) { diff --git a/states.h b/states.h index cb016b8..9b84af9 100644 --- a/states.h +++ b/states.h @@ -6,4 +6,13 @@ namespace GameState{ ENCOUNTER_SELECT, GAME_WORLD, }; +} + +namespace BattleState{ + enum{ + MOVE_CAMERA, + WAIT, + WAIT_ANIMATION, + SELECT_ACTION, + }; } \ No newline at end of file