/* Feito por Vitor Carneiro Maia em 18/10/2008 www.dcc.ufrj.br/~vitormaia Programa esqueleto em Allegro: Este programa inclui apenas o básico necessário para o jogo funcionar. - begin: Inicializa mouse, teclado e checa as placas de som e de vídeo; - closing: Fecha tudo; - loop: O jogo em si fica dentro de um loop que só permite saída se a tecla Esc for pressionada. A condição de saída pode ser qualquer uma, mas é obrigatório que haja um loop. Não são necessarios no esqueleto, mas incluí: - Mouse (com um comando simples no loop); - Uma frase com a função textprintf_ex; - Implementação de Double Buffering, para o mouse não "piscar"; */ //------------------------------------------------------------------------ // Includes & Namespaces #include #include using namespace std; //------------------------------------------------------------------------ // Defines #define MAX_X 800 #define MAX_Y 600 #define V_MAX_X 0 #define V_MAX_Y 0 #define COLOR_BITS 32 #define VIDEO_CARD GFX_AUTODETECT_FULLSCREEN #define DIGI_CARD DIGI_AUTODETECT #define MIDI_CARD MIDI_AUTODETECT //------------------------------------------------------------------------ // Prototypes int begin(void); void closing(void); void loop(void); //------------------------------------------------------------------------ // Globais BITMAP *buffer; // Para fazer double buffering //------------------------------------------------------------------------ int main(int argc, char **argv) { if (!begin()) { // Se não começar... closing(); // fecha (...) return -1; } buffer = create_bitmap(MAX_X,MAX_Y); loop(); closing(); return 0; } END_OF_MAIN(); int begin(void) { allegro_init(); install_keyboard(); install_mouse(); install_timer(); set_color_depth(COLOR_BITS); if (set_gfx_mode(VIDEO_CARD, MAX_X, MAX_Y, V_MAX_X, V_MAX_Y) < 0) { if (set_gfx_mode(GFX_AUTODETECT, MAX_X, MAX_Y, V_MAX_X, V_MAX_Y) < 0) { allegro_message("Erro ao inicializar o modo grafico"); return (FALSE); } } if (COLOR_BITS == 32) { set_alpha_blender(); } if (install_sound(DIGI_CARD, MIDI_CARD, NULL) < 0) { if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) < 0) { allegro_message("Erro ao inicializar o som"); return (FALSE); } } return (TRUE); } void closing(void) { remove_timer(); remove_mouse(); remove_sound(); remove_keyboard(); allegro_exit(); } //------------------------------------------------------------------------ // As linhas acima devem ser repetidas em todos os programas. void loop(void) { // O jogo se passa dentro deste loop... do { show_mouse(buffer); // Comando "printf" em allegro; textprintf_ex(buffer, font, 10, 10, makeacol32(255, 255, 255, 0),-1, "Nao se assuste! Para sair, pressione Esc."); blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h); }while(!key[KEY_ESC]); // ... para sair do loop, ESC deve ser pressionado, neste caso. }