I have just released a new library for managing player input via the keyboard, called
Key_State.
Key_State is a small and simple library which provides a way to answer to basic questions that are very important in video games:
1: Did the player press a certain key?
2: Is the player holding down a certain key?
DM uses an event based environment where code is tied directly to player commands, called
"verbs". In games with different environments, especially those with "game loops", the default event based player command system is a major obstacle. Using key states, a developer can passively log player commands, so that the game can actively respond on its own terms and at its own time. An example of this kind of system can be found in my action game
Casual Quest (CQ). Go try the game, then come back; that way you'll be better prepared for the next paragraph.
In CQ, a central game object maintains a list of players, enemies, projectiles, and other game objects and information. Every server tick the game loops through this list and gives each object a chance to execute its own custom behavior: enemies move around and attack player, projectiles move forward and impact things, and player characters respond to client input.
This works via key_state. Every time a player character is given its turn by the central game object, the player character queries the client for key-state information, using this exact same library. If the client is holding the up arrow key (client.key_state(NORTH)) then the player character will move north. If the client has pressed the space-bar (client.key_press(PRIMARY)) then the player character will attack, and then clear the key-press data (client.clear_press(~PRIMARY)).
Using key-state info and a game loop, BYOND developers can create smooth movement and fun action games.
I'm keeping the library in Beta for now because I want more feedback before I finalize it. Don't let that stop you from using it, though; It is a fully functioning and bug-free library which I use in all my projects. If you have ideas to make the library better, or you do find a bug,
please post on the forum.
If you found this link from the blog front page, you may be interested in my other blog post from 5 minutes ago,
New Library: Dmm Suite