Player Handler
src.controller.player_handler
¶
Player input controller for in-game actions.
The player handler translates keyboard state and key-down events into movement, attack, and defense actions for the active unit. It also resolves attack targets, updates animation state, and notifies the game loop when a turn may be complete.
The documentation follows Google-style docstrings so tools such as pdoc, Sphinx Napoleon, or MkDocs-based pipelines can expose parameters, return values, and side effects in a consistent HTML API reference.
PlayerHandler
¶
Controller for the currently active unit.
A PlayerHandler is created around the unit whose turn is active. It converts
keyboard input into movement, attack, and defense commands while preserving the
turn rules stored on the unit action flags.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the active unit. |
animation_manager |
AnimationManager
|
Registry used for animations, effects, and units. |
map |
Map
|
Map used for movement constraints. |
game |
Game
|
Game loop object receiving turn updates. |
Notes
This class is documented as part of the public project API and is intended to be readable in generated HTML documentation.
Source code in src\controller\player_handler.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
player
property
¶
Return the active unit controlled by this handler.
Returns:
| Name | Type | Description |
|---|---|---|
Unit |
Active unit resolved from the animation manager registry. |
get_effect(type)
¶
Return the first competence effect of the requested type, if available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
Action subtype, competence name, or category key used by the caller. |
required |
Returns:
| Type | Description |
|---|---|
|
Effect | None: Registered effect matching the requested key, if available. |
Source code in src\controller\player_handler.py
key_pressed_event()
¶
Apply continuous keyboard movement for the active unit.
Returns:
| Name | Type | Description |
|---|---|---|
None |
This method is executed for its side effects. |
Side Effects
Moves the active unit, changes unit state, and updates orientation or animation.
Source code in src\controller\player_handler.py
find_target(attack)
¶
Find the first enemy unit that is within range of the given attack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attack
|
Attack competence selected for execution or range testing. |
required |
Returns:
| Type | Description |
|---|---|
|
Unit | None: First living enemy unit inside the attack range, or |
Source code in src\controller\player_handler.py
key_down_event(event, screen, dt)
¶
Handle one-shot keyboard actions such as attacks, defenses, and turn updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Pygame event to process. |
required | |
screen
|
Pygame surface or screen wrapper used as the drawing target. |
required | |
dt
|
Elapsed time since the previous frame, used to advance animations. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
object |
Value produced by the underlying game or rendering operation. |
Side Effects
Executes attacks or defenses, updates action flags, and may advance turns.
Notes
Only discrete key presses are handled here; continuous movement is handled separately.