Merge: gamnit: virtual gamepad
authorJean Privat <jean@pryen.org>
Tue, 11 Apr 2017 12:30:27 +0000 (08:30 -0400)
committerJean Privat <jean@pryen.org>
Tue, 11 Apr 2017 12:30:27 +0000 (08:30 -0400)
Intro an easy to use virtual gamepad for quick ports of desktop games to mobiles devices with a touchscreen only. The gamepad is composed of up to 2 d-pads and up to 6 action buttons. Each button and direction on the pad is mapped to customizable keyboard keys. As such, it is ideal to simulate keyboard inputs on mobile devices.

The `virtual_gamepad` module uses the `app_files` annotation which automatically includes the required PNG files in Android's APK files when the module is imported.

The virtual gamepad is derived from the one in Asteronits, which it replaced. It is now used in Asteronits and Action Nitro, and it will be added to Devil's Avocados as soon as this is merged. The gamepad comes with a selection of button allowing for some customization, however custom buttons are also supported.

Usage example from Devil's Avocados:
~~~
var gamepad = new VirtualGamepad
gamepad.add_dpad
gamepad.add_button("q", gamepad_spritesheet.turn_left)
gamepad.add_button("e", gamepad_spritesheet.turn_right)
gamepad.add_button("space", gamepad_spritesheet.star)
gamepad.visible = true
app.gamepad = gamepad
~~~

And the result, on Android:

![screenshot_20170404-125407](https://cloud.githubusercontent.com/assets/208057/24668912/641d091a-1936-11e7-81ff-eaf026540db6.png)

This version should manage quite well the edge cases of touchscreen controls, which explains the complexity of `virtual_gamepad.nit`. However it is still limited, future work could add:
- Virtual analog joystick, it would be easier to code than the d-pad.
- Abstraction for gamepads (and analog joysticks). This would require unification with the current Android physical gamepad support and implementing desktop physical gamepad support with SDL2.

Pull-Request: #2405
Reviewed-by: Romain Chanoir <romain.chanoir@viacesi.fr>
Reviewed-by: Jean Privat <jean@pryen.org>

1  2 
contrib/asteronits/src/asteronits.nit
lib/gamnit/flat.nit

Simple merge
Simple merge