Posts Tagged ‘ game dev ’

Be Kind, Please Find

Be Kind, Please Find is the first graphical program that Kevin and I worked on together. It paved the way to making more visually impressive software and eventually Android development. In the spring of 2008, we took a game development class after finishing our basic C++ programming classes in college. We did not think much of it at the time as we thought as the class was just going to be an easy way to get a minor and bump up our GPA, but that semester was the first step towards our future. The project taught us how to manage resources and tasks to ensure that important things got done. It also taught us the importance of creating a good demo and presentation as that is what hooks people in. Our college senior project mirrors the philosophy and spirit of this project which set the bar for future students. It is our honor and privilege to present Be Kind, Please Find to the world.

Be Kind, Please Find

Handling continuous keypresses

This post is more of a concept rather than any specific way to do it. So let’s say you’re making a game where you use the arrow keys to move the player. You want to make the player move smoothly and continuously as long as the key is pressed, but stop as soon as the key is released. Easy enough? Well, some systems will register a continuous keypress as a single occurrence so it only triggers it once so your player moves one step and you have to keep tapping the key to get him to move. Other systems will register the initial keypress once, pause, and then a second later will repeat the keypress.

Now assuming you have access to a function to detect a key press and a key release, here’s how to make it work smoothly. Usually functions like onKeyPress() detects when a key is pressed, but not held down. Functions like onKeyRelease() will only detect if a key goes back up to it’s resting position. To use this to your advantage you want to make a global boolean variable to keep track of the keypresses. You initialize the bool as false and then set it to true when the key is pressed and then set it to false when the key is released. Then you check this bool at your action.

For example:

bool flag = false;

void onKeyPress(){
   flag = true;

void onKeyRelease(){
    flag = false;

void action(){
    if( flag ){

Again, the code is not for any specific programming language. It is just to illustrate the concept of how to handle keypresses smoothly.