Added basic controller keybind support.
This commit is contained in:
parent
86925ef031
commit
c4ee2608f2
@ -70,6 +70,7 @@ All rights reserved.
|
|||||||
#include "SaveFile.h"
|
#include "SaveFile.h"
|
||||||
#include "TitleScreen.h"
|
#include "TitleScreen.h"
|
||||||
#include "SoundEffect.h"
|
#include "SoundEffect.h"
|
||||||
|
#include "olcPGEX_Gamepad.h"
|
||||||
#ifndef __EMSCRIPTEN__
|
#ifndef __EMSCRIPTEN__
|
||||||
#include "discord.h"
|
#include "discord.h"
|
||||||
#endif
|
#endif
|
||||||
@ -175,6 +176,8 @@ AiL::AiL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AiL::OnUserCreate(){
|
bool AiL::OnUserCreate(){
|
||||||
|
GamePad::init();
|
||||||
|
|
||||||
Font::init();
|
Font::init();
|
||||||
|
|
||||||
InitializeDefaultKeybinds();
|
InitializeDefaultKeybinds();
|
||||||
@ -315,6 +318,18 @@ bool AiL::UpReleased(){
|
|||||||
bool AiL::DownReleased(){
|
bool AiL::DownReleased(){
|
||||||
return KEY_DOWN.Released();
|
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){
|
void AiL::HandleUserInput(float fElapsedTime){
|
||||||
if(!Menu::stack.empty())return; //A window being opened means there's no user input allowed.
|
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(){
|
void AiL::InitializeDefaultKeybinds(){
|
||||||
Player::KEY_ABILITY1.AddKeybind({KEY,Q});
|
Player::KEY_ABILITY1.AddKeybind({KEY,Q});
|
||||||
|
Player::KEY_ABILITY1.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::L1)});
|
||||||
|
Player::KEY_ABILITY1.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_L)});
|
||||||
Player::KEY_ABILITY2.AddKeybind({KEY,E});
|
Player::KEY_ABILITY2.AddKeybind({KEY,E});
|
||||||
|
Player::KEY_ABILITY2.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::R1)});
|
||||||
|
Player::KEY_ABILITY2.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_U)});
|
||||||
Player::KEY_ABILITY3.AddKeybind({KEY,R});
|
Player::KEY_ABILITY3.AddKeybind({KEY,R});
|
||||||
|
Player::KEY_ABILITY3.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_R)});
|
||||||
Player::KEY_ABILITY4.AddKeybind({KEY,F});
|
Player::KEY_ABILITY4.AddKeybind({KEY,F});
|
||||||
|
Player::KEY_ABILITY4.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::L2)});
|
||||||
Player::KEY_DEFENSIVE.AddKeybind({MOUSE,Mouse::RIGHT});
|
Player::KEY_DEFENSIVE.AddKeybind({MOUSE,Mouse::RIGHT});
|
||||||
|
Player::KEY_DEFENSIVE.AddKeybind({KEY,SPACE});
|
||||||
|
Player::KEY_DEFENSIVE.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::R2)});
|
||||||
Player::KEY_ITEM1.AddKeybind({KEY,K1});
|
Player::KEY_ITEM1.AddKeybind({KEY,K1});
|
||||||
|
Player::KEY_ITEM1.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::SELECT)});
|
||||||
Player::KEY_ITEM2.AddKeybind({KEY,K2});
|
Player::KEY_ITEM2.AddKeybind({KEY,K2});
|
||||||
|
Player::KEY_ITEM2.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::L3)});
|
||||||
Player::KEY_ITEM3.AddKeybind({KEY,K3});
|
Player::KEY_ITEM3.AddKeybind({KEY,K3});
|
||||||
|
Player::KEY_ITEM3.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::R3)});
|
||||||
KEY_ATTACK.AddKeybind({MOUSE,Mouse::LEFT});
|
KEY_ATTACK.AddKeybind({MOUSE,Mouse::LEFT});
|
||||||
|
KEY_ATTACK.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_D)});
|
||||||
KEY_LEFT.AddKeybind({KEY,LEFT});
|
KEY_LEFT.AddKeybind({KEY,LEFT});
|
||||||
KEY_LEFT.AddKeybind({KEY,A});
|
KEY_LEFT.AddKeybind({KEY,A});
|
||||||
|
KEY_LEFT.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::DPAD_L)});
|
||||||
KEY_RIGHT.AddKeybind({KEY,RIGHT});
|
KEY_RIGHT.AddKeybind({KEY,RIGHT});
|
||||||
KEY_RIGHT.AddKeybind({KEY,D});
|
KEY_RIGHT.AddKeybind({KEY,D});
|
||||||
|
KEY_RIGHT.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::DPAD_R)});
|
||||||
KEY_UP.AddKeybind({KEY,UP});
|
KEY_UP.AddKeybind({KEY,UP});
|
||||||
KEY_UP.AddKeybind({KEY,W});
|
KEY_UP.AddKeybind({KEY,W});
|
||||||
|
KEY_UP.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::DPAD_U)});
|
||||||
KEY_DOWN.AddKeybind({KEY,DOWN});
|
KEY_DOWN.AddKeybind({KEY,DOWN});
|
||||||
KEY_DOWN.AddKeybind({KEY,S});
|
KEY_DOWN.AddKeybind({KEY,S});
|
||||||
|
KEY_DOWN.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::DPAD_D)});
|
||||||
KEY_CONFIRM.AddKeybind({MOUSE,Mouse::LEFT});
|
KEY_CONFIRM.AddKeybind({MOUSE,Mouse::LEFT});
|
||||||
|
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,ENTER});
|
KEY_CONFIRM.AddKeybind({KEY,ENTER});
|
||||||
KEY_MENU.AddKeybind({KEY,ESCAPE});
|
KEY_MENU.AddKeybind({KEY,ESCAPE});
|
||||||
|
KEY_MENU.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AiL::SetBossNameDisplay(std::string name,float time){
|
void AiL::SetBossNameDisplay(std::string name,float time){
|
||||||
|
@ -159,6 +159,10 @@ public:
|
|||||||
bool RightHeld();
|
bool RightHeld();
|
||||||
bool UpHeld();
|
bool UpHeld();
|
||||||
bool DownHeld();
|
bool DownHeld();
|
||||||
|
bool LeftPressed();
|
||||||
|
bool RightPressed();
|
||||||
|
bool UpPressed();
|
||||||
|
bool DownPressed();
|
||||||
bool LeftReleased();
|
bool LeftReleased();
|
||||||
bool RightReleased();
|
bool RightReleased();
|
||||||
bool UpReleased();
|
bool UpReleased();
|
||||||
|
@ -38,6 +38,7 @@ All rights reserved.
|
|||||||
#include "Key.h"
|
#include "Key.h"
|
||||||
#include "DEFINES.h"
|
#include "DEFINES.h"
|
||||||
#include "AdventuresInLestoria.h"
|
#include "AdventuresInLestoria.h"
|
||||||
|
#include "olcPGEX_Gamepad.h"
|
||||||
|
|
||||||
INCLUDE_game
|
INCLUDE_game
|
||||||
|
|
||||||
@ -54,7 +55,10 @@ bool Input::Pressed(){
|
|||||||
return game->GetMouse(key).bPressed;
|
return game->GetMouse(key).bPressed;
|
||||||
}break;
|
}break;
|
||||||
case CONTROLLER:{
|
case CONTROLLER:{
|
||||||
throw; //TODO: Throw for now, this control scheme is unsupported!
|
for(GamePad*gamepad:GamePad::getGamepads()){
|
||||||
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bPressed)return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
||||||
@ -71,7 +75,10 @@ bool Input::Held(){
|
|||||||
return game->GetMouse(key).bHeld;
|
return game->GetMouse(key).bHeld;
|
||||||
}break;
|
}break;
|
||||||
case CONTROLLER:{
|
case CONTROLLER:{
|
||||||
throw; //TODO: Throw for now, this control scheme is unsupported!
|
for(GamePad*gamepad:GamePad::getGamepads()){
|
||||||
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bHeld)return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
||||||
@ -88,7 +95,10 @@ bool Input::Released(){
|
|||||||
return game->GetMouse(key).bReleased;
|
return game->GetMouse(key).bReleased;
|
||||||
}break;
|
}break;
|
||||||
case CONTROLLER:{
|
case CONTROLLER:{
|
||||||
throw; //TODO: Throw for now, this control scheme is unsupported!
|
for(GamePad*gamepad:GamePad::getGamepads()){
|
||||||
|
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bReleased)return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
ERR("Invalid Control Scheme detected! We shouldn't be here!! Type is "<<type);
|
||||||
@ -243,4 +253,20 @@ std::map<std::pair<InputType,int>,std::string> GenericKey::keyLiteral={
|
|||||||
{{MOUSE, Mouse::LEFT},"L.MOUSE"},
|
{{MOUSE, Mouse::LEFT},"L.MOUSE"},
|
||||||
{{MOUSE, Mouse::RIGHT},"R.MOUSE"},
|
{{MOUSE, Mouse::RIGHT},"R.MOUSE"},
|
||||||
{{MOUSE, Mouse::MIDDLE},"M.MOUSE"},
|
{{MOUSE, Mouse::MIDDLE},"M.MOUSE"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::FACE_D)},"A/X"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::FACE_L)},"X/Square"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::FACE_R)},"B/Circle"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::FACE_U)},"Y/Triangle"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::L1)},"L1"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::L2)},"L2"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::L3)},"L3"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::R1)},"R1"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::R2)},"R2"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::R3)},"R3"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::SELECT)},"SELECT"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::START)},"START"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::DPAD_L)},"LEFT"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::DPAD_R)},"RIGHT"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::DPAD_U)},"UP"},
|
||||||
|
{{CONTROLLER, static_cast<int>(GPButtons::DPAD_D)},"DOWN"},
|
||||||
};
|
};
|
@ -353,19 +353,19 @@ void Menu::OpenMenu(MenuType menu,bool cover){
|
|||||||
|
|
||||||
void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||||
vi2d prevSelection=selection;
|
vi2d prevSelection=selection;
|
||||||
if(game->GetKey(RIGHT).bPressed){
|
if(game->RightPressed()){
|
||||||
if(selection==vi2d{-1,-1})return;
|
if(selection==vi2d{-1,-1})return;
|
||||||
SetMouseNavigation(false);
|
SetMouseNavigation(false);
|
||||||
selection.x=(size_t(selection.x)+1)%keyboardButtons[selection.y].size();
|
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;
|
if(selection==vi2d{-1,-1})return;
|
||||||
selection.x--;
|
selection.x--;
|
||||||
SetMouseNavigation(false);
|
SetMouseNavigation(false);
|
||||||
if(selection.x<0)selection.x+=int32_t(keyboardButtons[selection.y].size());
|
if(selection.x<0)selection.x+=int32_t(keyboardButtons[selection.y].size());
|
||||||
}
|
}
|
||||||
if(game->GetKey(DOWN).bPressed||game->GetKey(UP).bPressed){
|
if(game->DownPressed()||game->UpPressed()){
|
||||||
if(game->GetKey(DOWN).bPressed){
|
if(game->DownPressed()){
|
||||||
SetMouseNavigation(false);
|
SetMouseNavigation(false);
|
||||||
bool found=false;
|
bool found=false;
|
||||||
bool selectedItem=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);
|
SetMouseNavigation(false);
|
||||||
if(selection==vi2d{-1,-1}){
|
if(selection==vi2d{-1,-1}){
|
||||||
//Highlight last item.
|
//Highlight last item.
|
||||||
|
@ -14,16 +14,6 @@ January 31st
|
|||||||
============
|
============
|
||||||
Make new unlocked nodes more obvious, made neighboring nodes more obvious
|
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
|
Implement Ursule, Mother of Bears Boss
|
||||||
Story proofreading/correcting/storyboarding
|
Story proofreading/correcting/storyboarding
|
||||||
- Fix Keyboard/Controller Menu Navigation (Need clearly defined rules)
|
- Fix Keyboard/Controller Menu Navigation (Need clearly defined rules)
|
||||||
|
@ -39,7 +39,7 @@ All rights reserved.
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 1
|
#define VERSION_PATCH 1
|
||||||
#define VERSION_BUILD 5823
|
#define VERSION_BUILD 5830
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
@ -5,6 +5,8 @@ License (OLC-3)
|
|||||||
|
|
||||||
Copyright 2018 - 2024 OneLoneCoder.com
|
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,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
@ -177,6 +179,12 @@ namespace olc {
|
|||||||
|
|
||||||
bool hasAxis(GPAxes a);
|
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);
|
HWButton getButton(GPButtons b);
|
||||||
|
|
||||||
bool hasButton(GPButtons b);
|
bool hasButton(GPButtons b);
|
||||||
@ -218,6 +226,9 @@ namespace olc {
|
|||||||
bool availableButtons[GP_BUTTON_COUNT] = {false};
|
bool availableButtons[GP_BUTTON_COUNT] = {false};
|
||||||
bool availableAxes[GP_AXIS_COUNT] = {false};
|
bool availableAxes[GP_AXIS_COUNT] = {false};
|
||||||
|
|
||||||
|
float deadZone=0.2f;
|
||||||
|
float deadZoneOuter=0.2f;
|
||||||
|
|
||||||
void handleButton(int id, bool value);
|
void handleButton(int id, bool value);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -1279,20 +1290,12 @@ olc::GamePad *olc::GamePad::selectWithAnyButton() {
|
|||||||
return nullptr;
|
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 olc::GamePad::getAxis(olc::GPAxes a) {
|
||||||
float axis = axes[static_cast<int>(a)];
|
float axis = axes[static_cast<int>(a)];
|
||||||
if (std::abs(axis) < OLC_GAMEPAD_DEADZONE) {
|
if (std::abs(axis) < deadZone) {
|
||||||
axis = 0;
|
axis = 0;
|
||||||
}
|
}
|
||||||
if (std::abs(axis) > 1 - OLC_GAMEPAD_DEADZONE_OUTER) {
|
if (std::abs(axis) > 1 - deadZoneOuter) {
|
||||||
axis = axis > 0 ? 1.0f : -1.0f;
|
axis = axis > 0 ? 1.0f : -1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1303,6 +1306,20 @@ float olc::GamePad::getAxis(olc::GPAxes a) {
|
|||||||
return axis;
|
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) {
|
olc::HWButton olc::GamePad::getButton(olc::GPButtons b) {
|
||||||
return buttons[static_cast<int>(b)];
|
return buttons[static_cast<int>(b)];
|
||||||
}
|
}
|
||||||
|
@ -54,3 +54,5 @@ All rights reserved.
|
|||||||
#include "olcPGEX_MiniAudio.h"
|
#include "olcPGEX_MiniAudio.h"
|
||||||
#define OLC_PGEX_SPLASHSCREEN
|
#define OLC_PGEX_SPLASHSCREEN
|
||||||
#include "olcPGEX_SplashScreen.h"
|
#include "olcPGEX_SplashScreen.h"
|
||||||
|
#define OLC_PGE_GAMEPAD
|
||||||
|
#include "olcPGEX_Gamepad.h"
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user