80 likes | 412 Views
Allegro Basics. Game Library. What is Allegro?. Allegro is a cross-platform library intended for use in computer games and other types of multimedia programming. Cross-platform support for Windows, Unix, and MacOS X systems. . License?. The giftware licence
E N D
Allegro Basics Game Library
What is Allegro? • Allegro is a cross-platform library intended for use in computer games and other types of multimedia programming. • Cross-platform support for Windows, Unix, and MacOS X systems.
License? • The giftware licence • Feel free to use the code for whatever you want – just do not claim that you wrote it!
Using Allegro • any source file which used Allegro functions or variables must #include <allegro.h>Put this after any standard header files • you should call allegro_init() near the start of your program. • make allegro_init() the first thing in your main function.
More on Allegro Usage • write END_OF_MAIN() after the closing brace of your main function. If you don't do this, your program will not link properly with the Allegro library. • Link with the appropriate Allegro Library
What does a game need to do? • Initialization - First of all we need to put the game into a known state, so that it always starts in the same way. For example, you might want to start the player in the middle of the screen, make a maze, or create a random map. All that would go in here. • Main game loop The game will need to keep doing things, over and over again, until the player dies, wins, gives up, or whatever. So we have a main game loop. It has three main components: • Input -- getting input from the player • Processing -- moving things around, responding to the input • Output -- sending information back to the player, usually by putting it on the screen but sometimes by other means, for example playing sounds • After the game - When the game has finished, we may need to do some other things, like tell the player why it finished, update a high score table, or something like that
Proposed Main #include <allegro.h> #include "game.h" intend_game; /* flag we'll set to end the game */ int main (void) { allegro_init(); /* initialise the Allegro library */ init(); /* initialise the game */ end_game = 0; /* reset flag */ do { /* loop */ input(); /* get input */ process(); /* process it */ output(); /* give output */ } while (end_game == 0); /* until the flag is set */ shutdown(); /* shut down anything that needs it */ allegro_exit(); /* just for luck */ return 0; /* tell the OS that all went well */ } END_OF_MAIN()