diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 0de0f7a8..4fa18950 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -70,6 +70,7 @@ All rights reserved. #include "SaveFile.h" #include "TitleScreen.h" #include "SoundEffect.h" +#include "olcPGEX_Gamepad.h" #ifndef __EMSCRIPTEN__ #include "discord.h" #endif @@ -175,6 +176,8 @@ AiL::AiL() } bool AiL::OnUserCreate(){ + GamePad::init(); + Font::init(); InitializeDefaultKeybinds(); @@ -315,6 +318,18 @@ bool AiL::UpReleased(){ bool AiL::DownReleased(){ return KEY_DOWN.Released(); } +bool AiL::LeftPressed(){ + return KEY_LEFT.Pressed(); +} +bool AiL::RightPressed(){ + return KEY_RIGHT.Pressed(); +} +bool AiL::UpPressed(){ + return KEY_UP.Pressed(); +} +bool AiL::DownPressed(){ + return KEY_DOWN.Pressed(); +} void AiL::HandleUserInput(float fElapsedTime){ if(!Menu::stack.empty())return; //A window being opened means there's no user input allowed. @@ -2278,25 +2293,45 @@ void AiL::DrawSquarePie(vf2d center,float radius,float degreesCut,Pixel col){ void AiL::InitializeDefaultKeybinds(){ Player::KEY_ABILITY1.AddKeybind({KEY,Q}); + Player::KEY_ABILITY1.AddKeybind({CONTROLLER,static_cast(GPButtons::L1)}); + Player::KEY_ABILITY1.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_L)}); Player::KEY_ABILITY2.AddKeybind({KEY,E}); + Player::KEY_ABILITY2.AddKeybind({CONTROLLER,static_cast(GPButtons::R1)}); + Player::KEY_ABILITY2.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_U)}); Player::KEY_ABILITY3.AddKeybind({KEY,R}); + Player::KEY_ABILITY3.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_R)}); Player::KEY_ABILITY4.AddKeybind({KEY,F}); + Player::KEY_ABILITY4.AddKeybind({CONTROLLER,static_cast(GPButtons::L2)}); Player::KEY_DEFENSIVE.AddKeybind({MOUSE,Mouse::RIGHT}); + Player::KEY_DEFENSIVE.AddKeybind({KEY,SPACE}); + Player::KEY_DEFENSIVE.AddKeybind({CONTROLLER,static_cast(GPButtons::R2)}); Player::KEY_ITEM1.AddKeybind({KEY,K1}); + Player::KEY_ITEM1.AddKeybind({CONTROLLER,static_cast(GPButtons::SELECT)}); Player::KEY_ITEM2.AddKeybind({KEY,K2}); + Player::KEY_ITEM2.AddKeybind({CONTROLLER,static_cast(GPButtons::L3)}); Player::KEY_ITEM3.AddKeybind({KEY,K3}); + Player::KEY_ITEM3.AddKeybind({CONTROLLER,static_cast(GPButtons::R3)}); KEY_ATTACK.AddKeybind({MOUSE,Mouse::LEFT}); + KEY_ATTACK.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_D)}); KEY_LEFT.AddKeybind({KEY,LEFT}); KEY_LEFT.AddKeybind({KEY,A}); + KEY_LEFT.AddKeybind({CONTROLLER,static_cast(GPButtons::DPAD_L)}); KEY_RIGHT.AddKeybind({KEY,RIGHT}); KEY_RIGHT.AddKeybind({KEY,D}); + KEY_RIGHT.AddKeybind({CONTROLLER,static_cast(GPButtons::DPAD_R)}); KEY_UP.AddKeybind({KEY,UP}); KEY_UP.AddKeybind({KEY,W}); + KEY_UP.AddKeybind({CONTROLLER,static_cast(GPButtons::DPAD_U)}); KEY_DOWN.AddKeybind({KEY,DOWN}); KEY_DOWN.AddKeybind({KEY,S}); + KEY_DOWN.AddKeybind({CONTROLLER,static_cast(GPButtons::DPAD_D)}); KEY_CONFIRM.AddKeybind({MOUSE,Mouse::LEFT}); + 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,ENTER}); KEY_MENU.AddKeybind({KEY,ESCAPE}); + KEY_MENU.AddKeybind({CONTROLLER,static_cast(GPButtons::START)}); } void AiL::SetBossNameDisplay(std::string name,float time){ diff --git a/Adventures in Lestoria/AdventuresInLestoria.h b/Adventures in Lestoria/AdventuresInLestoria.h index 485c9149..030d37df 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.h +++ b/Adventures in Lestoria/AdventuresInLestoria.h @@ -159,6 +159,10 @@ public: bool RightHeld(); bool UpHeld(); bool DownHeld(); + bool LeftPressed(); + bool RightPressed(); + bool UpPressed(); + bool DownPressed(); bool LeftReleased(); bool RightReleased(); bool UpReleased(); diff --git a/Adventures in Lestoria/Key.cpp b/Adventures in Lestoria/Key.cpp index d7fe9835..d13f17f5 100644 --- a/Adventures in Lestoria/Key.cpp +++ b/Adventures in Lestoria/Key.cpp @@ -38,6 +38,7 @@ All rights reserved. #include "Key.h" #include "DEFINES.h" #include "AdventuresInLestoria.h" +#include "olcPGEX_Gamepad.h" INCLUDE_game @@ -54,7 +55,10 @@ bool Input::Pressed(){ return game->GetMouse(key).bPressed; }break; case CONTROLLER:{ - throw; //TODO: Throw for now, this control scheme is unsupported! + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected&&gamepad->getButton(static_cast(key)).bPressed)return true; + } + return false; }break; } ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<GetMouse(key).bHeld; }break; case CONTROLLER:{ - throw; //TODO: Throw for now, this control scheme is unsupported! + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected&&gamepad->getButton(static_cast(key)).bHeld)return true; + } + return false; }break; } ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<GetMouse(key).bReleased; }break; case CONTROLLER:{ - throw; //TODO: Throw for now, this control scheme is unsupported! + for(GamePad*gamepad:GamePad::getGamepads()){ + if(gamepad->stillConnected&&gamepad->getButton(static_cast(key)).bReleased)return true; + } + return false; }break; } ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<,std::string> GenericKey::keyLiteral={ {{MOUSE, Mouse::LEFT},"L.MOUSE"}, {{MOUSE, Mouse::RIGHT},"R.MOUSE"}, {{MOUSE, Mouse::MIDDLE},"M.MOUSE"}, + {{CONTROLLER, static_cast(GPButtons::FACE_D)},"A/X"}, + {{CONTROLLER, static_cast(GPButtons::FACE_L)},"X/Square"}, + {{CONTROLLER, static_cast(GPButtons::FACE_R)},"B/Circle"}, + {{CONTROLLER, static_cast(GPButtons::FACE_U)},"Y/Triangle"}, + {{CONTROLLER, static_cast(GPButtons::L1)},"L1"}, + {{CONTROLLER, static_cast(GPButtons::L2)},"L2"}, + {{CONTROLLER, static_cast(GPButtons::L3)},"L3"}, + {{CONTROLLER, static_cast(GPButtons::R1)},"R1"}, + {{CONTROLLER, static_cast(GPButtons::R2)},"R2"}, + {{CONTROLLER, static_cast(GPButtons::R3)},"R3"}, + {{CONTROLLER, static_cast(GPButtons::SELECT)},"SELECT"}, + {{CONTROLLER, static_cast(GPButtons::START)},"START"}, + {{CONTROLLER, static_cast(GPButtons::DPAD_L)},"LEFT"}, + {{CONTROLLER, static_cast(GPButtons::DPAD_R)},"RIGHT"}, + {{CONTROLLER, static_cast(GPButtons::DPAD_U)},"UP"}, + {{CONTROLLER, static_cast(GPButtons::DPAD_D)},"DOWN"}, }; \ No newline at end of file diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index ff588133..854837f1 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -353,19 +353,19 @@ void Menu::OpenMenu(MenuType menu,bool cover){ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ vi2d prevSelection=selection; - if(game->GetKey(RIGHT).bPressed){ + if(game->RightPressed()){ if(selection==vi2d{-1,-1})return; SetMouseNavigation(false); selection.x=(size_t(selection.x)+1)%keyboardButtons[selection.y].size(); } - if(game->GetKey(LEFT).bPressed){ + if(game->LeftPressed()){ if(selection==vi2d{-1,-1})return; selection.x--; SetMouseNavigation(false); if(selection.x<0)selection.x+=int32_t(keyboardButtons[selection.y].size()); } - if(game->GetKey(DOWN).bPressed||game->GetKey(UP).bPressed){ - if(game->GetKey(DOWN).bPressed){ + if(game->DownPressed()||game->UpPressed()){ + if(game->DownPressed()){ SetMouseNavigation(false); bool found=false; bool selectedItem=false; @@ -405,7 +405,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ } } } - if(game->GetKey(UP).bPressed){ + if(game->UpPressed()){ SetMouseNavigation(false); if(selection==vi2d{-1,-1}){ //Highlight last item. diff --git a/Adventures in Lestoria/TODO.txt b/Adventures in Lestoria/TODO.txt index ac51c7f6..de5160cf 100644 --- a/Adventures in Lestoria/TODO.txt +++ b/Adventures in Lestoria/TODO.txt @@ -14,16 +14,6 @@ January 31st ============ Make new unlocked nodes more obvious, made neighboring nodes more obvious -Implement the rest of the enemy types: -- Baby Wolf -- Wolf -- Wolf Leader -- Baby Bear -- Brown Bear -- Green Frog -- Red Frog -- Orange Frog -- Blue Frog Implement Ursule, Mother of Bears Boss Story proofreading/correcting/storyboarding - Fix Keyboard/Controller Menu Navigation (Need clearly defined rules) diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 963ed36c..1c5cd6dd 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 5823 +#define VERSION_BUILD 5830 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Adventures in Lestoria/olcPGEX_Gamepad.h b/Adventures in Lestoria/olcPGEX_Gamepad.h index 8ab77877..13c81b84 100644 --- a/Adventures in Lestoria/olcPGEX_Gamepad.h +++ b/Adventures in Lestoria/olcPGEX_Gamepad.h @@ -5,6 +5,8 @@ License (OLC-3) Copyright 2018 - 2024 OneLoneCoder.com +This PGEX is located at https://github.com/gorbit99/olcPGEX_Gamepad + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -177,6 +179,12 @@ namespace olc { bool hasAxis(GPAxes a); + const float getDeadZone()const; + const float getDeadZoneOuter()const; + + void setDeadZone(const float deadZone); + void setDeadZoneOuter(const float deadZoneOuter); + HWButton getButton(GPButtons b); bool hasButton(GPButtons b); @@ -218,6 +226,9 @@ namespace olc { bool availableButtons[GP_BUTTON_COUNT] = {false}; bool availableAxes[GP_AXIS_COUNT] = {false}; + float deadZone=0.2f; + float deadZoneOuter=0.2f; + void handleButton(int id, bool value); #ifdef WIN32 @@ -1279,20 +1290,12 @@ olc::GamePad *olc::GamePad::selectWithAnyButton() { return nullptr; } -#ifndef OLC_GAMEPAD_DEADZONE -#define OLC_GAMEPAD_DEADZONE 0.2f -#endif - -#ifndef OLC_GAMEPAD_DEADZONE_OUTER -#define OLC_GAMEPAD_DEADZONE_OUTER 0.2f -#endif - float olc::GamePad::getAxis(olc::GPAxes a) { float axis = axes[static_cast(a)]; - if (std::abs(axis) < OLC_GAMEPAD_DEADZONE) { + if (std::abs(axis) < deadZone) { axis = 0; } - if (std::abs(axis) > 1 - OLC_GAMEPAD_DEADZONE_OUTER) { + if (std::abs(axis) > 1 - deadZoneOuter) { axis = axis > 0 ? 1.0f : -1.0f; } @@ -1303,6 +1306,20 @@ float olc::GamePad::getAxis(olc::GPAxes a) { return axis; } +const float olc::GamePad::getDeadZone()const{ + return deadZone; +} +const float olc::GamePad::getDeadZoneOuter()const{ + return deadZoneOuter; +} + +void olc::GamePad::setDeadZone(const float deadZone){ + this->deadZone=deadZone; +} +void olc::GamePad::setDeadZoneOuter(const float deadZoneOuter){ + this->deadZoneOuter=deadZoneOuter; +} + olc::HWButton olc::GamePad::getButton(olc::GPButtons b) { return buttons[static_cast(b)]; } diff --git a/Adventures in Lestoria/pixelGameEngine.cpp b/Adventures in Lestoria/pixelGameEngine.cpp index 220aaec1..fdc7249b 100644 --- a/Adventures in Lestoria/pixelGameEngine.cpp +++ b/Adventures in Lestoria/pixelGameEngine.cpp @@ -53,4 +53,6 @@ All rights reserved. #define OLC_PGEX_MINIAUDIO #include "olcPGEX_MiniAudio.h" #define OLC_PGEX_SPLASHSCREEN -#include "olcPGEX_SplashScreen.h" \ No newline at end of file +#include "olcPGEX_SplashScreen.h" +#define OLC_PGE_GAMEPAD +#include "olcPGEX_Gamepad.h" \ No newline at end of file diff --git a/x64/Release/Adventures in Lestoria.exe b/x64/Release/Adventures in Lestoria.exe index cfccacce..3243b3cd 100644 Binary files a/x64/Release/Adventures in Lestoria.exe and b/x64/Release/Adventures in Lestoria.exe differ