nodes/controls.pyΒΆ

Part of Squash the Creeps.

 1"""What the player can do, declared once and carried by the node that reads it.
 2
 3A context is live exactly while the node holding it is in the tree, so the
 4player's controls arrive with the player and leave with it. Nothing is
 5registered from ``main()``, where ``InputMap`` has no tree yet.
 6"""
 7
 8from simvx.core import Axis2D, Controller, InputContext, Key, Mouse
 9
10#: Running around the arena. Movement is one typed action rather than four, so
11#: the letter keys, the arrows, a controller's left stick and the drawn pad's
12#: stick all feed it and whichever is furthest from rest wins. ``+y`` is down
13#: the screen, which the fixed isometric camera maps straight onto world ``+z``.
14PLAYER = InputContext(
15    {
16        "move": [
17            Axis2D(up=Key.W, down=Key.S, left=Key.A, right=Key.D),
18            Axis2D(up=Key.UP, down=Key.DOWN, left=Key.LEFT, right=Key.RIGHT),
19            Controller.LEFT_STICK,
20        ],
21        "jump": [Key.SPACE, Controller.A],
22    },
23    name="player",
24)
25
26#: Leaving the title screen and restarting after a loss. A tap counts, because
27#: the web runtime delivers touch as a left click, and so does a face button,
28#: because a pad player has to be able to get into the game.
29SHELL = {
30    "start": [Key.R, Key.ENTER, Key.SPACE, Mouse.LEFT, Controller.A, Controller.START],
31    "quit": [Key.ESCAPE],
32}