diff --git a/SeasonsOfLoneliness.cpp b/SeasonsOfLoneliness.cpp index e77c853..1334857 100644 --- a/SeasonsOfLoneliness.cpp +++ b/SeasonsOfLoneliness.cpp @@ -673,7 +673,7 @@ public: std::string CONSOLE_REF_TEXT; bool SOUND_IS_PLAYING=false; int MAIN_MENU_SELECTION=0; - std::string MENU_OPTIONS[4]={"NEW GAME","CONTINUE","MUTE SOUND","EXIT"}; + std::string MENU_OPTIONS[4]={"NEW GAME","MUTE SOUND","EXIT"}; int BATTLE_REASON_CODE=-1; bool BATTLE_DROUGHT_ACTIVE=false; bool ROCKET_BOARD_OPTION=false; @@ -682,6 +682,8 @@ public: vf2d BOSS_SIZE={1,1}; vf2d CREDITS_SCROLLING_OFFSET={0,12}; bool HIDE_CARDS=false; + bool USE_TOUCH_CONTROLS=false; + bool MOUSE_DOWN=false; Map*MAP_1=new Map("map1"); Map*MAP_2=new Map("map2"); @@ -700,7 +702,7 @@ public: *SANDWORM_DECAL,*SNAKE_DECAL,*MOTH_DECAL,*FLASH_FLOOD_DECAL,*SUNNY_DAY_DECAL,*FIRESTORM_DECAL,*SOLARFLARE_DECAL, *HP_REGEN_DECAL,*SLOWED_DECAL, *SPEED_DECAL,*HIDDEN_DECAL,*BOOK_DECAL,*BOOK2_DECAL, *LAUNCHPAD_CLOSED_DECAL,*LAUNCHPAD_HALF1_DECAL,*LAUNCHPAD_HALF2_DECAL,*LAUNCHPAD_DECAL,*Y_Y_DECAL, - *PETRIFY_DECAL,*A_A_DECAL,*A_A_RECHARGE_DECAL, *ENERGYBALL_DECAL; + *PETRIFY_DECAL,*A_A_DECAL,*A_A_RECHARGE_DECAL, *ENERGYBALL_DECAL, *TOUCHSCREEN_DECAL; std::map BASE_OBJECTS; std::vector ENCOUNTERS; Encounter ENCOUNTER_SPIDEY_1; @@ -734,6 +736,8 @@ public: int PETRIFY_TURNS=0; int LAST_FRAME_SOUND_PLAYED=0; bool queueBGMPlayback=false; + bool MOUSE_PRESSED_DOWN=false; + bool MOUSE_RELEASED=false; Map*CURRENT_MAP=MAP_1; @@ -885,6 +889,7 @@ public: A_A_DECAL=new Decal(new Sprite("assets/A.A.png")); A_A_RECHARGE_DECAL=new Decal(new Sprite("assets/A.A_recharge.png")); ENERGYBALL_DECAL=new Decal(new Sprite("assets/energyball.png")); + TOUCHSCREEN_DECAL=new Decal(new Sprite("assets/touchcontroller.png")); playerAnim->spr=PLAYER_DECAL; playerAnimRight->spr=PLAYER_DECAL; @@ -1272,6 +1277,11 @@ public: } return; } + if (GetMouse(0).bPressed) { + USE_TOUCH_CONTROLS=true; + } else { + USE_TOUCH_CONTROLS=false; + } if (!GetKey(W).bPressed&&!GetKey(A).bPressed&&!GetKey(S).bPressed&&!GetKey(D).bPressed&& !GetKey(UP).bPressed&&!GetKey(RIGHT).bPressed&&!GetKey(DOWN).bPressed&&!GetKey(LEFT).bPressed) { ActionButtonPress(); @@ -1309,6 +1319,13 @@ public: } void ActionButtonPress() { + if (GetMouse(0).bPressed) { + MOUSE_DOWN=true; + MOUSE_PRESSED_DOWN=true; + if (GetMouseX()<128&&GetMouseY()>128) { + return; + } + } if (playerCanMove()) { switch (GAME_STATE) { case GAMEWORLD:{ @@ -1326,23 +1343,22 @@ public: } if (GAME_STATE==CUTSCENE_3) { switch (MAIN_MENU_SELECTION) { - case 0: - case 1:{ + case 0:{ PlaySound(&SOUND_SELECT); fadeOut(); audioFadeOut(); }break; - case 2:{ + case 1:{ SOUND_IS_MUTED=!SOUND_IS_MUTED; if (SOUND_IS_MUTED) { - MENU_OPTIONS[2]="UNMUTE SOUND"; + MENU_OPTIONS[1]="UNMUTE SOUND"; engine.SetOutputVolume(0); } else { - MENU_OPTIONS[2]="MUTE SOUND"; + MENU_OPTIONS[1]="MUTE SOUND"; engine.SetOutputVolume(0.6); } }break; - case 3:{ + case 2:{ END_THE_GAME=true; }break; } @@ -1412,41 +1428,45 @@ public: bool OnUserUpdate(float fElapsedTime) override { elapsedTime+=fElapsedTime; + if (GetMouse(0).bReleased) { + MOUSE_DOWN=false; + MOUSE_RELEASED=true; + } while (elapsedTime>TARGET_RATE) { elapsedTime-=TARGET_RATE; updateGame(); rand(); } if (GetKey(F1).bPressed) { - ConsoleShow(F1,false); + //ConsoleShow(F1,false); //Disable for official release. } if (playerCanMove()) { - if (GetKey(D).bPressed||GetKey(RIGHT).bPressed||GetKey(NP6).bPressed) { + if (RightPressed()) { changeAnimation(playerAnimWalkRight); } - if (GetKey(A).bPressed||GetKey(LEFT).bPressed||GetKey(NP4).bPressed) { + if (LeftPressed()) { changeAnimation(playerAnimWalkLeft); } - if (GetKey(W).bPressed||GetKey(UP).bPressed||GetKey(NP8).bPressed) { + if (UpPressed()) { changeAnimation(playerAnimWalkUp); } - if (GetKey(S).bPressed||GetKey(DOWN).bPressed||GetKey(NP5).bPressed||GetKey(NP2).bPressed) { + if (DownPressed()) { changeAnimation(playerAnimWalkDown); } - if (!GetKey(D).bHeld&&!GetKey(RIGHT).bHeld&&!GetKey(NP6).bHeld&& - !GetKey(A).bHeld&&!GetKey(LEFT).bHeld&&!GetKey(NP4).bHeld&& - !GetKey(S).bHeld&&!GetKey(UP).bHeld&&!GetKey(NP8).bHeld&& - !GetKey(W).bHeld&&!GetKey(DOWN).bHeld&&!GetKey(NP5).bHeld&&!GetKey(NP2).bHeld) { - if (GetKey(D).bReleased||GetKey(RIGHT).bReleased||GetKey(NP6).bReleased) { + if (!RightHeld()&& + !LeftHeld()&& + !UpHeld()&& + !DownHeld()) { + if (RightReleased()) { changeAnimation(playerAnimRight); } - if (GetKey(A).bReleased||GetKey(LEFT).bReleased||GetKey(NP4).bReleased) { + if (LeftReleased()) { changeAnimation(playerAnimLeft); } - if (GetKey(W).bReleased||GetKey(UP).bReleased||GetKey(NP8).bReleased) { + if (UpReleased()) { changeAnimation(playerAnim); } - if (GetKey(S).bReleased||GetKey(DOWN).bReleased||GetKey(NP5).bReleased||GetKey(NP2).bReleased) { + if (DownReleased()) { changeAnimation(playerAnimDown); } } @@ -1454,12 +1474,12 @@ public: if (IN_BATTLE_ENCOUNTER&&!messageBoxVisible) { switch (BATTLE_STATE) { case battle::PLAYER_SELECTION:{ - if (GetKey(D).bPressed||GetKey(RIGHT).bPressed||GetKey(NP6).bPressed) { + if (RightPressed()) { BATTLE_CARD_SELECTION_IND=(BATTLE_CARD_SELECTION_IND+1)%availablePowers.size(); BATTLE_CARD_SELECTION=availablePowers[BATTLE_CARD_SELECTION_IND]; PlaySound(&SOUND_CHANGE_OPTION); } - if (GetKey(A).bPressed||GetKey(LEFT).bPressed||GetKey(NP4).bPressed) { + if (LeftPressed()) { if (--BATTLE_CARD_SELECTION_IND<0) { BATTLE_CARD_SELECTION_IND=availablePowers.size()-1; } @@ -1468,7 +1488,7 @@ public: } }break; case battle::PLAYER_TARGET_SELECTION:{ - if (GetKey(D).bPressed||GetKey(RIGHT).bPressed||GetKey(NP6).bPressed) { + if (RightPressed()) { while (true) { PLAYER_SELECTED_TARGET=(PLAYER_SELECTED_TARGET+1)%CURRENT_ENCOUNTER.entities.size(); if (CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->hp>0) { @@ -1477,12 +1497,12 @@ public: } PlaySound(&SOUND_CHANGE_OPTION); } - if (GetKey(W).bPressed||GetKey(UP).bPressed||GetKey(NP8).bPressed) { + if (UpPressed()) { PLAYER_SELECTED_TARGET=-1; //std::cout<<"Battle State is "<=28) { TERMINAL_SELECTED_CHAR=(TERMINAL_SELECTED_CHAR+7)%28; } else { @@ -1544,7 +1564,7 @@ public: } }break; case cutscene::READY_TO_BOARD:{ - if (GetKey(W).bPressed||GetKey(UP).bPressed||GetKey(NP8).bPressed||GetKey(S).bPressed||GetKey(DOWN).bPressed||GetKey(NP5).bPressed||GetKey(NP2).bPressed) { + if (UpPressed()||DownPressed()) { ROCKET_BOARD_OPTION=!ROCKET_BOARD_OPTION; } }break; @@ -1556,6 +1576,8 @@ public: Clear(BLANK); SetDrawTarget(2); drawGame(); + MOUSE_PRESSED_DOWN=false; + MOUSE_RELEASED=false; // called once per frame return !END_THE_GAME; } @@ -1955,7 +1977,7 @@ public: if (playerCanMove()) { bool animationchanged=false; bool positionModified=false; - if (GetKey(D).bHeld||GetKey(RIGHT).bHeld||GetKey(NP6).bHeld) { + if (RightHeld()) { if (GAME_STATE!=IN_SPACE&&MAP[(int)PLAYER_COORDS[1]][(int)std::clamp(PLAYER_COORDS[0]+MOVE_SPD,0.1,(double)MAP_WIDTH)]!=4) { PLAYER_COORDS[0]=std::clamp(PLAYER_COORDS[0]+MOVE_SPD,0.1,(double)MAP_WIDTH); positionModified=true; @@ -1967,7 +1989,7 @@ public: animationchanged=true; } } - if (GetKey(A).bHeld||GetKey(LEFT).bHeld||GetKey(NP4).bHeld) { + if (LeftHeld()) { if (GAME_STATE!=IN_SPACE&&MAP[(int)PLAYER_COORDS[1]][(int)std::clamp(PLAYER_COORDS[0]-MOVE_SPD,0.1,(double)MAP_WIDTH)]!=4) { PLAYER_COORDS[0]=std::clamp(PLAYER_COORDS[0]-MOVE_SPD,0.1,(double)MAP_WIDTH); positionModified=true; @@ -1979,7 +2001,7 @@ public: animationchanged=true; } } - if (GetKey(W).bHeld||GetKey(UP).bHeld||GetKey(NP8).bHeld) { + if (UpHeld()) { if (GAME_STATE!=IN_SPACE&&MAP[(int)std::clamp(PLAYER_COORDS[1]-MOVE_SPD,0.1,(double)MAP_HEIGHT)][(int)PLAYER_COORDS[0]]!=4) { PLAYER_COORDS[1]=std::clamp(PLAYER_COORDS[1]-MOVE_SPD,0.1,(double)MAP_HEIGHT); positionModified=true; @@ -1996,7 +2018,7 @@ public: } else { HIDE_CARDS=false; } - if (GetKey(S).bHeld||GetKey(DOWN).bHeld||GetKey(NP5).bHeld||GetKey(NP2).bHeld) { + if (DownHeld()) { if (GAME_STATE!=IN_SPACE&&MAP[(int)std::clamp(PLAYER_COORDS[1]+MOVE_SPD,0.1,(double)MAP_HEIGHT)][(int)PLAYER_COORDS[0]]!=4) { PLAYER_COORDS[1]=std::clamp(PLAYER_COORDS[1]+MOVE_SPD,0.1,(double)MAP_HEIGHT); positionModified=true; @@ -3690,6 +3712,9 @@ public: FillRectDecal({0,0},{WIDTH,HEIGHT},Pixel(ORIGINAL_FOREGROUND_EFFECT_COLOR.r,ORIGINAL_FOREGROUND_EFFECT_COLOR.g,ORIGINAL_FOREGROUND_EFFECT_COLOR.b,ORIGINAL_FOREGROUND_EFFECT_COLOR.a*PIXEL_EFFECT_TRANSPARENCY)); SetDrawTarget(2); } + if (USE_TOUCH_CONTROLS&&(CURRENT_CUTSCENE==cutscene::NONE||CURRENT_CUTSCENE==cutscene::INPUT_USERNAME||CURRENT_CUTSCENE==cutscene::READY_TO_BOARD)) { + DrawDecal({0,HEIGHT-128},TOUCHSCREEN_DECAL,{1,1},Pixel(255,255,255,128)); + } if (messageBoxVisible) { SetDrawTarget(nullptr); DrawDialogBox({4,HEIGHT-60},{WIDTH/2,16},Pixel(18, 0, 33,180)); @@ -4661,6 +4686,43 @@ public: FillRectDecal(starpixels[i]->pos,starpixels[i]->size,{(uint8_t)(starpixels[i]->r),(uint8_t)(starpixels[i]->g),(uint8_t)(starpixels[i]->b),(uint8_t)(std::clamp(distanceFromCenter/64.0*255,0.0,255.0))}); } } + + bool UpPressed(){ + return GetKey(W).bPressed||GetKey(UP).bPressed||GetKey(NP8).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128; + } + bool DownPressed(){ + return GetKey(S).bPressed||GetKey(DOWN).bPressed||GetKey(NP5).bPressed||GetKey(NP2).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32; + } + bool LeftPressed(){ + return GetKey(A).bPressed||GetKey(LEFT).bPressed||GetKey(NP4).bPressed||MOUSE_PRESSED_DOWN&&GetMouseX()<=32&&GetMouseX()>=0; + } + bool RightPressed(){ + return GetKey(D).bPressed||GetKey(RIGHT).bPressed||GetKey(NP6).bPressed||MOUSE_PRESSED_DOWN&&GetMouseX()<=128&&GetMouseX()>=96; + } + bool UpHeld(){ + return GetKey(W).bHeld||GetKey(UP).bHeld||GetKey(NP8).bHeld||MOUSE_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128; + } + bool DownHeld(){ + return GetKey(S).bHeld||GetKey(DOWN).bHeld||GetKey(NP5).bHeld||GetKey(NP2).bHeld||MOUSE_DOWN&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32; + } + bool LeftHeld(){ + return GetKey(A).bHeld||GetKey(LEFT).bHeld||GetKey(NP4).bHeld||MOUSE_DOWN&&GetMouseX()<=32&&GetMouseX()>=0; + } + bool RightHeld(){ + return GetKey(D).bHeld||GetKey(RIGHT).bHeld||GetKey(NP6).bHeld||MOUSE_DOWN&&GetMouseX()<=128&&GetMouseX()>=96; + } + bool UpReleased(){ + return GetKey(W).bReleased||GetKey(UP).bReleased||GetKey(NP8).bReleased||MOUSE_RELEASED&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128; + } + bool DownReleased(){ + return GetKey(S).bReleased||GetKey(DOWN).bReleased||GetKey(NP5).bReleased||GetKey(NP2).bReleased||MOUSE_RELEASED&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32; + } + bool LeftReleased(){ + return GetKey(A).bReleased||GetKey(LEFT).bReleased||GetKey(NP4).bReleased||MOUSE_RELEASED&&GetMouseX()<=32&&GetMouseX()>=0; + } + bool RightReleased(){ + return GetKey(D).bReleased||GetKey(RIGHT).bReleased||GetKey(NP6).bReleased||MOUSE_RELEASED&&GetMouseX()<=128&&GetMouseX()>=96; + } }; diff --git a/Seasons_of_Loneliness b/Seasons_of_Loneliness index 288b52b..3e85421 100755 Binary files a/Seasons_of_Loneliness and b/Seasons_of_Loneliness differ diff --git a/assets/touchcontroller.png b/assets/touchcontroller.png new file mode 100644 index 0000000..e2abd0e Binary files /dev/null and b/assets/touchcontroller.png differ