Thursday, November 10, 2016

multiplayer - Key mapping for a 2-players game


I've been struggling for a while trying to figure out the best way to map two players on a single keyboard. Let's consider something generic:



  • Arrows

  • Validation

  • Cancel (optional)


  • Some common actions shared between the two players (start, reset, etc.)


So far, I used:



  • P1: WASD + [Space or Tab]

  • P2: Arrows + [Enter or Return]

  • Common: R for reset


The problem is that some configuration can be uncomfortable on certain keyboards (especially when there is no keypad). Plus some players like to have the direction on left hand (FPS style) and others on right hand (platformer style). Also SHIFT is usually not a good choice on windows because of the sticky keys feature.


Also I'd like to avoid using a settings screen (kind of heavy for a small game). I guess a config file would be OK, but is there another way to handle this problem that would make every one happy?




Answer



Let the user configure the bindings from an options menu in the application. Players might be using QWERTZ (German) or AZERTY (French) layout keyboards, Dvorak layout keyboards, joysticks, etc., and they don't want to have to learn Yet Another Config File Language.


But still, a lot of players will want to jump in and play without changing any settings. So you still have to choose good defaults and show them to the player when the game starts. Consider this:



  • Right player moves with arrow keys and does actions with apostrophe and Enter.

  • Left player moves with RDFG and does actions with Z and X. Do not straddle the line between TGB and YHN because a lot of "ergonomic" keyboards split the left hand and right hand keys here.

  • Single player mode should allow input from either side, so that players used to the common emulator default of arrows and ZX can jump in.

  • Common actions can be done while the game is paused. Common back/pause is Esc.

  • Show these keys to the players at the bottom of the first screen of the game, so that the player can get used to them before being in any real danger.



As Christian pointed out in this question, a lot of keyboards can't handle a lot of simultaneous presses. USB keyboards in particular are limited to no more than six, which isn't enough for a diagonal press and both actions on both sides. So I strongly encourage you to also support USB joysticks, be they Xbox 360 controllers or USB Human Interface Device (HID) class joysticks. SDL and SDL-wrapper libraries such as Pygame will recognize either, but if you're developing a Windows Store game, only Xbox 360 controllers will work because Microsoft forbids DirectInput in Windows Runtime. When you save the input configuration file, also save the VID/PID or name of all connected joysticks. This way, when the application starts with a different set of joysticks than were plugged in last time the application started, it can notify the player that joysticks were added or removed and ask the player to reconfigure the joysticks by pressing a button for each action in turn.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...