diff --git a/C++ProjectTemplate b/C++ProjectTemplate index dd48660..28ad7ec 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index a76e8ec..3873f8b 100644 --- a/main.cpp +++ b/main.cpp @@ -163,8 +163,9 @@ public: bool HEALING_OVERWORLD_SINGLE_MEMBER=false; //When set to true, a single member is being healed. bool OVERWORLD_ITEM_BEING_USED=false; //When set to true, we need to equip an item after target selected. std::string DISPLAY_TARGET_MESSAGE=""; //Display some text while selecting a target. - Key KEY_GENERATE_EVENTS=UP; - float lastPress=0; + Key KEY_LASTPRESSED=NONE; + int lastPress=0; + int lastRepeatedFrame=0; bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things. @@ -303,13 +304,13 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"), return true; } - void GetAnyKey() { - - } - void GetAnyKeyPress(olc::Key keypress) override { - if (keypress==UP||keypress==DOWN||keypress==RIGHT||keypress==LEFT) { - KEY_GENERATE_EVENTS=keypress; + if (keypress==UP||keypress==DOWN||keypress==RIGHT||keypress==LEFT|| + keypress==W||keypress==A||keypress==S||keypress==D|| + keypress==NP2||keypress==NP4||keypress==NP5||keypress==NP6||keypress==NP8) { + KEY_LASTPRESSED=keypress; + lastPress=frameCount; + lastRepeatedFrame=frameCount; } if (messageBoxVisible) { if (messageBoxMarker==messageBoxFinalText.length()) { @@ -675,6 +676,10 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"), StartEffect(FOUNTAIN_EFFECT); } + if (GetKey(KEY_LASTPRESSED).bReleased) { + KEY_LASTPRESSED=NONE; + } + if (BATTLE_ENCOUNTER!=nullptr&&!messageBoxVisible) { switch (BATTLE_STATE) { case BattleState::SELECT_ACTION:{ @@ -2654,16 +2659,16 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"), return GetKey(TAB).bHeld; } bool UpPressed(){ - return GetKey(W).bPressed||GetKey(UP).bPressed||GetKey(NP8).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128; + return GetKey(W).bPressed||GetKey(UP).bPressed||GetKey(NP8).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128||KeyRepeat(UP); } bool DownPressed(){ - return GetKey(S).bPressed||GetKey(DOWN).bPressed||GetKey(NP5).bPressed||GetKey(NP2).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32&&GetMouseX()<=HEIGHT-128; + return GetKey(S).bPressed||GetKey(DOWN).bPressed||GetKey(NP5).bPressed||GetKey(NP2).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32&&GetMouseX()<=HEIGHT-128||KeyRepeat(DOWN); } bool LeftPressed(){ - return GetKey(A).bPressed||GetKey(LEFT).bPressed||GetKey(NP4).bPressed||MOUSE_PRESSED_DOWN&&GetMouseX()<=32&&GetMouseX()>=0&&GetMouseY()>=HEIGHT-128; + return GetKey(A).bPressed||GetKey(LEFT).bPressed||GetKey(NP4).bPressed||MOUSE_PRESSED_DOWN&&GetMouseX()<=32&&GetMouseX()>=0&&GetMouseY()>=HEIGHT-128||KeyRepeat(LEFT); } bool RightPressed(){ - return GetKey(D).bPressed||GetKey(RIGHT).bPressed||GetKey(NP6).bPressed||MOUSE_PRESSED_DOWN&&GetMouseX()<=128&&GetMouseX()>=96&&GetMouseY()>=HEIGHT-128; + return GetKey(D).bPressed||GetKey(RIGHT).bPressed||GetKey(NP6).bPressed||MOUSE_PRESSED_DOWN&&GetMouseX()<=128&&GetMouseX()>=96&&GetMouseY()>=HEIGHT-128||KeyRepeat(RIGHT); } bool UpHeld(){ return GetKey(W).bHeld||GetKey(UP).bHeld||GetKey(NP8).bHeld||MOUSE_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128; @@ -4148,6 +4153,33 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"), } } } + + //Returns true if the key is meant to be continuously repeated because of being held down. + //dir should be UP,DOWN,LEFT,RIGHT + bool KeyRepeat(Key dir) { + if (KEY_LASTPRESSED!=NONE) { + bool allowed=false; + switch (dir) { + case UP:{ + allowed=(KEY_LASTPRESSED==W||KEY_LASTPRESSED==NP8||KEY_LASTPRESSED==UP)&&frameCount-lastPress>20&&frameCount%4==0&&lastRepeatedFrame!=frameCount; + }break; + case DOWN:{ + allowed=(KEY_LASTPRESSED==S||KEY_LASTPRESSED==NP2||KEY_LASTPRESSED==NP5||KEY_LASTPRESSED==DOWN)&&frameCount-lastPress>20&&frameCount%4==0&&lastRepeatedFrame!=frameCount; + }break; + case LEFT:{ + allowed=(KEY_LASTPRESSED==A||KEY_LASTPRESSED==NP4||KEY_LASTPRESSED==LEFT)&&frameCount-lastPress>20&&frameCount%4==0&&lastRepeatedFrame!=frameCount; + }break; + case RIGHT:{ + allowed=(KEY_LASTPRESSED==D||KEY_LASTPRESSED==NP6||KEY_LASTPRESSED==RIGHT)&&frameCount-lastPress>20&&frameCount%4==0&&lastRepeatedFrame!=frameCount; + }break; + } + if (allowed) { + lastRepeatedFrame=frameCount; + return true; + } + } + return false; + } }; int main()