ansi-terminal-game

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit dec0ded855307c20cd4fa09864604713eb6366d1
parent df06fb8b4298d01f45c48c99e39a1f9b0c27b348
Author: Francesco Ariis <fa-ml@ariis.it>
Date:   Wed, 22 Feb 2023 22:25:06 +0100

Clarify KeyPress/Tick behaviour

Diffstat:
MNEWS | 11+++++++++++
Msrc/Terminal/Game/Layer/Object/Primitive.hs | 9+++++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS @@ -1,3 +1,14 @@ +next +---- + +- Clarified KeyPress and Tick behaviour. tl;dr: *all* keypresses are + recorder and fed to your game-logic function. If your played manages + to type the Divine Comedy in the space of a Tick, all those characters + are recorder, not just one. + If your game is running faster when keys are pressed, that probably + means you are updating some world variables on `KeyPress` events too, + while you should do that only on `Tick` events. + 1.8.1.0 ------- diff --git a/src/Terminal/Game/Layer/Object/Primitive.hs b/src/Terminal/Game/Layer/Object/Primitive.hs @@ -28,6 +28,15 @@ type TPS = Integer type FPS = Integer -- | An @Event@ is a 'Tick' (time passes) or a 'KeyPress'. +-- +-- Note that all @Keypress@es are recorded and fed to your game-logic +-- function. This means you will not lose a single character, no matter +-- how fast your player is at typing or how low you set 'FPS' to be. +-- +-- Example: in a game where you are controlling a hot-air baloon and have +-- @direction@ and @position@ variables, you most likely want @direction@ +-- to change at every @KeyPress@, while having @position@ only change at +-- @Tick@s. data Event = Tick | KeyPress Char -- ↑↓→← do not work on Windows (are handled by the app,