controls.pyΒΆ

Part of HeartBeast Action RPG.

 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
 4adventurer's controls arrive with the player and leave with the player, and the
 5title card's controls last exactly as long as the title card. Nothing is
 6registered from ``main()``, where ``InputMap`` has no tree yet.
 7"""
 8
 9from __future__ import annotations
10
11from simvx.core import Axis2D, Controller, InputContext, Key, Mouse
12
13#: Walking, swinging and rolling. Movement is one typed action rather than
14#: four, so WASD, the arrow keys, a controller's left stick and the drawn pad's
15#: stick all feed it and whichever is furthest from rest wins. The sword and
16#: the roll sit on the two face buttons a thumb reaches first.
17ADVENTURER = InputContext(
18    {
19        "move": [
20            Axis2D(up=Key.W, down=Key.S, left=Key.A, right=Key.D),
21            Axis2D(up=Key.UP, down=Key.DOWN, left=Key.LEFT, right=Key.RIGHT),
22            Controller.LEFT_STICK,
23        ],
24        "attack": [Key.J, Key.Z, Controller.A],
25        "roll": [Key.K, Key.X, Controller.B],
26    },
27    name="adventurer",
28)
29
30#: Leaving the title card. A tap counts, because the web runtime delivers touch
31#: as a left click, and so does a face button, because a pad player has to be
32#: able to get into the game.
33TITLE = InputContext(
34    {
35        "start": [Key.SPACE, Key.ENTER, Mouse.LEFT, Controller.A, Controller.START],
36    },
37    name="title",
38)
39
40#: Always available, whichever screen is up.
41SHELL = {
42    "quit": [Key.ESCAPE, Controller.BACK],
43}