Added controller vibration for world shake events/player hurt events.

pull/30/head
sigonasr2 1 year ago
parent c4ee2608f2
commit 1fd37bbd51
  1. 15
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 10
      Adventures in Lestoria/Menu.cpp
  3. 23
      Adventures in Lestoria/Player.cpp
  4. 1
      Adventures in Lestoria/Player.h
  5. 2
      Adventures in Lestoria/Version.h
  6. 3
      Adventures in Lestoria/assets/config/Player.txt

@ -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<int>(GPButtons::FACE_D)});
KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_R)});
KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});
KEY_CONFIRM.AddKeybind({KEY,SPACE});
KEY_CONFIRM.AddKeybind({KEY,ENTER});
KEY_MENU.AddKeybind({KEY,ESCAPE});
KEY_MENU.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});

@ -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;

@ -51,6 +51,7 @@ All rights reserved.
#include "config.h"
#include <string_view>
#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;

@ -277,6 +277,7 @@ private:
void Initialize();
float iframe_time=0;
float lastCombatTime=0;
float hurtRumbleTime=0.0f;
Ability useItem1;
Ability useItem2;
Ability useItem3;

@ -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

@ -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

Loading…
Cancel
Save