From 1fd37bbd5123a26d56478e0b66d7e190064be06d Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 15 Jan 2024 03:22:34 -0600 Subject: [PATCH] Added controller vibration for world shake events/player hurt events. --- .../AdventuresInLestoria.cpp | 15 ++++++++++++ Adventures in Lestoria/Menu.cpp | 10 ++++---- Adventures in Lestoria/Player.cpp | 23 +++++++++++++++++++ Adventures in Lestoria/Player.h | 1 + Adventures in Lestoria/Version.h | 2 +- .../assets/config/Player.txt | 3 +++ 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 4fa18950..831584fc 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -567,6 +567,13 @@ void AiL::UpdateCamera(float fElapsedTime){ worldShakeTime-=fElapsedTime; if(worldShakeTime<=0){ camera.SetTarget(player->GetPos()); + #pragma region Gamepad Stop Vibration + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected){ + gamepad->stopVibration(); + } + } + #pragma endregion } if(lastWorldShakeAdjust==0){ lastWorldShakeAdjust=0.02f; @@ -1553,6 +1560,13 @@ void AiL::SetupWorldShake(float duration){ worldShakeTime=duration; worldShake=vf2d{player->GetPos()}; camera.SetTarget(worldShake); + #pragma region Controller Vibration + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected){ + gamepad->startVibration(); + } + } + #pragma endregion } @@ -2329,6 +2343,7 @@ void AiL::InitializeDefaultKeybinds(){ KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_D)}); KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_R)}); KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast(GPButtons::START)}); + KEY_CONFIRM.AddKeybind({KEY,SPACE}); KEY_CONFIRM.AddKeybind({KEY,ENTER}); KEY_MENU.AddKeybind({KEY,ESCAPE}); KEY_MENU.AddKeybind({CONTROLLER,static_cast(GPButtons::START)}); diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index 854837f1..1daa3da9 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -151,7 +151,7 @@ Menu*Menu::CreateMenu(MenuType type,vf2d pos,vf2d size){ } void Menu::CheckClickAndPerformMenuSelect(AiL*game){ - if(game->GetMouse(Mouse::LEFT).bReleased||game->GetKey(SPACE).bReleased||game->GetKey(ENTER).bReleased){ + if(game->KEY_CONFIRM.Released()){ MenuSelect(game); } } @@ -231,7 +231,7 @@ void Menu::Update(AiL*game){ } } - if(itemHovered&&draggingComponent==nullptr&&selection!=vi2d{-1,-1}&&(((!UsingMouseNavigation()&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){ + if(itemHovered&&draggingComponent==nullptr&&selection!=vi2d{-1,-1}&&!UsingMouseNavigation()&&(game->KEY_CONFIRM.Held())){ buttonHoldTime+=game->GetElapsedTime(); }else{ buttonHoldTime=0; @@ -251,7 +251,7 @@ void Menu::Update(AiL*game){ if(!UsingMouseNavigation()){ if(!game->IsTextEntryEnabled()){ - if(game->GetKey(ENTER).bReleased||game->GetKey(SPACE).bReleased){ + if(game->KEY_CONFIRM.Released()){ if(selectedComponent==nullptr){//Dropping over an empty area. ClearDraggingComponent(); }else @@ -261,7 +261,7 @@ void Menu::Update(AiL*game){ } } }else{ - if(game->GetMouse(Mouse::LEFT).bReleased){ + if(game->KEY_CONFIRM.Released()){ if(selectedComponent==nullptr){//Dropping over an empty area. ClearDraggingComponent(); }else @@ -449,7 +449,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ selection.x=-1; } } - if(game->GetMouse(0).bPressed||game->GetKey(ENTER).bPressed||game->GetKey(SPACE).bPressed){ + if(game->KEY_CONFIRM.Pressed()){ SetMouseNavigation(game->GetMouse(0).bPressed); //If a click occurs we use mouse controls. if(!UsingMouseNavigation()){ buttonHoldTime=0; diff --git a/Adventures in Lestoria/Player.cpp b/Adventures in Lestoria/Player.cpp index 5639d834..91647b28 100644 --- a/Adventures in Lestoria/Player.cpp +++ b/Adventures in Lestoria/Player.cpp @@ -51,6 +51,7 @@ All rights reserved. #include "config.h" #include #include "SoundEffect.h" +#include "olcPGEX_Gamepad.h" INCLUDE_MONSTER_DATA INCLUDE_MONSTER_LIST @@ -284,6 +285,18 @@ void Player::Update(float fElapsedTime){ notEnoughManaDisplay.second=std::max(0.f,notEnoughManaDisplay.second-fElapsedTime); notificationDisplay.second=std::max(0.f,notificationDisplay.second-fElapsedTime); lastHitTimer=std::max(0.f,lastHitTimer-fElapsedTime); + if(hurtRumbleTime>0.f){ + hurtRumbleTime=std::max(0.f,hurtRumbleTime-fElapsedTime); + if(hurtRumbleTime==0.f){ + #pragma region Gamepad Stop Vibration + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected){ + gamepad->stopVibration(); + } + } + #pragma endregion + } + } blockTimer=std::max(0.f,blockTimer-fElapsedTime); lastCombatTime=lastCombatTime+fElapsedTime; manaTickTimer-=fElapsedTime; @@ -704,6 +717,16 @@ bool Player::Hurt(int damage,bool onUpperLevel,float z){ SoundEffect::PlaySFX("Player Hit",SoundEffect::CENTERED); } hp=std::max(0,hp-int(mod_dmg)); + + #pragma region Gamepad Vibration + hurtRumbleTime="Player.Hurt Rumble Time"_F; + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected){ + gamepad->startVibration(); + } + } + #pragma endregion + if(lastHitTimer>0){ damageNumberPtr.get()->damage+=int(mod_dmg); damageNumberPtr.get()->pauseTime=0.4f; diff --git a/Adventures in Lestoria/Player.h b/Adventures in Lestoria/Player.h index f7616f3a..fe12ffc8 100644 --- a/Adventures in Lestoria/Player.h +++ b/Adventures in Lestoria/Player.h @@ -277,6 +277,7 @@ private: void Initialize(); float iframe_time=0; float lastCombatTime=0; + float hurtRumbleTime=0.0f; Ability useItem1; Ability useItem2; Ability useItem3; diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 1c5cd6dd..3d5fa86c 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 5830 +#define VERSION_BUILD 5837 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Adventures in Lestoria/assets/config/Player.txt b/Adventures in Lestoria/assets/config/Player.txt index 7a35a41c..314f609f 100644 --- a/Adventures in Lestoria/assets/config/Player.txt +++ b/Adventures in Lestoria/assets/config/Player.txt @@ -29,6 +29,9 @@ Player # How long between each footstep. Footstep Timer = 0.4 + # How long the rumble lasts when getting hit by a monster. + Hurt Rumble Time = 0.1s + # Each attack will have _N,_E,_S,_W appended to them once read in-game. PLAYER_ANIMATION[0] = WARRIOR_WALK PLAYER_ANIMATION[1] = WARRIOR_IDLE