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 <allegro5/allegro.h> Put this after any standard header files you should call al_init() near the start of your program. make al_init() the first thing in your main function.
More on Allegro Usage Link with the appropriate Allegro Library DLLs must be available for Allegro programs to run (either in current directory or Windows/System directory)
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 int main(int argc, const char *argv[]) { if (argc > 1) filename = argv[1]; } else filename = "mysha.pcx"; initialize_allegro(); initialize_display(); initialize_timer(); keep_on = true; while (keep_on) process_events(); process_display(); process_cleanup(); return 0;
Proposed Initializaton void initialize_allegro() { if (!al_init()) abort_example("Could not init Allegro.\n"); } al_install_mouse(); al_install_keyboard(); al_init_image_addon();
Making the display display = al_create_display(800, 600); if (!display) { abort_example("Error creating display\n"); } al_set_window_title(display, filename);();
Making the Bitmap al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); t0 = al_get_time(); membitmap = al_load_bitmap(filename); t1 = al_get_time(); if (!membitmap) { abort_example("%s not found or failed to load\n", filename); } al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
Making the Display ALIVE al_clear_to_color(al_map_rgb_f(0, 0, 0)); if (zoom == 1) al_draw_bitmap(bitmap, 0, 0, 0); else al_draw_scaled_rotated_bitmap( bitmap, 0, 0, 0, 0, zoom, zoom, 0, 0); al_flip_display();