LD#11: 24 Hours Left

One day down, one more to go!

I have been adding mouse support to my game. As I never implemented mouse control before, ever, why not do so in a time-based competition?

I am surprised at how complicated it can be to support mouse input in my existing input system, but one thing it did teach me is that I think my input system design needs to be reworked. For example, if my game wants to know the status of the pause key, it has to keep track of the status and ask my input system for the current status. As you press and release keys, the input system updates an array, but the game itself doesn’t know when a key’s status is updated until it asks and sees that it is different.

Here’s my actual game.cpp code:

if (!m_pauseKeyPressed && InputSystem::getInstance()->isKeyPressed("Pause"))
m_isPaused = !m_isPaused;
m_pauseKeyPressed = true;
if (m_isPaused)
m_isPaused = !m_isPaused;
else if (!InputSystem::getInstance()->isKeyPressed("Pause"))
m_pauseKeyPressed = false;

All of that code is needed just to pause and unpause the game.

A simpler way to do it is to have callbacks. When a key is pressed or released, it will call a function called OnKeyPress() or OnKeyRelease(), and those functions can do whatever they want. If the pause key is pressed, the OnKeyPress() function can call the PauseKeyPressed() function. I no longer have to keep the state of the key in both the input system and the game.

In a similar way, mouse movement and button handling would work better with callbacks. Right now, since I don’t have callbacks, I have to make the game keep the status of the mouse and check if the mouse button had been pressed or was already pressed.

But it’s Ludum Dare. If the code wasn’t hastily put together and ugly, you were doing it wrong. B-)

Comments are closed.

Twitter: gbgames

  • RT : I've read so many bad takes on the CDPR crunch situation that I really need to address them. This is a thread, and my last ta…
  • RT : Soltaire fans: We teamed up with some other great solitaire devs on Steam and made this 5 game bundle which you can get for…
  • RT : Everyday I'm mad that we have a leader who has allowed and enabled the government to commit genocide* and am also mad tha…