void closeAllegro(void){ al_uninstall_system(); al_uninstall_mouse(); al_shutdown_primitives_addon; al_shutdown_font_addon(); al_shutdown_ttf_addon(); al_shutdown_image_addon(); al_uninstall_system(); }
int main(void) { ALLEGRO_DISPLAY *display; ALLEGRO_BITMAP *icons[NUM_ICONS]; ALLEGRO_EVENT_QUEUE *queue; int u, v; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_install_keyboard(); al_init_image_addon(); display = al_create_display(320, 200); if (!display) { abort_example("Error creating display\n"); } al_clear_to_color(al_map_rgb_f(0, 0, 0)); al_flip_display(); /* First icon 16x16: Read from file. */ icons[0] = al_load_bitmap("data/cursor.tga"); if (!icons[0]) { abort_example("icons.tga not found\n"); } /* Second icon 32x32: Create it. */ al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); icons[1] = al_create_bitmap(32, 32); al_set_target_bitmap(icons[1]); for (v = 0; v < 32; v++) { for (u = 0; u < 32; u++) { al_put_pixel(u, v, al_map_rgb_f(u / 31.0, v / 31.0, 1)); } } al_set_target_backbuffer(display); al_set_display_icons(display, NUM_ICONS, icons); 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)); 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; } } al_uninstall_system(); return 0; }
void c_engine::destroy_engine() { if (m_al_display) { al_destroy_display(m_al_display); } al_uninstall_system(); }
void shutdown() { al_shutdown_image_addon(); al_shutdown_ttf_addon(); al_shutdown_font_addon(); al_shutdown_primitives_addon(); al_uninstall_keyboard(); al_uninstall_mouse(); al_uninstall_audio(); al_uninstall_system(); }
int initializeAllegro(void){ if(!al_init()){ fprintf(stderr,"No se pudo inicializar Allegro\n"); return ERROR; } if(!al_install_mouse()){ fprintf(stderr,"No se pudo inicializar el mouse.\n"); al_uninstall_system(); return ERROR; } if(!al_init_primitives_addon()){ fprintf(stderr,"No se pudo inicializar el mouse.\n"); al_uninstall_system(); al_uninstall_mouse(); return ERROR; } al_init_font_addon(); //esta funcion en su declaracion dice que devuelve VOID, por eso no puedo hacer el chequeo if(!al_init_ttf_addon()){ fprintf(stderr,"No se pudo inicializar el mouse.\n"); al_uninstall_system(); al_uninstall_mouse(); al_shutdown_primitives_addon; al_shutdown_font_addon(); return ERROR; } if(!al_init_image_addon()){ fprintf(stderr,"No se inicializo el addon de imagenes\n"); fprintf(stderr,"No se pudo inicializar el mouse.\n"); al_uninstall_system(); al_uninstall_mouse(); al_shutdown_primitives_addon; al_shutdown_font_addon(); al_shutdown_ttf_addon(); return ERROR; } return 0; }
bool Framework::destruct() { // TODO autit this function delete instance; instance = nullptr; initialized = false; al_uninstall_system(); return true; }
int main(void) { al_init(); ALLEGRO_DISPLAY *d = al_create_display(W, H); ALLEGRO_VERTEX v[POINTS]; ALLEGRO_COLOR c; v[0].x = 0; v[0].y = 0; c = al_map_rgb(rand()%256, rand()%256, rand()%256); v[0].color = al_get_prim_color(c); v[1].x = 0+R; v[1].y = 0; c = al_map_rgb(rand()%256, rand()%256, rand()%256); v[1].color = al_get_prim_color(c); float a = 0; float r = R; int i; for (i = 2; i < POINTS; i++) { v[i].x = 0+cos(a)*r; v[i].y = 0+sin(a)*r; a += 0.3f; r -= 1.5f; c = al_map_rgb(rand()%256, rand()%256, rand()%256); v[i].color = al_get_prim_color(c); } int frames = 0; ALLEGRO_TRANSFORM t; while (true) { al_clear_to_color(al_map_rgb(0, 0, 0)); al_identity_transform(&t); al_rotate_transform(&t, frames*0.1f); al_translate_transform(&t, W/2, H/2); al_use_transform(&t); al_draw_prim(v, NULL, 0, POINTS, ALLEGRO_PRIM_TRIANGLE_FAN); al_flip_display(); /* GP2X Wiz is locked to 60FPS using OpenGL */ frames++; if (frames > 400) break; } al_uninstall_system(); return 0; }
bool System::shutdownSharedSystem() { if (al_is_joystick_installed()) al_uninstall_joystick(); if (al_is_mouse_installed()) al_uninstall_mouse(); if (al_is_keyboard_installed()) al_uninstall_keyboard(); al_shutdown_image_addon(); if (al_is_system_installed()) al_uninstall_system(); return true; }
GUI::~GUI() { al_stop_timer(timer); al_unregister_event_source(queue, al_get_keyboard_event_source()); al_unregister_event_source(queue, al_get_display_event_source(display)); al_unregister_event_source(queue, al_get_timer_event_source(timer)); al_destroy_event_queue(queue); al_destroy_bitmap(tiles); al_destroy_display(display); al_uninstall_keyboard(); al_shutdown_font_addon(); al_shutdown_primitives_addon(); al_shutdown_image_addon(); al_uninstall_system(); }
/* NOTE: don't put any ALLEGRO_DEBUG in here! */ static void android_cleanup(bool uninstall_system) { if (already_cleaned_up) { return; } if (uninstall_system) { /* I don't think android calls our atexit() stuff since we're in a shared lib so make sure al_uninstall_system is called */ al_uninstall_system(); } finish_activity(_al_android_get_jnienv()); (*javavm)->DetachCurrentThread(javavm); already_cleaned_up = true; }
int main(int argc __attribute__((unused)), char *argv[]) { /* init allegro library */ ALLEGRO_TIMER *timer = NULL; al_init(); /* prepare random number generator */ srand(time(NULL)); /* activate all engine subsystems using the startup macro */ resetCollisionTable(); STARTUP(videoInit()) STARTUP(init_datafile(argv)) STARTUP(al_install_keyboard()) STARTUP(al_install_joystick()) STARTUP(fontInit()) STARTUP(setupSound()) timer = al_create_timer(1.0 / 60); al_start_timer(timer); initMediaLib(); initBuffers(); /* prepare game */ startGame(); /* begin game loop */ while(!state.terminate) { runState(timer); } /* finish, return control to os */ al_destroy_timer(timer); shutdownState(); shutdownGame(); videoKill(); shutdownSound(); al_uninstall_system(); PHYSFS_deinit(); /* no problems, exit false */ return EXIT_SUCCESS; }
void safe_exit(int exit_value) { fprintf(stdout, "\nStopping sound thread."); stop_sound_thread(); // will only stop the sound thread if it's been initialised fprintf(stdout, "\nDestroying display."); if (display != NULL) // display is initialised to NULL right at the start al_destroy_display(display); fprintf(stdout, "\nDestroying timer."); if (timer != NULL) // same al_destroy_timer(timer); fpr("\nClosing down Allegro system."); al_uninstall_system(); fprintf(stdout, "\nExiting with value %i.", exit_value); exit(exit_value); }
virtual ~Core() { if (_optionParser) delete _optionParser; if (_slideshowDisplay) delete _slideshowDisplay; if (_captureDisplay) delete _captureDisplay; if (_captureListener) delete _captureListener; if (_cameraContext) delete _cameraContext; if (_eventQueue) al_destroy_event_queue(_eventQueue); if (_timer) al_destroy_timer(_timer); al_uninstall_mouse(); al_uninstall_keyboard(); al_shutdown_image_addon(); al_uninstall_system(); }
void Renderer::uninit() { if(queue_) al_destroy_event_queue(queue_); if(tmr_) al_destroy_timer(tmr_); if(prg_) { al_use_shader(nullptr); al_destroy_shader(prg_); } if(resManager_) delete resManager_; for(auto chunk: chunkData_) { delete chunk.second; } chunkData_.clear(); if(dpy_) al_destroy_display(dpy_); if(al_is_system_installed()) al_uninstall_system(); tmr_ = nullptr; dpy_ = nullptr; queue_ = nullptr; prg_ = nullptr; resManager_ = nullptr; // TODO: delete loaded chunks? }
void main_close_allegro_library() { regular_message("shutdown primitive addon"); al_shutdown_primitives_addon(); regular_message("shutdown native dialog addon"); al_shutdown_native_dialog_addon(); regular_message("shutdown image addon"); al_shutdown_image_addon(); regular_message("uninstall audio"); al_uninstall_audio(); regular_message("uninstall keyboard"); al_uninstall_keyboard(); regular_message("uinstall mouse"); al_uninstall_mouse(); regular_message("uninstll allegro system"); al_uninstall_system(); }
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(int argc, char **argv) { float r = 0.5, g = 0.5, b = 1, ratio = 0; int dir = 1; ALLEGRO_DISPLAY *display; ALLEGRO_BITMAP *mysha; ALLEGRO_BITMAP *buffer; const char *tinter_shader_src[] = { "uniform sampler2D backBuffer;", "uniform float r;", "uniform float g;", "uniform float b;", "uniform float ratio;", "void main() {", " vec4 color;", " float avg, dr, dg, db;", " color = texture2D(backBuffer, gl_TexCoord[0].st);", " avg = (color.r + color.g + color.b) / 3.0;", " dr = avg * r;", " dg = avg * g;", " db = avg * b;", " color.r = color.r - (ratio * (color.r - dr));", " color.g = color.g - (ratio * (color.g - dg));", " color.b = color.b - (ratio * (color.b - db));", " gl_FragColor = color;", "}" }; const int TINTER_LEN = 18; double start; GLint loc; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro\n"); } al_install_keyboard(); al_init_image_addon(); al_set_new_display_flags(ALLEGRO_OPENGL); display = al_create_display(320, 200); if (!display) { abort_example("Error creating display\n"); } mysha = al_load_bitmap("data/mysha.pcx"); if (!mysha) { abort_example("Could not load image.\n"); } buffer = al_create_bitmap(320, 200); if (!al_have_opengl_extension("GL_EXT_framebuffer_object") && !al_have_opengl_extension("GL_ARB_fragment_shader")) { abort_example("Fragment shaders not supported.\n"); } tinter_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); glShaderSourceARB(tinter_shader, TINTER_LEN, tinter_shader_src, NULL); glCompileShaderARB(tinter_shader); tinter = glCreateProgramObjectARB(); glAttachObjectARB(tinter, tinter_shader); glLinkProgramARB(tinter); loc = glGetUniformLocationARB(tinter, "backBuffer"); glUniform1iARB(loc, al_get_opengl_texture(buffer)); start = al_get_time(); while (1) { double now, diff; ALLEGRO_KEYBOARD_STATE state; al_get_keyboard_state(&state); if (al_key_down(&state, ALLEGRO_KEY_ESCAPE)) { break; } now = al_get_time(); diff = now - start; start = now; ratio += diff * 0.5 * dir; if (dir < 0 && ratio < 0) { ratio = 0; dir = -dir; } else if (dir > 0 && ratio > 1) { ratio = 1; dir = -dir; } al_set_target_bitmap(buffer); glUseProgramObjectARB(tinter); loc = glGetUniformLocationARB(tinter, "ratio"); glUniform1fARB(loc, ratio); loc = glGetUniformLocationARB(tinter, "r"); glUniform1fARB(loc, r); loc = glGetUniformLocationARB(tinter, "g"); glUniform1fARB(loc, g); loc = glGetUniformLocationARB(tinter, "b"); glUniform1fARB(loc, b); al_draw_bitmap(mysha, 0, 0, 0); glUseProgramObjectARB(0); al_set_target_backbuffer(display); al_draw_bitmap(buffer, 0, 0, 0); al_flip_display(); al_rest(0.001); } glDetachObjectARB(tinter, tinter_shader); glDeleteObjectARB(tinter_shader); al_uninstall_system(); return 0; }
int main() { //inicialização camera *cam = camera_inicializa(0); if(!cam) erro("erro na inicializacao da camera\n"); int largura = cam->largura; int altura = cam->altura; if(!al_init()) erro("erro na inicializacao do allegro\n"); if(!al_init_image_addon()) erro("erro na inicializacao do adicional de imagem\n"); if(!al_init_primitives_addon()) erro("erro na inicializacao do adicional de primitivas\n"); ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS); if(!timer) erro("erro na criacao do relogio\n"); ALLEGRO_DISPLAY *display = al_create_display(largura, altura); if(!display) erro("erro na criacao da janela\n"); ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue(); if(!queue) erro("erro na criacao da fila\n"); al_register_event_source(queue, al_get_timer_event_source(timer)); al_register_event_source(queue, al_get_display_event_source(display)); al_start_timer(timer); /**********/ unsigned char ***matriz = camera_aloca_matriz(cam); int ***background = alocaHsvMatriz(cam->largura, cam->altura); fila *f = aloca(); //cor para desenhar o círculo ALLEGRO_COLOR cor = al_map_rgb_f(0, 0, 1); ALLEGRO_BITMAP *buffer = al_get_backbuffer(display); //tela exibindo img normal ALLEGRO_BITMAP *esquerda = al_create_sub_bitmap(buffer, 0, 0, largura, altura); //tela mostrando como o computador enxerga //ALLEGRO_BITMAP *direita = al_create_sub_bitmap(buffer, largura/2, 0, largura/2, altura/2); ALLEGRO_BITMAP *silhueta = al_create_bitmap(largura, altura); /**********/ srand(time(NULL)); int desenhar = 0; int terminar = 0; int cycle = 0; int hitx = rand() % (largura); int hity = rand() % (altura); int x, y; float cyr, cxr, cnr, lastCx, lastCy; int r, g, b, r2, g2, b2; int h, s, v, h2, s2, v2; int fh, fs, fv; int dh, ds, dv; int tempH; int token; double value; int dist; al_rest(1); for(y = 0; y < altura; y++) for(x = 0; x < largura; x++){ rgbToHsv(cam->quadro[y][x][0], cam->quadro[y][x][1], cam->quadro[y][x][2], &background[y][x][0], &background[y][x][1], &background[y][x][2]); if(background[y][x][0] > 180){ background[y][x][0] -= 360; background[y][x][0] = -background[y][x][0]; } } al_rest(1); for(y = 0; y < altura; y++) for(x = 0; x < largura; x++){ rgbToHsv(cam->quadro[y][x][0], cam->quadro[y][x][1], cam->quadro[y][x][2], &fh, &fs, &fv); if(fh > 180){ fh -= 360; fh = -fh; } background[y][x][0] += fh; background[y][x][0] /=2; background[y][x][1] += fs; background[y][x][1] /=2; background[y][x][2] += fv; background[y][x][2] /=2; } //gameloop while(1) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); switch(event.type) { case ALLEGRO_EVENT_TIMER: desenhar = 1; break; case ALLEGRO_EVENT_DISPLAY_CLOSE: terminar = 1; break; default: printf("evento desconhecido\n"); } if(terminar) break; //interpretar img e realizar transformações printf("%d\n", al_is_event_queue_empty(queue)); if(desenhar && al_is_event_queue_empty(queue)) { desenhar = 0; camera_atualiza(cam); /**********/ int bx, by, bn; cyr = 0; cxr = 0; cnr = 0; for(y = 0; y < altura; y++){ for(x = 0; x < largura; x++){ //Espada r = cam->quadro[y][x][0]; g = cam->quadro[y][x][1]; b = cam->quadro[y][x][2]; rgbToHsv(r, g, b, &h, &s, &v); if(h < 15 || h > 345) if(s > 75 && v > 75){ cyr += y; cxr += x; cnr++; } //Silhueta (REFINAR!!!) if(h > 180) tempH = -(h - 360); else tempH = h; dh = tempH - background[y][x][0]; if(dh < 0) dh = -dh; ds = s - background[y][x][1]; if(ds < 0) ds = -ds; dv = v - background[y][x][2]; if(dv < 0) dv = -dv; //dh > 15 && ds > 10 para tirar a interfencia de iluminacao, mas gera mtuiro ruido //ds > 25 é o mais preciso, mas sofre de interferencia de iluminacao if(dv > 25){ //valores para teste! matriz[y][x][0] = 37; matriz[y][x][1] = 50; matriz[y][x][2] = 248; } else{ matriz[y][x][0] = 0; matriz[y][x][1] = 0; matriz[y][x][2] = 0; } //Escudo if(h < 135 && h > 105 && s > 50 && v > 75){ by += y; bx += x; bn++; matriz[y][x][0] = 0; matriz[y][x][1] = 255; matriz[y][x][2] = 0; } } } /*for(y = 1; y < altura-1; y++) for(x = 1; x < largura-1; x++){ token = 4; if(255 != matriz[y+1][x][0]) token--; if(255 != matriz[y-1][x][0]) token--; if(255 != matriz[y][x+1][0]) token--; if(255 != matriz[y][x-1][0]) token--; if(token == 0){ matriz[y][x][0] = 0; matriz[y][x][1] = 0; matriz[y][x][2] = 0; }*/ cycle++; if(cycle > 50 && bn > 0){ value = (pow(hitx - (bx / 2 /bn), 2) + pow(hity - (by / 2 / bn), 2)); dist = sqrt(value) - 7; if(dist < 100 && dist > -100 && bn > 0) printf("block!\n"); else{ if(matriz[hity][hitx][0] == 255) printf("hit\n"); else printf("miss\n"); } cycle = 0; hitx = rand() % (largura/2); hity = rand() % (altura/2); } /**********/ camera_copia(cam, cam->quadro, esquerda); //Copia img editada na img direita camera_copia(cam, matriz, silhueta); //cor para teste! al_convert_mask_to_alpha(silhueta, al_map_rgb(37, 50, 248)); al_draw_bitmap(silhueta, 0, 0, 0); /**********/ if(bn > 0) al_draw_circle(bx / bn, by / bn, 100, al_map_rgb(0, 0, 255), 1); if(cycle >= 40){ if(cycle < 48){ al_draw_circle(hitx, hity, 15, al_map_rgb(0, 0, 255), 30); al_draw_circle(hitx + largura, hity, 6, al_map_rgb(0, 0, 255), 3); } else al_draw_circle(hitx, hity, 15, al_map_rgb(255, 0, 0), 30); } if(cnr > 10){ lastCx = cxr / cnr; lastCy = cyr / cnr; al_draw_circle(lastCx, lastCy, 100, al_map_rgb(255, 0, 0), 1); insere(f, lastCx, lastCy); } else insere(f, lastCx, lastCy); if(f->count > 10) retira(f); drawAtk(f); al_flip_display(); } } /**********/ libera(f); al_destroy_bitmap(silhueta); al_destroy_bitmap(esquerda); camera_libera_matriz(cam, matriz); liberaHsvMatriz(background, cam->largura, cam->altura); /**********/ al_stop_timer(timer); al_unregister_event_source(queue, al_get_display_event_source(display)); al_unregister_event_source(queue, al_get_timer_event_source(timer)); al_destroy_event_queue(queue); al_destroy_display(display); al_destroy_timer(timer); al_shutdown_primitives_addon(); al_shutdown_image_addon(); al_uninstall_system(); camera_finaliza(cam); return EXIT_SUCCESS; }
VALUE rbal_uninstall_system(VALUE rself) { al_uninstall_system(); return Qnil; }
/* signal_handler: * Used to trap various signals, to make sure things get shut down cleanly. */ static RETSIGTYPE signal_handler (int num) { al_uninstall_system(); fprintf (stderr, "Shutting down Allegro due to signal #%d\n", num); raise (num); }
bool Renderer::init(Minecraft *mc, const char *argv0) { NBT_Debug("begin"); al_set_org_name("mctools"); al_set_app_name("viewer"); if(!al_init()) { NBT_Debug("al_init failed???"); return false; } ALLEGRO_TIMER *tmr = nullptr; ALLEGRO_EVENT_QUEUE *queue = nullptr; ALLEGRO_DISPLAY *dpy = nullptr; ALLEGRO_BITMAP *bmp = nullptr; ALLEGRO_TRANSFORM *def_trans = nullptr; ALLEGRO_FONT *fnt = nullptr; if(!al_install_keyboard()) goto init_failed; if(!al_install_mouse()) goto init_failed; if(!al_init_primitives_addon()) goto init_failed; if(!al_init_image_addon()) goto init_failed; if(!al_init_font_addon()) goto init_failed; tmr = al_create_timer(1.0/60.0); if(!tmr) goto init_failed; queue = al_create_event_queue(); if(!queue) goto init_failed; // do display creation last so a display isn't created and instantly destroyed if any of the // preceeding initializations fail. al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_PROGRAMMABLE_PIPELINE | ALLEGRO_OPENGL_3_0); //al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE); //al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_REQUIRE); al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 24, ALLEGRO_REQUIRE); dpy = al_create_display(800, 600); if(!dpy) { NBT_Debug("display creation failed"); goto init_failed; } if(!al_get_opengl_extension_list()->ALLEGRO_GL_EXT_framebuffer_object) { NBT_Debug("FBO GL extension is missing. bail"); goto init_failed; } glGenVertexArrays(1, &vao_); glBindVertexArray(vao_); NBT_Debug("load shaders"); if(!loadShaders("shaders/default.vtx", "shaders/default.pxl")) { NBT_Debug("shader init failed"); goto init_failed; } NBT_Debug("load allegro shaders"); if(!loadAllegroShaders()) { NBT_Debug("allegro shader init failed"); goto init_failed; } glBindVertexArray(0); NBT_Debug("create resource manager"); resManager_ = new ResourceManager(this); if(!resManager_->init(mc, argv0)) { NBT_Debug("failed to init resource manager"); goto init_failed; } fnt = al_create_builtin_font(); if(!fnt) { NBT_Debug("failed to create builtin font"); goto init_failed; } al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_mouse_event_source()); al_register_event_source(queue, al_get_display_event_source(dpy)); al_register_event_source(queue, al_get_timer_event_source(tmr)); def_trans = al_get_projection_transform(dpy); al_copy_transform(&al_proj_transform_, def_trans); al_identity_transform(&camera_transform_); rx_look = 0.0; queue_ = queue; tmr_ = tmr; dpy_ = dpy; bmp_ = bmp; fnt_ = fnt; grab_mouse_ = false; // initial clear display // make things look purdy al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); NBT_Debug("end"); return true; init_failed: delete resManager_; resManager_ = nullptr; if(fnt) al_destroy_font(fnt); if(dpy) al_destroy_display(dpy); if(queue) al_destroy_event_queue(queue); al_uninstall_system(); NBT_Debug("end"); return false; }
int main() { camera *cam = camera_inicializa(0); if(!cam) erro("nao foi possivel inicializar camera"); int largura = cam->largura; int altura = cam->altura; if(!al_init()) erro("nao foi possivel inicializar allegro"); if(!al_init_primitives_addon()) erro("nao foi possivel inicializar adicional de primitivas"); if(!al_init_image_addon()) erro("nao foi possivel inicializar a adicional de imagem "); ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue(); if(!queue) erro("nao foi possivel criar fila de eventos"); ALLEGRO_DISPLAY *display = al_create_display(2 * largura, altura * 2); if(!display) erro("nao foi possivel criar janela"); al_register_event_source(queue, al_get_display_event_source(display)); ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS); if(!timer) erro("nao foi possivel criar relogio"); al_register_event_source(queue, al_get_timer_event_source(timer)); /**********/ unsigned char ***matriz = camera_aloca_matriz(cam); unsigned char ***anterior; ALLEGRO_COLOR cor = al_map_rgb_f(0, 0, 1); ALLEGRO_BITMAP *buffer = al_get_backbuffer(display); ALLEGRO_BITMAP *esquerda = al_create_sub_bitmap(buffer, 0, 0, largura, altura); ALLEGRO_BITMAP *direita = al_create_sub_bitmap(buffer, largura, 0, largura, altura); ALLEGRO_BITMAP * baixo = al_create_sub_bitmap(buffer, largura/2, altura, largura, altura); sniper = al_load_bitmap("semi.png"); /**********/ int continuar = 1; int atualizar = 0; al_start_timer(timer); while(continuar) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); switch(event.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: continuar = 0; break; case ALLEGRO_EVENT_TIMER: atualizar = 1; break; } if(atualizar && al_is_event_queue_empty(queue)) { camera_atualiza(cam); /**********/ int cy = 0; int cx = 0; int cn = 0; for(int y = 0; y < altura; y++) for(int x = 0; x < largura; x++) { float r = (cam->quadro[y][x][0]) / 255; float g = (cam->quadro[y][x][1]) / 255; float b = (cam->quadro[y][x][2]) / 255; /*if(compara_imagem(cam, matriz, anterior)) { cy += y; cx += x; cn += 1; matriz[y][x][0] = 255; matriz[y][x][1] = 255; matriz[y][x][2] = 255; } else { matriz[y][x][0] = 0; matriz[y][x][1] = 0; matriz[y][x][2] = 0; } } */ anterior = compara_imagem(cam, matriz, anterior); //int x1 = cx / cn; //int y1 = cy / cn; /**********/ } camera_copia(cam, cam->quadro, esquerda); camera_copia(cam, matriz, direita); camera_copia(cam, anterior, baixo); if(cn > 0){ //al_draw_circle(cx / cn, cy / cn, 120, cor, 1); //al_draw_bitmap(sniper, cx / cn, cy / cn, 120); // SNIPER al_draw_bitmap(sniper, cx / cn - 400, cy / cn - 300, 120); camera_copia(cam, cam->quadro, direita); /**********/ al_flip_display(); atualizar = 0; } } } al_stop_timer(timer); /**********/ al_destroy_bitmap(direita); al_destroy_bitmap(esquerda); camera_libera_matriz(cam, matriz); /**********/ al_unregister_event_source(queue, al_get_timer_event_source(timer)); al_destroy_timer(timer); al_unregister_event_source(queue, al_get_display_event_source(display)); al_destroy_display(display); al_destroy_event_queue(queue); al_shutdown_primitives_addon(); al_uninstall_system(); camera_finaliza(cam); return EXIT_SUCCESS; }
~Fixture() { al_destroy_bitmap(bitmap); al_uninstall_system(); }
static mrb_value uninstall(mrb_state *mrb, mrb_value self) { al_uninstall_system(); return mrb_nil_value(); }
int main() { bool menu = true; char pontuacao[100]; char vida[100]; ALLEGRO_COLOR font_color; ALLEGRO_FONT *font,*font2; ALLEGRO_AUDIO_STREAM *musica = NULL; camera *cam = camera_inicializa(0); if(!cam) erro("erro na inicializacao da camera\n"); int x = 0, y = 0; int largura = cam->largura; int altura = cam->altura; int fps = 0,tempo = 5; int ndisco = 9; if(!al_init()) erro("erro na inicializacao do allegro\n"); if(!al_init_image_addon()) erro("erro na inicializacao do adicional de imagem\n"); al_init_font_addon(); al_init_ttf_addon(); font_color = al_map_rgb(0, 0, 0); font = al_load_ttf_font("Fontes/Blokletters-Viltstift.ttf", 20, 0); font2 = al_load_ttf_font("Fontes/Blokletters-Viltstift.ttf", 50, 0); if(!al_init_primitives_addon()) erro("erro na inicializacao do adicional de primitivas\n"); ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS); if(!timer) erro("erro na criacao do relogio\n"); ALLEGRO_DISPLAY *display = al_create_display(2 * largura,altura); if(!display) erro("erro na criacao da janela\n"); ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue(); if(!queue) erro("erro na criacao da fila\n"); if (!al_install_audio()) { fprintf(stderr, "Falha ao inicializar áudio.\n"); return false; } if (!al_init_acodec_addon()) { fprintf(stderr, "Falha ao inicializar codecs de áudio.\n"); return false; } if (!al_reserve_samples(1)) { fprintf(stderr, "Falha ao alocar canais de áudio.\n"); return false; } musica = al_load_audio_stream("Audio/elementary.ogg", 4, 1024); if(!musica) erro("Erro na alocação da musica de fundo\n"); al_attach_audio_stream_to_mixer(musica, al_get_default_mixer()); al_set_audio_stream_playing(musica, true); al_register_event_source(queue, al_get_timer_event_source(timer)); al_register_event_source(queue, al_get_display_event_source(display)); al_start_timer(timer); unsigned char ***matriz = camera_aloca_matriz(cam); ALLEGRO_BITMAP *buffer = al_get_backbuffer(display); ALLEGRO_BITMAP *fundo = al_load_bitmap("Imagens/Elementary2.png"); if(!fundo) erro("erro ao carregar Elementary.png"); ALLEGRO_BITMAP *esquerda = al_create_sub_bitmap(buffer, 0, 0, largura, altura); ALLEGRO_BITMAP *direita = al_create_sub_bitmap(buffer, largura, 0, largura, altura); /**********/ Disco *discos[9]; bool perdeu = false; carregarDiscos(discos); int pontos=0,velo = 1; int aux1 = 1; int vidas = 10; int ultimoDisco = 0; int distance = 0; int desenhar = 0; int terminar = 0; al_set_target_bitmap(esquerda); al_draw_bitmap(fundo,0,0,0); while(1) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); switch(event.type) { case ALLEGRO_EVENT_TIMER: desenhar = 1; break; case ALLEGRO_EVENT_DISPLAY_CLOSE: terminar = 1; break; } if(terminar) break; if(desenhar && al_is_event_queue_empty(queue)) { desenhar = 0; camera_atualiza(cam); mediana(cam); /**********/ al_set_target_bitmap(esquerda); al_draw_bitmap(fundo,0,0,0); if(!menu){ while(aux1 <= ndisco){ if(discos[aux1]->status == false){ if(distance > 50 || ultimoDisco==0 ){ printf("%d\n",aux1 ); al_draw_bitmap(discos[aux1]->elemento,discos[aux1]->pos_x,discos[aux1]->pos_y,0); discos[aux1]->status = true; distance = 0; ultimoDisco = aux1; break; }else aux1++; }else{ discos[aux1]->pos_y+=(10+velo); al_draw_bitmap(discos[aux1]->elemento,discos[aux1]->pos_x,discos[aux1]->pos_y,0); aux1++; } } distance = discos[ultimoDisco]->pos_y; for(aux1 = 1;aux1<ndisco;aux1++){ if(discos[aux1]->pos_x >= x-30 && discos[aux1]->pos_x <= x+30 && discos[aux1]->pos_y >= y-30 && discos[aux1]->pos_y <= y+30){ if(discos[aux1]->tipo == 2){ // Tipo do fogo(Necessario para vencer o jogo) pontos +=10; velo += 1; discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; }else if(discos[aux1]->tipo == 1){ //Tipo da agua(Perde o jogo se destruir esse disco) discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; al_flip_display(); vidas--; }else if(discos[aux1]->tipo == 3){//Tipo planta(Aumenta velocidade de queda das peças) velo *= 2; discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; } }else if( discos[aux1]->pos_y > 480){ if(discos[aux1]->tipo == 2){ //Tipo da agua e Planta(Não perde se deixar cair) discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; al_flip_display(); vidas--; }else{ discos[aux1]->pos_x = rand()%9 * 55; discos[aux1]->pos_y = 0; discos[aux1]->status = false; } } } aux1 = 1; sprintf(pontuacao,"PONTUAÇÃO: %d",pontos); al_draw_text(font, al_map_rgb(255, 255, 255), 50, 5, 0,pontuacao); sprintf(vida,"VIDAS: %d",vidas); al_draw_text(font, al_map_rgb(255, 255, 255), 300, 5, 0,vida); al_flip_display(); } if(perdeu){ al_draw_text(font2, al_map_rgb(255, 0, 0), 50, 100, 0,"PONTUAÇÃO FINAL"); sprintf(pontuacao,"%d",pontos); al_draw_text(font2, al_map_rgb(255, 0, 0), 250, 170, 0,pontuacao); al_flip_display(); al_rest(3); break; } if(vidas == 0){ perdeu = true; } if(menu){ if(abrirJogo(x,y,&fps,&tempo,font,font2, font_color)){ fundo = al_load_bitmap("Imagens/galaxia.png"); menu = false; } } cameraRastreia(cam,&x,&y); al_set_target_bitmap(direita); camera_copia(cam, cam->quadro, direita); al_flip_display(); } } al_destroy_bitmap(direita); al_destroy_bitmap(fundo); al_destroy_bitmap(esquerda); camera_libera_matriz(cam, matriz); int fri = 9; while(fri != 0){ free(discos[fri]); fri--; } al_stop_timer(timer); al_unregister_event_source(queue, al_get_display_event_source(display)); al_unregister_event_source(queue, al_get_timer_event_source(timer)); al_destroy_event_queue(queue); al_destroy_display(display); al_destroy_timer(timer); al_destroy_audio_stream(musica); al_shutdown_primitives_addon(); al_shutdown_image_addon(); al_uninstall_system(); camera_finaliza(cam); return EXIT_SUCCESS; }
Framework::~Framework() { #ifdef WRITE_LOG fprintf( LogFile, "Framework: Save Config\n" ); #endif SaveSettings(); #ifdef PANDORA #ifdef WRITE_LOG fprintf( LogFile, "Framework: Hacky Pandora Shutdown\n" ); #endif raise(SIGKILL); #endif #ifdef WRITE_LOG fprintf( LogFile, "Framework: Clear stages\n" ); #endif if( ProgramStages != 0 ) { // Just make sure all stages are popped and deleted ShutdownFramework(); } #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown\n" ); #endif al_unregister_event_source( eventAllegro, DISPLAY->GetEventSource() ); al_destroy_event_queue( eventAllegro ); al_destroy_mutex( eventMutex ); al_destroy_timer( frameTimer ); #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown display\n" ); #endif DISPLAY->Shutdown(); delete DISPLAY; #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown audio\n" ); #endif delete AUDIO; #ifdef NETWORK_SUPPORT #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown enet\n" ); #endif enet_deinitialize(); #endif #ifdef DOWNLOAD_SUPPORT #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown downloads\n" ); #endif DOWNLOADS->AbortDownloads = true; delete DOWNLOADS; #endif #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown Allegro\n" ); #endif al_uninstall_system(); #ifdef WRITE_LOG fclose( LogFile ); #endif }