C++ Game Programming
Basic C++ Lessons
This set of lessons will give you a simple introduction to programming in the C++ language.
Allegro Lessons
This set of lessons will demonstrate how to use the Allegro graphics library to create video games.
Game Source Code
Here you will find source code to several games so that you can see the code in action.
Recommended Books
Here is a list of books which should help you with C++

Allegro Input/Output
The last lesson's example was pretty useless, but important, lets add on to that now. Here is some example code:

#include <allegro.h>

int x = 10;
int y = 10;

int main(){
 
    allegro_init();
    install_keyboard();
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
    
    while ( !key[KEY_ESC] ){
    
        clear_keybuf();
        
        acquire_screen();
        
        textout_ex( screen, font, " ", x, y, makecol( 0, 0, 0), makecol( 0, 0, 0) );
        
        if (key[KEY_UP]) --y;        
        else if (key[KEY_DOWN]) ++y;    
        else if (key[KEY_RIGHT]) ++x;
        else if (key[KEY_LEFT]) --x;

        textout_ex( screen, font, "@", x, y, makecol( 255, 0, 0), makecol( 0, 0, 0) );
        
        release_screen();
        
        rest(50);

    }    
    
    return 0;
    
}   
END_OF_MAIN(); 

This program will write a "@" to the screen and move it around when the user presses the up, down, left, or right arrows. The first new line here, while( !key[KEY_ESC] ){. key[] is an array of flags which are set to true when a specific key is pressed. In order to test for a certain key just place one of the following codes within the brackets.

      KEY_A - KEY_Z,
      KEY_0 - KEY_9,
      KEY_0_PAD - KEY_9_PAD,
      KEY_F1 - KEY_F12,

      KEY_ESC, KEY_TILDE, KEY_MINUS, KEY_EQUALS,
      KEY_BACKSPACE, KEY_TAB, KEY_OPENBRACE, KEY_CLOSEBRACE,
      KEY_ENTER, KEY_COLON, KEY_QUOTE, KEY_BACKSLASH,
      KEY_BACKSLASH2, KEY_COMMA, KEY_STOP, KEY_SLASH,
      KEY_SPACE,

      KEY_INSERT, KEY_DEL, KEY_HOME, KEY_END, KEY_PGUP,
      KEY_PGDN, KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN,

      KEY_SLASH_PAD, KEY_ASTERISK, KEY_MINUS_PAD,
      KEY_PLUS_PAD, KEY_DEL_PAD, KEY_ENTER_PAD,

      KEY_PRTSCR, KEY_PAUSE,

      KEY_ABNT_C1, KEY_YEN, KEY_KANA, KEY_CONVERT, KEY_NOCONVERT,
      KEY_AT, KEY_CIRCUMFLEX, KEY_COLON2, KEY_KANJI,

      KEY_LSHIFT, KEY_RSHIFT,
      KEY_LCONTROL, KEY_RCONTROL,
      KEY_ALT, KEY_ALTGR,
      KEY_LWIN, KEY_RWIN, KEY_MENU,
      KEY_SCRLOCK, KEY_NUMLOCK, KEY_CAPSLOCK

      KEY_EQUALS_PAD, KEY_BACKQUOTE, KEY_SEMICOLON, KEY_COMMAND
clear_keybuf() clears the key buffer. The key buffer is a block of memory where your program will keep a list of all the buttons pressed, you should run clear_keybuf() before every input just incase if there is some unwanted data left in the buffer.

acquire_screen() is used to get Allegro ready to draw to the screen, always be sure to include this before using any functions that draw to the screen and include release_screen() once you are finished.

textout_ex() will draw text to the screen. It takes seven parameters. The first is where you want it to write to, Allegro creates a variable called screen which represents the actuall screen, just use this for now. The second parameter is the type of font to be used, if you do not want to create your own font style, just use font which is the basic font included with Allegro. The next parameter is the text to be drawn to the screen.

The next two are the x and y coordinates which point to where you want the text to be drawn to. When positioning something, remember that coordinates 0, 0 would be the top left of the screen. Adding to x will move the position to the right, while adding to y will move it further down.

Next goes the color of the text. makecol() takes three parameters, the first the intensity of red, the second of green, and then blue. makecol() will then return a value which represents the mix of color made from the three parameters.

The final parameter is the background color.

rest() is used to pause the program for a set amount of milliseconds, just put how long you want to wait in milliseconds between the parenthesis.

Google