pjasicek / OpenClaw

Reimplementation of Captain Claw (1997) platformer
GNU General Public License v3.0
338 stars 39 forks source link

joystick or controls #135

Open Noisk8 opened 5 years ago

Noisk8 commented 5 years ago

Is it possible to change the controls or use a joystick? what would be the proper way to include SDL_joystick in the ActorController.cpp and .h file?

pjasicek commented 5 years ago

Uh, haven't seen the code for quite some time :) But here goes:

1) Create some new config option in config.xml file, e.g. true and save it to BaseGameApp::m_GlobalOptions at startup with default value for this being false.

2) In these methods:

ActorController::Update ActorController::VOnKeyDown ActorController::VOnKeyUp

Implement custom logic based on the key which is being handled.

Someone added some "alternate" controls via some pull request which enabled controlling of claw via WASD and shotting/attack through mouse buttons. This is distinguished by e.g. this line:

https://github.com/pjasicek/OpenClaw/blob/master/OpenClaw/ActorController.cpp#L55

Hope this helps.

Noisk8 commented 5 years ago

Thanks to see if I understand, I am not clear how to do the config.xml file, I use linux and see that there is a config file linux

the line would be something like this?

(SDL_GetScancodeFromKey(key) == SDL_SCANCODE_LALT || SDL_GetScancodeFromKey(key) == SDL_CONTROLLER_BUTTON_A )

pjasicek commented 5 years ago

Well I looked at the "Controller" abstraction code by SDL and it is not that simple at all. Game Controller input is handled by a different subsystem so it is handled differently than keyboard. You can look here for more details:

http://lazyfoo.net/tutorials/SDL/19_gamepads_and_joysticks/index.php

In the engine startup routine you would have to add initialization of the SDL Game Controller and keep the reference to the controller somewhere in the g_pApp. Then when processing input you would have to check for any game controller events and handle them accordingly.

mialy commented 5 years ago

Here are 3 commits for my basic implementation of controller support: https://github.com/mialy/OpenClaw/commits/controllers

I'm really bad at C/C++, and what stops me even more is I was unable run build on Windows with Visual Studio (Linux works though) . Still, implementation supports Xbox One S controller + some other NES-like, but with fixed buttons, meaning if button "1" in your controller is identified as "menu" and not "A" or "X" button, you have bad luck. My plan was to implement key mapping in C# launcher, but now I haven't much time. I'm glad, If this code could helps somebody.

Noisk8 commented 5 years ago

If I connect my joystick is activated the menu controls? or just activates the buttons automatically?