GUI::GUI() { al_init(); al_init_image_addon(); al_init_primitives_addon(); al_init_font_addon(); al_install_keyboard(); al_set_new_display_flags(ALLEGRO_WINDOWED); display = al_create_display(640, 480); al_set_window_position(display,10,10); al_set_window_title(display, "Rogue"); timer = al_create_timer(1.0 / TICK_PER_S); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); viewport.view = Rectangle(0,0,640,480); tiles = al_load_bitmap("Images/Phoebus_tileset.png"); }
void BaseGame::initScreen(ScreenType screenType, string screenTitle) { if(!al_init()) { al_show_native_message_box(NULL, "Error", "Error", "Could not initialize Allegro 5", NULL, 0); exit(-1); } int displayFlags = 0; switch(screenType) { case WINDOW: displayFlags = ALLEGRO_WINDOWED; break; case FULLSCREEN: displayFlags = ALLEGRO_FULLSCREEN; break; case FULLSCREEN_WINDOWED: displayFlags = ALLEGRO_FULLSCREEN | ALLEGRO_FULLSCREEN_WINDOW; break; default: displayFlags = ALLEGRO_WINDOWED; } al_set_new_display_flags(displayFlags); display = al_create_display(windowSize.x, windowSize.y); al_set_window_position(display, 0, 0); al_set_window_title(display, screenTitle.c_str()); if(!display) { al_show_native_message_box(display, "Error", "Error", "Could not create Allegro Window", NULL, 0); exit(-1); } }
int main3() { if(!al_init()) { al_show_native_message_box(NULL, NULL, "Error", "Could not initialize Allegro 5", NULL, ALLEGRO_MESSAGEBOX_ERROR); return -1; } al_set_new_display_flags(ALLEGRO_FULLSCREEN); // al_set_new_display_flags(ALLEGRO_WINDOWED); // al_set_new_display_flags(ALLEGRO_RESIZABLE); // al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE); ALLEGRO_DISPLAY *display = al_create_display(800, 600); if(!display) { al_show_native_message_box(NULL, NULL, "Error", "Could not create Allegro 5 display", NULL, ALLEGRO_MESSAGEBOX_ERROR); return -1; } al_set_window_position(display, 200, 100); al_set_window_title(display, "CodingMadeEasy"); // You generally want to do this after you check to see if the display was created. If the display wasn't created then there's // no point in calling this function al_rest(10.0); al_destroy_display(display); return 0; }
void mw2_Application::Initialize() { al_init(); al_init_image_addon(); al_install_keyboard(); al_install_mouse(); al_init_primitives_addon(); al_init_font_addon(); al_init_ttf_addon(); al_init_acodec_addon(); al_install_audio(); al_reserve_samples(20); // maximum 20 sounds at a time al_set_new_display_flags(ALLEGRO_WINDOWED); al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); // this prevents random lag al_set_new_display_option( ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST ); mWindow = al_create_display(Settings::width, Settings::height); al_set_window_title(mWindow, Settings::title.c_str()); mw2_Input::Initialize(mWindow); srand( (unsigned int) std::time(0) ); }
int init(ALG* allg, ALLEGRO_FONT* font) { if (!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } if (!al_install_keyboard()) { fprintf(stderr, "failed to initialize the keyboard!\n"); return -1; } allg->timer2 = al_create_timer(1.0 / FPS); if (!allg->timer2) { fprintf(stderr, "failed to create timer!\n"); return -1; } allg->display2 = al_create_display(SCREEN_W, SCREEN_H); if (!allg->display2) { fprintf(stderr, "failed to create display!\n"); al_destroy_timer(allg->timer2); return -1; } al_set_window_title(allg->display2, "Set Value"); al_init_font_addon(); al_clear_to_color(al_map_rgb(255, 0, 255)); al_set_target_bitmap(al_get_backbuffer(allg->display2)); allg->event_queue2 = al_create_event_queue(); if (!allg->event_queue2) { fprintf(stderr, "failed to create event_queue!\n"); al_destroy_display(allg->display2); al_destroy_timer(allg->timer2); return -1; } al_register_event_source(allg->event_queue2, al_get_display_event_source(allg->display2)); al_register_event_source(allg->event_queue2, al_get_timer_event_source(allg->timer2)); al_register_event_source(allg->event_queue2, al_get_keyboard_event_source()); al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_text(font, al_map_rgb(255, 255, 255), 150 / 2, 30, ALLEGRO_ALIGN_CENTRE, "value:"); al_flip_display(); al_start_timer(allg->timer2); return 0; }
void inicializa_jogo (Jogo* jogo){ jogo->largura = LARGURA_INICIAL; jogo->altura = ALTURA_INICIAL; jogo->sair = false; jogo->redraw = false; allegro_init(jogo); allegro_display_init(jogo, jogo->largura, jogo->altura); allegro_image_init(jogo); allegro_primitives_init(jogo); allegro_audio_init(jogo); allegro_acodec_init(jogo); allegro_reserve_samples(jogo); allegro_font_init(jogo); allegro_mouse_init(jogo); allegro_keyboard_init(jogo); allegro_timer_init(jogo); allegro_event_queue_init(jogo); jogo->estado_do_jogo = MENU_INICIAL; menu_inicial_init( jogo); menu_pausa_init( jogo); menu_opcoes_init( jogo); cria_sound_manager(jogo); for (int i = 0; i<N_ESCUDOS; i++) jogo->escudo[i] = NULL; jogo->tanque = NULL; al_set_window_title(jogo->display, "Space Invaders"); }
void gui_window_create(int length, int height) { /* Variável representando a janela principal */ window = NULL; boat = NULL; heart = NULL; /* Criamos a nossa janela - dimensões de largura x altura pixels */ window = al_create_display(length, height); boat = al_load_bitmap("b3.png"); heart = al_load_bitmap("heart.png"); boat_height = al_get_bitmap_height(boat); boat_width = al_get_bitmap_width(boat); /* Preenchemos a janela de branco */ al_clear_to_color(al_map_rgb(255, 255, 255)); /* Atualiza a tela */ al_flip_display(); if (!event_queue) { fprintf(stderr, "Falha ao criar fila de eventos.\n"); gui_window_destroy(); } al_set_window_title(window, "Jogo da canoa"); /* Associa teclado com a janela */ al_register_event_source(event_queue, al_get_display_event_source(window)); }
//----------------------------------------------------------------------------------------------------- // Nome: sobre // Desc: Nada mais é que a função para mostrar os responsáveis pela criação do jogo e outras informações. // Foram utilizadas imagens para mostrar o conteúdo //----------------------------------------------------------------------------------------------------- void sobre() { ALLEGRO_BITMAP *imagem_sobre = al_load_bitmap("images/about.jpg"); // Cria e carrega arquivo imagem_principal.jpg ALLEGRO_BITMAP *botao_ok = al_load_bitmap("images/ok button.jpg"); // Cria e carrega arquivo ok button.jpg al_set_window_title(janela_principal, "Sobre Projeto Final"); // Definimos o título do programa al_draw_bitmap(imagem_sobre, 0, 0, NULL); // A imagem sobre o programa (a ser definida) al_draw_bitmap(botao_ok, LARGURA_MAX / 1.12, ALTURA_MAX / 1.07, NULL); // O botão "voltar", para retornar ao menu principal al_flip_display(); // Atualiza a tela // O próximo bloco de comandos será realizado até que a variável fechar seja igual a true do { inicializa_evento(); // Função utilizada para melhorar o programa em termos de visualização de código if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { if (ev.mouse.button & 1) { if( (pos_x_mouse >= 536) && (pos_x_mouse <= 595) && (pos_y_mouse >= 374) && (pos_y_mouse <= 393) ) break; // Voltar para o menu principal } } } while(!fechar); al_destroy_bitmap(imagem_sobre); // Finaliza a imagem sobre al_destroy_bitmap(botao_ok); // Finaliza o botão ok }
void Engine::Init() { done = false; al_init(); //Initialises the allegro library al_init_image_addon(); al_init_primitives_addon(); display = al_create_display(WIDTH, HEIGHT); al_set_window_title(display, "Double Pendulum Simulation"); al_install_keyboard(); //Installs keyboard driver al_install_mouse(); //installs mouse driver eventQueue = al_create_event_queue(); al_register_event_source(eventQueue, al_get_display_event_source(display)); al_register_event_source(eventQueue, al_get_keyboard_event_source()); al_register_event_source(eventQueue, al_get_mouse_event_source()); timer = al_create_timer(1.0f / FPS); al_register_event_source(eventQueue, al_get_timer_event_source(timer)); al_start_timer(timer); doublePendulum = new DoublePendulum(); doublePendulum->Init(150, 150, 4, 4, 0.5, 0.5, 400, 200); }
/** * Method that initializes the Allegro library, along with the rest of the objects * needed to use the class. */ void Application::initApp() { /* al_init(); al_install_mouse(); al_install_keyboard(); al_init_image_addon(); */ /* std::string sFilePath = "/home/aalmunia/CodeTesting/cpp/Life/resources/mysha.pcx"; ALLEGRO_BITMAP *pBitmap = al_load_bitmap(sFilePath.c_str()); if(!pBitmap) { std::cout << "The file " << sFilePath << " has not been loaded correctly" << std::endl; } else { std::cout << "The file " << sFilePath << " has been correctly opened" << std::endl; } */ this->pDisplay = al_create_display(this->iWindowWidth, this->iWindowHeight); if(this->pDisplay != NULL) { al_set_window_title(this->pDisplay, this->sWindowName.c_str()); this->bInit = true; this->initColors(); al_clear_to_color(this->colRed); std::cout << "Initialized OK" << std::endl; while(true) { al_flip_display(); } } }
void SpaceSim::LoadAllegro() { al_init(); //allegro-5.0.10-monolith-md-debug.lib //Anti Aliasing al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST); //Creating screen screen_width = 1350; screen_height = 690; display = al_create_display(screen_width,screen_height); al_set_window_position(display,0,0); al_set_window_title(display, "Domitian Engine"); //Initializing Addons al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); al_install_keyboard(); al_install_audio(); al_init_acodec_addon(); al_reserve_samples(10); };
void init_video (void) { if (! al_init_image_addon ()) error (-1, 0, "%s (void): failed to initialize image addon", __func__); al_set_new_display_flags (al_get_new_display_flags () | (display_mode < 0 ? ALLEGRO_WINDOWED : ALLEGRO_FULLSCREEN) | ALLEGRO_RESIZABLE | ALLEGRO_GENERATE_EXPOSE_EVENTS); display_width = display_width ? display_width : DISPLAY_WIDTH; display_height = display_height ? display_height : DISPLAY_HEIGHT; if (display_mode >= 0) { ALLEGRO_DISPLAY_MODE d; get_display_mode (display_mode, &d); display_width = d.width; display_height = d.height; al_set_new_display_refresh_rate (d.refresh_rate); al_set_new_display_flags (al_get_new_display_flags () & ~ALLEGRO_FULLSCREEN_WINDOW); } al_set_new_display_option (ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_SUGGEST); display = al_create_display (display_width, display_height); if (! display) error (-1, 0, "%s (void): failed to initialize display", __func__); set_target_backbuffer (display); al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP); al_set_window_title (display, WINDOW_TITLE); icon = load_bitmap (ICON); al_set_display_icon (display, icon); cutscene = true; if (mr.fit_w == 0 && mr.fit_h == 0) { mr.fit_w = 2; mr.fit_h = 2; } set_multi_room (1, 1); effect_buffer = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT); black_screen = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT); uscreen = create_bitmap (CUTSCENE_WIDTH, CUTSCENE_HEIGHT); iscreen = create_bitmap (display_width, display_height); clear_bitmap (uscreen, TRANSPARENT_COLOR); video_timer = create_timer (1.0 / EFFECT_HZ); al_init_font_addon (); builtin_font = al_create_builtin_font (); if (! builtin_font) error (-1, 0, "%s (void): cannot create builtin font", __func__); if (! al_init_primitives_addon ()) error (-1, 0, "%s (void): failed to initialize primitives addon", __func__); }
bool init(int w, int h, bool fullscreen = false) { // HWND hWndDisplay = NULL; const char* err; #define INIT(x, y) if(!(x)) { err = y; goto err; } mt_seed(); // Allegro initialization INIT( al_init() && al_install_mouse() && al_install_keyboard() && al_init_image_addon() && al_init_primitives_addon(), "initialize allegro" ); if(fullscreen) al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); INIT(display = al_create_display(w, h), "create display") al_set_window_title(display, "ŒwiteŸ"); // { auto icon = al_load_bitmap("img\\icon.gif"); // if(icon) al_set_display_icon(display, icon); } // if(fullscreen) { // hWndDisplay = al_get_win_window_handle(display); // SetWindowLong(hWndDisplay, GWL_STYLE, 0); // ShowWindow(hWndDisplay, SW_MAXIMIZE); // } INIT(timer = al_create_timer(1.0 / 60), "create timer") INIT(event_queue = al_create_event_queue(), "create event queue") al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_mouse_event_source()); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_start_timer(timer); // End of Allegro initialization INIT(setup(display), "initialize renderer"); #undef INIT return true; err: if(display) al_destroy_display(display); { char* buf = new char[strlen(err) + 13]; sprintf(buf, "Failed to %s!\n", err); // MessageBoxA(NULL, buf, "Error", MB_ICONERROR); delete buf; } return false; }
void init_misc() { al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); al_set_window_title(display, "Pikmin fangame engine"); if(smooth_scaling) al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR | ALLEGRO_MIPMAP); al_reserve_samples(16); srand(time(NULL)); // TODO the function is always returning 0. area_image_size = /*al_get_new_display_option(ALLEGRO_MAX_BITMAP_SIZE, NULL)*/ 800; }
void StateControl::CreateAllegroDisplay() { al_set_new_display_flags(ALLEGRO_WINDOWED); display = al_create_display(ScreenWidth, ScreenHeight); if (!display) { al_show_native_message_box(display, "Error", "Display Settings", "Couldn't create a display.", NULL, ALLEGRO_MESSAGEBOX_ERROR); exit(-1); } /* setting new window title */ al_set_window_title(display, "Radio Station"); }
void GameLib_Init(){ // Inicializa a Allegro al_init(); // Inicializa o add-on para utilização de imagens al_init_image_addon(); // Configura a janela oScreen = al_create_display(nWigth, nHeigth); al_set_window_title(oScreen, cTitle); }
//---------------------------------------------------------------------------- bool AllegroRender::Init(bool openWindowed, const char *windowTitle, int windowLength, int windowHeight) { display = al_create_display(windowLength, windowHeight); if (!display) { return false; } if (!al_init_image_addon()) { return false; } al_set_window_title(display, windowTitle); al_hide_mouse_cursor(display); return true; }
grafika::grafika() { al_init(); al_install_keyboard(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); font=al_load_ttf_font("C:\\WINDOWS\\Fonts\\times.ttf",15,0); okno = al_create_display( 800, 600); al_set_window_title(okno,"Samoloty"); al_set_target_bitmap(al_get_backbuffer(okno)); menu=al_load_bitmap("menu.png"); strzalka=al_load_bitmap("strzalka.bmp"); al_convert_mask_to_alpha( strzalka, al_map_rgb( 255, 255, 255 ) ); font_menu_glowne=al_load_ttf_font("C:\\WINDOWS\\Fonts\\times.ttf",35,0); }
void gdp_init(){ // aloca limites de exibicao listlifeless = calloc(LIFELESS,sizeof(Lifeless*)); listchars = calloc(CHARS,sizeof(Char*)); // configurações iniciais ncanaisaudio = 3; // numero de canais de audio connecterro = 0; //nao existe erro ntotlifeless = 0; // numero de objetos ntotchars = 4; // numero de personagens ntotenemies = 0; // numero de inimigos opmap = 1; // mapa escolhido scale = 1.5; //escala do mapa boss_char_id = gdp_files_quick_getint("Configs//server.txt","boss_char_id"); //id do boss // Inicializa a Allegro al_init(); // Inicializa o add-on para utilização de imagens al_init_image_addon(); // Inicializa o add-on para utilização de teclado al_install_keyboard(); // Inicialização do add-on para uso de fontes al_init_font_addon(); al_init_ttf_addon(); // Inicialização do add-on para uso de sons al_install_audio(); al_init_acodec_addon(); al_reserve_samples(ncanaisaudio); //inicia addons de primitivas al_init_primitives_addon(); // Configura a janela al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW|ALLEGRO_FULLSCREEN); SCREEN = al_create_display(wigth, height); // define o titulo al_set_window_title(SCREEN, title); ambient = NULL; }
//Funciones void inicializar(void){ //Inicializar los AddOns if(!al_init()) { fprintf(stderr, "Error al inicializar Allegro."); // Imprimir errores en stream STDERR exit(-1); } if(!al_init_primitives_addon()) { fprintf(stderr, "Error al inicializar el addon de primitivas."); // Imprimir errores en stream STDERR exit(-2); } dis = al_create_display(VENTANA_X, VENTANA_Y); // Crear el display de tamaño 500x300 píxeles al_set_window_title(dis, "Ejemplo Allegro 5 - www.multiaportes.com"); // Establecer el título de la ventana }
static void calcfps() { const double SAMPLE_TIME = 0.250; static int frames; static double tock=0.0; double tick; char string[64]; frames++; tick = al_get_time(); if (tick - tock > SAMPLE_TIME) { snprintf(string, 64, "%d FPS", (int) (frames/(tick - tock) + 0.5)); al_set_window_title(dpy, string); frames = 0; tock = tick; } }
DrawingClass::DrawingClass (int w, int h, Interface *interface) { al_init(); mDisplay = al_create_display(w, h); al_set_window_title(mDisplay, "Tower Defense"); mEventQueue = al_create_event_queue(); mTimer = al_create_timer (1.0/((float)ConstFps)); mInterface = interface; al_init_font_addon(); al_init_ttf_addon(); al_init_primitives_addon(); al_install_mouse(); al_install_keyboard(); assert(al_install_audio()); assert(al_init_acodec_addon()); assert(al_reserve_samples(1)); al_init_image_addon(); al_register_event_source(mEventQueue, al_get_display_event_source(mDisplay)); al_register_event_source(mEventQueue, al_get_timer_event_source(mTimer)); al_register_event_source(mEventQueue, al_get_mouse_event_source()); al_register_event_source(mEventQueue, al_get_keyboard_event_source()); float tileSize = interface->GetTileSize(); mBigFont = al_load_font("DejaVuSans.ttf", tileSize, 0); mFont = al_load_font("DejaVuSans.ttf", tileSize/2, 0); mSmallFont = al_load_font("DejaVuSans.ttf", tileSize/4, 0); mMusic = 0; // mBackground = al_create_bitmap(tileSize, tileSize); mBackground = al_load_bitmap("Images/grass.png"); /* al_set_target_bitmap(mBackground); * al_draw_filled_circle(tileSize/2, tileSize/2, tileSize/2, al_map_rgb(0, 255, 0)); * al_set_target_bitmap(al_get_backbuffer(mDisplay)); */ CreateMap(); }
void GameEngine::Init() { done = false; input = new InputHandler(); collisionDetector = new CollisionDetector(); menuState = new State_Menu(); gameState = new State_Game(); states.push_back(menuState); states.push_back(gameState); al_init(); //Initialises the allegro library al_install_keyboard(); al_install_mouse(); al_set_new_display_flags(ALLEGRO_RESIZABLE); al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST); al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR); al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); al_set_new_display_option(ALLEGRO_SAMPLES, 6, ALLEGRO_SUGGEST); display = al_create_display(WIDTH, HEIGHT); al_set_window_title(display, "Vinctus Arce"); eventQueue = al_create_event_queue(); al_register_event_source(eventQueue, al_get_display_event_source(display)); al_register_event_source(eventQueue, al_get_keyboard_event_source()); al_register_event_source(eventQueue, al_get_mouse_event_source()); timer = al_create_timer(1.0f / FPS); al_register_event_source(eventQueue, al_get_timer_event_source(timer)); al_start_timer(timer); PushState(menuState); }
void error_display(const char *text) { ALLEGRO_DISPLAY *disp; ALLEGRO_EVENT_QUEUE *ev_queue; ALLEGRO_FONT *font; al_init(); al_install_keyboard(); al_install_mouse(); al_init_font_addon(); al_set_new_display_flags(ALLEGRO_WINDOWED); al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST); disp = al_create_display(640, 480); al_set_window_title(disp, "mruby-minigame"); ev_queue = al_create_event_queue(); al_register_event_source(ev_queue, al_get_display_event_source(disp)); al_register_event_source(ev_queue, al_get_keyboard_event_source()); al_register_event_source(ev_queue, al_get_mouse_event_source()); font = al_create_builtin_font(); for (;;) { ALLEGRO_EVENT ev; while (al_get_next_event(ev_queue, &ev)) { if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) goto done; } al_clear_to_color(al_map_rgb(200, 120, 120)); al_draw_multiline_text(font, al_map_rgb(255, 255, 255), 64, 64, 640-64, 10, ALLEGRO_ALIGN_LEFT, text); al_flip_display(); } done: return; }
void GameEngine::Init() { running = true; al_init(); //Initialises the allegro library al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); display = al_create_display(scrx, scry); al_set_window_title(display, "Knights"); al_install_keyboard(); //Installs keyboard driver eventQueue = al_create_event_queue(); redrawQueue = al_create_event_queue(); al_register_event_source(eventQueue, al_get_display_event_source(display)); al_register_event_source(eventQueue, al_get_keyboard_event_source()); redrawTimer = al_create_timer(1.0f / FPS); al_register_event_source(redrawQueue, al_get_timer_event_source(redrawTimer)); al_start_timer(redrawTimer); srand((int)time(NULL)); //Randomises the numbers used in program so that it's not the same each time. }
AllegroWindow::AllegroWindow(int width, int height) { display = NULL; if (!al_init()) { al_show_native_message_box(NULL, NULL, NULL, "Failed to initialize allegro!", NULL, NULL); } display = al_create_display(width + 20, height + 20); al_set_window_title(display, "Sierpinski's carpet"); if (!display) { al_show_native_message_box(NULL, NULL, NULL, "Failed to create display!", NULL, NULL); } al_init_primitives_addon(); al_clear_to_color(al_map_rgb(255, 255, 255)); //al_destroy_display(display); //al_destroy_event_queue(event_queue); }
int main(void) { ALLEGRO_DISPLAY *display; ALLEGRO_BITMAP *icon1; ALLEGRO_BITMAP *icon2; ALLEGRO_EVENT_QUEUE *queue; ALLEGRO_TIMER *timer; int i; if (!al_init()) { abort_example("Could not init Allegro.\n"); return 1; } al_install_keyboard(); al_init_image_addon(); display = al_create_display(320, 200); if (!display) { abort_example("Error creating display\n"); return 1; } /* First icon: Read from file. */ icon1 = al_load_bitmap("data/icon.tga"); if (!icon1) { abort_example("icon.tga not found\n"); return 1; } /* Second icon: Create it. */ al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); icon2 = al_create_bitmap(16, 16); al_set_target_bitmap(icon2); for (i = 0; i < 256; i++) { int u = i % 16; int v = i / 16; al_put_pixel(u, v, al_map_rgb_f(u / 15.0, v / 15.0, 1)); } al_set_target_backbuffer(display); al_set_window_title(display, "Changing icon example"); timer = al_create_timer(0.5); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); for (;;) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } if (event.type == ALLEGRO_EVENT_TIMER) { al_set_display_icon(display, (event.timer.count & 1) ? icon2 : icon1); } } al_uninstall_system(); return 0; }
int main(){ //variaveis que tem alguma coisa a ver com o jogados, como exp recebida e level int game_status = 0, option = 0, school = 0; //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- //Variaveis internas relacionadas as bibliotecas usadas e erros do jogo em si. int status_allegro = 0, tecla = 0; //A variavel teclado tem 5 estados /* 0 - Neutro 1 - Tecla para cima 2 - Tecla para Baixo 3 - Tecla para Direita 4 - Tecla para Esquerda */ //iniciando o Allegro e todos as suas bibliotecas e funções usadas. al_init(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); al_install_keyboard(); //Iniciando o jogo. display = al_create_display(SCREEN_W, SCREEN_H); background = al_load_bitmap("img/background.jpg"); start_menu_img = al_load_bitmap("img/start_screen.jpg"); font_text = al_load_font("font/font.ttf", 50, 0); timer = al_create_timer(0.1); tcont = al_create_timer(1.0); sections_event = al_create_event_queue(); al_set_window_title(display, "M.I.P. - Matemática, Português e Inglês"); al_start_timer(timer); al_start_timer(tcont); //Qualquer valor que seja colocado apos a imagem, ira interferir na sua posição em relação a tela. fadeout(7, SCREEN_W, SCREEN_H, display); al_draw_bitmap(background, 0,0,0); al_flip_display(); //Verificando erros no allegro e suas bibliotecas. status_allegro = check_allegro(background, start_menu_img, sections_event, display, font_text, timer, tcont); if(status_allegro == -1){ close_game(background, start_menu_img, sections_event, display, timer, tcont); return 0; } al_register_event_source(sections_event, al_get_keyboard_event_source()); al_register_event_source(sections_event, al_get_display_event_source(display)); //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- //menu_background(); fadeout(1, SCREEN_W, SCREEN_H, display); al_draw_bitmap(start_menu_img, 0,0,0); printf("Menu Principal\n"); //capture_event(); al_flip_display(); al_draw_textf(font_text, al_map_rgb(0, 255, 255), SCREEN_H / 4, SCREEN_W / 4, ALLEGRO_ALIGN_LEFT, "Novo Jogo"); al_draw_textf(font_text, al_map_rgb(0, 255, 255), SCREEN_H / (3.7), SCREEN_W / 3, ALLEGRO_ALIGN_LEFT, "Continuar"); al_draw_textf(font_text, al_map_rgb(0, 255, 255), SCREEN_H / (3.4), SCREEN_W / (2.5), ALLEGRO_ALIGN_LEFT, "Sair do jogo"); al_flip_display(); option = capture_event_queue(SCREEN_H, SCREEN_W, keyboard, display, sections_event, tecla, font_text); if(option == -1){ close_game(background, start_menu_img, sections_event, display, timer, tcont); return 0; } switch(option){ case 0: game_start(); printf("game_start\n"); break; case 1: game_load(); printf("game_load\n"); break; case 2: printf("Finalizando Jogo\n"); close_game(background, start_menu_img, sections_event, display, timer, tcont); return 0; break; } //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- //Apos a escolha entre continuar ou começar novamente o usuário estará na tela de seleção de escolas printf("Selecione a escola\n"); scanf("%d", &school); switch(school){ case 0: open_math(); break; case 1: open_ing(); break; case 2: open_port(); break; } //--------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------- return 0; }
int inicializadores(int *LARGURA_TELA, int *ALTURA_TELA, float *FPS, ALLEGRO_DISPLAY *janela , ALLEGRO_EVENT_QUEUE *fila_eventos, ALLEGRO_BITMAP *poderes, ALLEGRO_FONT *fonte_equacao, ALLEGRO_FONT *fonte_pontos, ALLEGRO_TIMER *timer){ if (!al_init()){ fprintf(stderr, "Falha ao inicializar a Allegro.\n"); return -1; } al_init_image_addon(); // Inicialização do add-on para uso de fontes al_init_font_addon(); // Inicialização do add-on para uso de fontes True Type if (!al_init_ttf_addon()){ fprintf(stderr, "Falha ao inicializar add-on allegro_ttf.\n"); return -1; } janela = al_create_display(LARGURA_TELA, ALTURA_TELA); if (!janela){ fprintf(stderr, "Falha ao criar janela.\n"); return -1; } timer = al_create_timer(1.0 / FPS); if(!timer){ fprintf(stderr, "failed to create timer!\n"); return -1; } // Configura o título da janela al_set_window_title(janela, "PENAS - Telas de Poderes -"); fonte_equacao = al_load_font("fontes/letra_equacao.ttf", 36, 0); if (!fonte_equacao){ al_destroy_display(janela); fprintf(stderr, "Falha ao carregar fonte.\n"); return -1; } fonte_pontos = al_load_font("fontes/letra_equacao.ttf", 26, 0); if (!fonte_pontos){ al_destroy_display(janela); fprintf(stderr, "Falha ao carregar fonte.\n"); return -1; } // Torna apto o uso de mouse na aplicação if (!al_install_mouse()){ fprintf(stderr, "Falha ao inicializar o mouse.\n"); al_destroy_display(janela); return -1; } // Atribui o cursor padrão do sistema para ser usado if (!al_set_system_mouse_cursor(janela, ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT)){ fprintf(stderr, "Falha ao atribuir ponteiro do mouse.\n"); al_destroy_display(janela); return -1; } fila_eventos = al_create_event_queue(); if (!fila_eventos){ fprintf(stderr, "Falha ao inicializar o fila de eventos.\n"); al_destroy_display(janela); return -1; } if (!al_init_primitives_addon()){ fprintf(stderr, "Falha ao inicializar add-on de primitivas.\n"); return false; } // Dizemos que vamos tratar os eventos vindos do mouse al_register_event_source(fila_eventos, al_get_mouse_event_source()); al_register_event_source(fila_eventos, al_get_display_event_source(janela)); al_register_event_source(fila_eventos, al_get_timer_event_source(timer)); }
int main(int argc, char *argv[]) { ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *evqueue = NULL; ALLEGRO_TIMER *timer = NULL; ALLEGRO_KEYBOARD_STATE keyboard_state; ALLEGRO_EVENT event; ALLEGRO_FONT *font; ALLEGRO_BITMAP *clock_hand, *clock_quadrant, *bow, *sword; float clock_ray = 0, clock_angle = 0; int clock_ray_alpha; float soul_interval = SOUL_TIME_INTERVAL; FuzzyPlayer *player, *cpu; FuzzyGame * game; bool running = true; bool redraw = true; int map_x = 13*16, map_y = 5*16; int screen_width = WINDOW_WIDTH; int screen_height = WINDOW_HEIGHT; double curtime; /* Initialization */ fuzzy_iz_error(al_init(), "Failed to initialize allegro"); fuzzy_load_addon("image", al_init_image_addon()); fuzzy_load_addon("primitives", al_init_primitives_addon()); fuzzy_load_addon("keyboard", al_install_keyboard()); fuzzy_load_addon("mouse", al_install_mouse()); al_init_font_addon(); fuzzy_iz_error(timer = al_create_timer(1.0 / FPS), "Cannot create FPS timer"); fuzzy_iz_error(evqueue = al_create_event_queue(), "Cannot create event queue"); fuzzy_iz_error(display = al_create_display(screen_width, screen_height), "Cannot initialize display"); al_set_window_title(display, WINDOW_TITLE); fuzzy_iz_error(font = al_load_font(fuzzy_res(FONT_FOLDER, "fixed_font.tga"), 0, 0), "Cannot load 'fixed_font.tga'"); clock_hand = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "clock_hand.png")); fuzzy_iz_error(clock_hand, "Cannot load clock handle"); clock_quadrant = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "clock_quadrant.png")); fuzzy_iz_error(clock_hand, "Cannot load clock quadrant"); bow = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "bow.png")); fuzzy_iz_error(clock_hand, "Cannot load bow image"); sword = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "sword.png")); fuzzy_iz_error(clock_hand, "Cannot load sword image"); /* Queue setup */ al_register_event_source(evqueue, al_get_display_event_source(display)); al_register_event_source(evqueue, al_get_timer_event_source(timer)); al_register_event_source(evqueue, al_get_keyboard_event_source()); al_register_event_source(evqueue, al_get_mouse_event_source()); /* Game setup */ game = fuzzy_game_new("level000.tmx"); player = fuzzy_player_new(game, FUZZY_PLAYER_LOCAL, "Dolly"); cpu = fuzzy_player_new(game, FUZZY_PLAYER_CPU, "CPU_0"); fuzzy_chess_add(game, player, FUZZY_FOO_LINK, 34, 30); fuzzy_chess_add(game, player, FUZZY_FOO_LINK, 33, 30); fuzzy_chess_add(game, cpu, FUZZY_FOO_LINK, 40, 30); bool showing_area = false; FuzzyChess *chess, *focus = NULL; al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_bitmap(game->map->bitmap, -map_x, -map_y, 0); al_flip_display(); #if DEBUG ALLEGRO_BITMAP *icon; int fps, fps_accum; double fps_time; icon = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "icon.tga")); if (icon) al_set_display_icon(display, icon); fps_accum = fps_time = 0; fps = FPS; #endif /* Server connection */ int svsock; //~ FuzzyMessage * sendmsg = fuzzy_message_new(); svsock = fuzzy_server_connect(FUZZY_DEFAULT_SERVER_ADDRESS, FUZZY_DEFAULT_SERVER_PORT); _aaa_menu(game, svsock); /* MAIN loop */ player->soul_time = al_get_time(); al_start_timer(timer); while (running) { /* wait until an event happens */ al_wait_for_event(evqueue, &event); switch (event.type) { case ALLEGRO_EVENT_TIMER: /* check soul ticks */ curtime = al_get_time(); while (curtime - player->soul_time >= soul_interval) { //~ fuzzy_debug("Soul tick!"); player->soul_time += soul_interval; player->soul_points += SOUL_POINTS_BOOST; clock_ray = 1; } clock_angle = (curtime - player->soul_time)/soul_interval * FUZZY_2PI; if (clock_ray) { clock_ray = (curtime - player->soul_time)/RAY_TIME_INTERVAL * 50 + 40; clock_ray_alpha = (curtime - player->soul_time)/RAY_TIME_INTERVAL*(55) + 200; if (clock_ray >= 90) clock_ray = 0; } al_get_keyboard_state(&keyboard_state); if (al_key_down(&keyboard_state, ALLEGRO_KEY_RIGHT)) { map_x += 5; if (map_x > (game->map->tot_width - screen_width)) map_x = game->map->tot_width - screen_width; } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_LEFT)) { map_x -= 5; if (map_x < 0) map_x = 0; } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_UP)) { map_y -= 5; if (map_y < 0) map_y = 0; } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_DOWN)) { map_y += 5; if (map_y > (game->map->tot_height - screen_height)) map_y = game->map->tot_height - screen_height; } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_O)) { soul_interval = fuzzy_max(0.1, soul_interval - 0.05); } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_P)) { soul_interval += 0.05; } redraw = true; break; case ALLEGRO_EVENT_KEY_DOWN: if(! focus) break; _attack_area_off(); switch(event.keyboard.keycode) { case ALLEGRO_KEY_W: _chess_move(game, player, focus, focus->x, focus->y-1); break; case ALLEGRO_KEY_A: _chess_move(game, player, focus, focus->x-1, focus->y); break; case ALLEGRO_KEY_S: _chess_move(game, player, focus, focus->x, focus->y+1); break; case ALLEGRO_KEY_D: _chess_move(game, player, focus, focus->x+1, focus->y); break; case ALLEGRO_KEY_K: _attack_area_on(); break; case ALLEGRO_KEY_SPACE: /* switch attack type */ if (! focus) break; if (focus->atkarea == &FuzzyMeleeMan) focus->atkarea = &FuzzyRangedMan; else focus->atkarea = &FuzzyMeleeMan; break; } break; case ALLEGRO_EVENT_DISPLAY_CLOSE: running = false; break; case ALLEGRO_EVENT_KEY_UP: break; case ALLEGRO_EVENT_KEY_CHAR: break; case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: if(event.mouse.button == RIGHT_BUTTON) { _attack_area_on(); } else if(event.mouse.button == LEFT_BUTTON) { /* world to tile coords */ int tx = (event.mouse.x+map_x) / game->map->tile_width; int ty = (event.mouse.y+map_y) / game->map->tile_height; #ifdef DEBUG printf("SELECT %d %d\n", tx, ty); #endif if(showing_area && fuzzy_chess_inside_target_area(game, focus, tx, ty)) { /* select attack target */ if (fuzzy_map_spy(game->map, FUZZY_LAYER_SPRITES, tx, ty) == FUZZY_CELL_SPRITE) { if (fuzzy_chess_local_attack(game, player, focus, tx, ty)) _attack_area_off(); } } else { /* select chess */ chess = fuzzy_chess_at(game, player, tx, ty); if (chess && focus != chess) { _attack_area_off(); if (focus != NULL) { // already has a focus effect, just move it fuzzy_sprite_move(game->map, FUZZY_LAYER_BELOW, focus->x, focus->y, tx, ty); } else { fuzzy_sprite_create(game->map, FUZZY_LAYER_BELOW, GID_TARGET, tx, ty); } focus = chess; } else if (! chess) { if (showing_area) { // just hide the attack area _attack_area_off(); } else if(focus) { // remove the focus fuzzy_sprite_destroy(game->map, FUZZY_LAYER_BELOW, focus->x, focus->y); focus = NULL; } } } } break; default: #ifdef DEBUG //~ fprintf(stderr, "Unknown event received: %d\n", event.type); #endif break; } if (redraw && al_is_event_queue_empty(evqueue)) { curtime = al_get_time(); fuzzy_map_update(game->map, curtime); // Clear the screen al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_bitmap(game->map->bitmap, -map_x, -map_y, 0); #ifdef GRID_ON /* Draw the grid */ int tw = game->map->tile_width; int ty = game->map->tile_height; int x, y; for (x=(tw-map_x)%tw; x<screen_width; x+=tw) al_draw_line(x, 0, x, screen_height, al_map_rgba(7,7,7,100), 1); for (y=(ty-map_y)%ty; y<screen_height; y+=ty) al_draw_line(0, y, screen_width, y, al_map_rgba(7,7,7,100), 1); #endif #if DEBUG al_draw_filled_rounded_rectangle(screen_width-100, 4, screen_width, 30, 8, 8, al_map_rgba(0, 0, 0, 200)); al_draw_textf(font, al_map_rgb(255, 255, 255), screen_width-50, 8, ALLEGRO_ALIGN_CENTRE, "FPS: %d", fps); #endif /* draw SP count */ al_draw_filled_rounded_rectangle(4, screen_height-170, 175, screen_height-4, 8, 8, al_map_rgba(0, 0, 0, 200)); al_draw_textf(font, al_map_rgb(255, 255, 255), 15, screen_height-163, ALLEGRO_ALIGN_LEFT, "SP: %d", player->soul_points); /* draw Soul Clock */ al_draw_scaled_bitmap(clock_quadrant, 0, 0, 301, 301, 20, screen_height-80-139/2, 139, 139, 0); al_draw_scaled_rotated_bitmap(clock_hand, 160, 607, 90, screen_height-80, 0.11, 0.11, clock_angle, 0); al_draw_circle(90, screen_height-80, clock_ray, al_map_rgb(80, clock_ray_alpha, 80), 2.0); /* draw weapon */ if (focus) { ALLEGRO_BITMAP * weapon; if (focus->atkarea == &FuzzyMeleeMan) weapon = sword; else weapon = bow; al_draw_scaled_bitmap(weapon, 0, 0, 90, 90, 20, 20, 60, 60, 0); } al_flip_display(); #if DEBUG fps_accum++; if (curtime - fps_time >= 1) { fps = fps_accum; fps_accum = 0; fps_time = curtime; } #endif redraw = false; } } /* Cleanup */ //~ void * retval; //~ char srvkey[FUZZY_SERVERKEY_LEN]; //~ fuzzy_protocol_server_shutdown(svsock, sendmsg, srvkey); //~ fuzzy_message_del(sendmsg); fuzzy_game_free(game); al_destroy_event_queue(evqueue); al_destroy_display(display); al_destroy_timer(timer); return 0; }