View Single Post
  #4 (permalink)  
Old 07-06-2008, 12:54 AM
Aereshaa's Avatar   
Aereshaa Aereshaa is offline
Guru
 
Join Date: Apr 2008
Posts: 498
Rep Power: 9
Aereshaa is a jewel in the roughAereshaa is a jewel in the roughAereshaa is a jewel in the roughAereshaa is a jewel in the rough
Default Re: Allegro Game Library

It does if you are willing to look up the formulae! For example, I made a 3d Pong game a few weeks ago. Basically, I used Allegro with math.h and checked the formulae on wikipedia. Also there are 3d math routines, although I haven't used them at all...

Okay, so next thing is input. Allegro uses two main sources of input: the keyboard array and the mouse variables. The keyboard array is key[] which is indexed by a kabillion macros: here's how it works:
Code:
key[KEY_A]
key[KEY_ESC]
key[KEY_SHIFT]
key[KEY_F1]
key[KEY_CTRL]
...aand so on. A complete list is here.

For mouse, use the variables mouse_x mouse_y, and use the bit-mapped variable mouse_b. mouse_b & 1 is left button, mouse_b & 2 is right, mouse_b & 4 is middle. any other buttons on your mouse can probably be found at later bits.

Okay, next is text. To draw text on the screen, you need a font. Fonts can be loaded to allegro from GRX format .fnt files, 8x8 or 8x16 BIOS format fonts, or from specially prepared bitmaps. Allegro also contains a global font variable, containing a simple font.
To load a font, use the load_font() function, like so.
Code:
FONT * myfont = load_font("myfont.fnt",NULL,NULL);
The two NULL arguments are a palette, which doesn't exist, and a loader script file, which is not needed.

So, to use a font, use the textprintf_ex() function.
Code:
textprintf(buffer,font,x,y,color,bgcolor,"format string", ...)
The color or bgcolor arguments may be -1, in which case they are transparent.
There are also textprintf_centre_ex(), and textprintf_right_ex(), variants which treat the coordinates given differently.

Last edited by Aereshaa; 07-06-2008 at 01:27 AM.
Reply With Quote