void uninit() { if (this->event_queue_) al_destroy_event_queue(this->event_queue_); if (this->timer_) al_destroy_timer(this->timer_); al_uninstall_keyboard(); al_uninstall_mouse(); }
void shutdown_allegro(al_defs *al){ unload_resources(al); al_destroy_display(al->disp); al_destroy_event_queue(al->queue); al_shutdown_image_addon(); al_shutdown_font_addon(); al_shutdown_ttf_addon(); al_uninstall_keyboard(); }
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(); }
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(); }
void Game::cleanup() { //delete units delete mpUnit; mpUnit = NULL; delete mpAIUnit; mpAIUnit = NULL; delete mpAIUnit2; mpAIUnit2 = NULL; //delete the timers delete mpLoopTimer; mpLoopTimer = NULL; delete mpMasterTimer; mpMasterTimer = NULL; //delete the graphics system delete mpGraphicsSystem; mpGraphicsSystem = NULL; delete mpGraphicsBufferManager; mpGraphicsBufferManager = NULL; delete mpSpriteManager; mpSpriteManager = NULL; delete mpMessageManager; mpMessageManager = NULL; al_destroy_sample(mpSample); mpSample = NULL; al_destroy_font(mpFont); mpFont = NULL; //shutdown components al_uninstall_audio(); al_shutdown_image_addon(); al_shutdown_font_addon(); al_shutdown_ttf_addon(); al_uninstall_keyboard(); al_uninstall_mouse(); al_shutdown_primitives_addon(); }
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 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(); }
Framework::~Framework() { Settings->Save( "settings.cfg" ); #ifdef WRITE_LOG printf( "Framework: Shutdown\n" ); #endif al_destroy_event_queue( eventQueue ); al_destroy_display( displaySurface ); al_destroy_mutex( extraEventsMutex ); delete imageMgr; delete audioMgr; delete fontMgr; delete networkMgr; delete downloadMgr; // Shutdown Allegro if( mixer != 0 ) { al_destroy_mixer( mixer ); } if( voice != 0 ) { al_destroy_voice( voice ); } al_uninstall_keyboard(); al_uninstall_mouse(); al_shutdown_primitives_addon(); al_shutdown_ttf_addon(); al_shutdown_image_addon(); al_shutdown_font_addon(); al_uninstall_audio(); al_uninstall_joystick(); }
bool deinitialize () { int i; al_destroy_font (global.programing_font); al_destroy_event_queue (global.queue); al_destroy_display (global.display); al_destroy_bitmap (global.arrow_bitmap); for (i = 0; i < NUM_OF_SPRITE_TYPES; i++) { al_destroy_bitmap (global.sprite_bitmap[i]); } for (i = 0; i < NUM_OF_BACKGROUNDS; i++) { al_destroy_bitmap (global.backgrounds[i]); } for (i = 0; i < NUM_OF_SOUNDS; i++) { al_destroy_sample (global.sounds[i]); } /*if (global.music) { al_drain_audio_stream (global.music); al_destroy_audio_stream (global.music); } */ al_shutdown_image_addon (); al_uninstall_audio (); al_uninstall_keyboard (); return true; }
static int allua_keyboard_uninstall(lua_State * L) { al_uninstall_keyboard(); return 0; }
int main(void) { asteroids.lives = START_LIVES; asteroids.display = NULL; asteroids.timer = NULL; asteroids.event_queue = NULL; SHIP *ship; bool redraw = true; bool quit = false; bool key[7] = { false }; seed_rand(); atexit(shutdown); if(!init()) exit(EXIT_FAILURE); if((asteroids.high_score = get_config_value("high_score")) == NULL) asteroids.high_score = "0"; asteroids.level = level_create(0, 0); if(!(ship = ship_create())) exit(EXIT_FAILURE); al_flip_display(); al_start_timer(asteroids.timer); while(!quit) { ALLEGRO_EVENT ev; al_wait_for_event(asteroids.event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) { /* start game */ if(asteroids.level->number == 0 && key[KEY_S]) { start(); continue; } /* are we out of asteroids to destroy? */ if(list_length(asteroids.level->asteroids) == 0) asteroids.level = level_next(asteroids.level); /* update objects */ ship = ship_update(ship, key, asteroids.timer); explosions_update(); asteroids.level = level_update(asteroids.level, ship, key, asteroids.timer); /* ship->asteroid collisions. */ check_ship_asteroid_collisions(ship, asteroids.level->asteroids); /* ship[missile] -> asteroid collisions. */ check_ship_missile_asteroid_collisions(asteroids.level, ship); /* ship[missile] -> saucer collisions. */ check_ship_missile_saucer_collisions(asteroids.level, ship); /* saucer[missile] -> ship collisions. */ check_saucer_missile_ship_collisions(asteroids.level, ship); /* saucer[missile] -> asteroid collisions. */ check_saucer_missile_asteroids_collisions(asteroids.level); /* saucer->asteroid collisions. */ check_saucer_asteroid_collisions(asteroids.level); redraw = true; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { keydown(ev, key); quit = key[KEY_ESCAPE]; } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { keyup(ev, key); ship->fire_debounce = key[KEY_SPACE]; ship->hyper_debounce = key[KEY_LCONTROL]; } if(redraw && al_is_event_queue_empty(asteroids.event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(BLACK)); level_draw(asteroids.level); draw_lives(); draw_high_score(); animation_draw_list(asteroids.explosions); if(asteroids.level->number == 0) { draw_home(); al_flip_display(); continue; } if(asteroids.lives > 0) { ship_draw(ship, key[KEY_UP]); missile_draw_list(ship->missiles); } else { if(ship->explosion) ship_draw(ship, false); draw_gameover(); } al_flip_display(); } }; /* FIXME: cleanup */ if(asteroids.timer != NULL) al_destroy_timer(asteroids.timer); if(asteroids.event_queue != NULL) al_destroy_event_queue(asteroids.event_queue); if(asteroids.display != NULL) al_destroy_display(asteroids.display); LIST *head = list_first(asteroids.level->asteroids); while(head != NULL) { ASTEROID *rock = (ASTEROID *) head->data; asteroid_free(rock); head = head->next; } ship_free(ship); al_destroy_bitmap(asteroids.lives_sprite); ship_shutdown(); missile_shutdown(); asteroid_shutdown(); explosion_shutdown(); al_uninstall_keyboard(); exit(EXIT_SUCCESS); }
int main( int argc, char* argv[] ) { ALLEGRO_EVENT e; ALLEGRO_TIMER* t; int64_t framesToUpdate = 0; if( !al_init() ) { return -1; } al_init_font_addon(); if( !al_install_keyboard() || !al_install_mouse() || !al_init_primitives_addon() || !al_init_ttf_addon() || !al_init_image_addon() ) { return -1; } #if NETWORK_SUPPORT != 0 if( !install_network() ) { return -1; } #endif #if HTTP_SUPPORT if( !install_http() ) { return -1; } #ifdef PANDORA Downloads = new HttpManager(2); #else Downloads = new HttpManager(6); #endif #endif #if EXIT_IF_NO_AUDIO != 0 if( !al_install_audio() || !al_init_acodec_addon() ) { return -1; } voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); if (!voice) return 1; mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); if (!mixer) return 1; if (!al_attach_mixer_to_voice(mixer, voice)) return 1; #else if( al_install_audio() ) { if( al_init_acodec_addon() ) { voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); if( voice != 0 ) { mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); if( mixer != 0 ) al_attach_mixer_to_voice(mixer, voice); } } } #endif // EXIT_IF_NO_AUDIO // Random number is guarenteed to be random srand( 5 ); GameStack = new StageStack(); CurrentConfiguration = new Configuration(); if( CurrentConfiguration->FullScreen ) al_set_new_display_flags( ALLEGRO_FULLSCREEN_WINDOW ); al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST); bool foundMode = false; int fallbackW = 640; int fallbackH = 480; if( CurrentConfiguration->ForceResolution ) { foundMode = true; } else { for( int modeIdx = 0; modeIdx < al_get_num_display_modes(); modeIdx++ ) { if( al_get_display_mode( modeIdx, &ScreenMode ) != NULL ) { if( ScreenMode.width == CurrentConfiguration->ScreenWidth && ScreenMode.height == CurrentConfiguration->ScreenHeight ) { foundMode = true; } else { fallbackW = ScreenMode.width; fallbackH = ScreenMode.height; } } if( foundMode ) break; } } if( foundMode ) { Screen = al_create_display( CurrentConfiguration->ScreenWidth, CurrentConfiguration->ScreenHeight ); } else { Screen = al_create_display( fallbackW, fallbackH ); CurrentConfiguration->ScreenWidth = fallbackW; CurrentConfiguration->ScreenHeight = fallbackH; } al_hide_mouse_cursor( Screen ); t = al_create_timer( 1.0 / SCREEN_FPS ); if( t == NULL ) Quit = true; al_start_timer( t ); EventQueue = al_create_event_queue(); al_register_event_source( EventQueue, al_get_display_event_source( Screen ) ); al_register_event_source( EventQueue, al_get_keyboard_event_source() ); al_register_event_source( EventQueue, al_get_mouse_event_source() ); al_register_event_source( EventQueue, al_get_timer_event_source( t ) ); #if NETWORK_SUPPORT != 0 al_register_event_source( EventQueue, get_network_event_source() ); #endif #if HTTP_SUPPORT Downloads->urlDownloads = CurrentConfiguration->MaxConcurrentDownloads; al_register_event_source( EventQueue, get_http_event_source() ); #endif Fonts = new FontManager(); Images = new ImageManager(); Audio = new SoundManager(); al_set_blender( ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA ); GameStack->Push( (Stage*)new BootUp() ); while( !Quit ) { if( GameStack->IsEmpty() ) { Quit = true; } else { while( al_get_next_event( EventQueue, &e ) ) { #if HTTP_SUPPORT Downloads->Event( &e ); #endif switch( e.type ) { case ALLEGRO_EVENT_DISPLAY_CLOSE: Quit = true; break; case ALLEGRO_EVENT_JOYSTICK_CONFIGURATION: al_reconfigure_joysticks(); break; case ALLEGRO_EVENT_TIMER: if( e.timer.source == t ) framesToUpdate++; else if( !GameStack->IsEmpty() ) GameStack->Current()->Event( &e ); break; default: if( !GameStack->IsEmpty() ) GameStack->Current()->Event( &e ); switch( e.type ) { #if HTTP_SUPPORT case ALLEGRO_EVENT_HTTP: #endif #if NETWORK_SUPPORT case ALLEGRO_EVENT_NETWORK_CONNECTION: case ALLEGRO_EVENT_NETWORK_RECEIVEPACKET: case ALLEGRO_EVENT_NETWORK_DISCONNECTION: #endif case ALLEGRO_EVENT_BUTTON_CLICK: case ALLEGRO_EVENT_MOUSEEX_MOVE: case ALLEGRO_EVENT_MOUSEEX_DOWN: case ALLEGRO_EVENT_MOUSEEX_UP: case ALLEGRO_EVENT_MOUSEEX_CLICK: case ALLEGRO_EVENT_MOUSEEX_DOUBLECLICK: case ALLEGRO_EVENT_MOUSEEX_BOXED: case ALLEGRO_EVENT_MOUSEEX_WHEEL: al_unref_user_event( &e.user ); break; } break; } } if( framesToUpdate > 0 ) { for( int frmUp = 0; frmUp < framesToUpdate; frmUp++ ) { if( !GameStack->IsEmpty() ) GameStack->Current()->Update(); } framesToUpdate = 0; } al_clear_to_color( al_map_rgb( 128, 128, 128 ) ); if( !GameStack->IsEmpty() ) GameStack->Current()->Render(); al_flip_display(); Images->Tidy(); Fonts->Tidy(); Audio->Tidy(); } } while( !GameStack->IsEmpty() ) { GameStack->Pop(); } delete Downloads; delete Fonts; delete Images; delete Audio; al_destroy_event_queue( EventQueue ); al_destroy_display( Screen ); #if HTTP_SUPPORT uninstall_http(); #endif #if NETWORK_SUPPORT != 0 uninstall_network(); #endif al_uninstall_keyboard(); al_uninstall_mouse(); al_shutdown_primitives_addon(); al_shutdown_ttf_addon(); al_shutdown_image_addon(); al_uninstall_audio(); al_shutdown_font_addon(); return 0; }
/*metodo principal, gerencia a janela*/ int main(int argc, char argv[]) { /*janela principal*/ ALLEGRO_DISPLAY *janela = NULL; /*fila de eventos*/ ALLEGRO_EVENT_QUEUE *filaEvento = NULL; /*evento atual*/ ALLEGRO_EVENT evento; ALLEGRO_BITMAP *botao_gravar = NULL, *botao_carregar = NULL, *botao_girar_horario = NULL, *botao_girar_antihorario = NULL; /*ponteiro para um arquivo no dico*/ FILE *arquivo; /*definicoes do arquivo*/ int altura = 0,//altura da imagem largura = 0, //largura da imagem maxCor = 0;//inteiro que representa tonalidade de cor maxima char tipo[3];//tipo de PGM /*estrutura para armazenar os bits do arquivo*/ unsigned char **data = NULL; /*sinaliza fechamento da janela*/ bool fechaJanela = false; /*sinaliza existencia de arquivo aberto*/ bool arquivoAberto = false; /*inicializa bibliotecas*/ if(!(al_init() && al_install_mouse()&& al_init_image_addon()&& al_install_keyboard()&& al_init_primitives_addon()&& (filaEvento = al_create_event_queue()))){ printf("Erro ao inicializar biblioteca(s)!\n"); return 0; } // Alocamos o botão para fechar a aplicação criaBotao(botoes[0], "carregar.bmp"); botao_carregar = al_load_bitmap("carregar.bmp"); if (!botao_carregar) { fprintf(stderr, "Falha ao criar botão de carregar a imagem.\n"); al_destroy_display(janela); return -1; } // Alocamos o botão para fechar a aplicação botao_gravar = al_load_bitmap("salvar.bmp"); if (!botao_gravar) { fprintf(stderr, "Falha ao criar botão de salvar a imagem.\n"); al_destroy_bitmap(botao_carregar); al_destroy_display(janela); return -1; } // Alocamos o botão para fechar a aplicação botao_girar_horario = al_load_bitmap("girar_horario.bmp"); if (!botao_girar_horario) { fprintf(stderr, "Falha ao criar botão de girar a imagem 90º sentido horario.\n"); al_destroy_bitmap(botao_carregar); al_destroy_bitmap(botao_gravar); al_destroy_display(janela); return -1; } // Alocamos o botão para fechar a aplicação botao_girar_antihorario = al_load_bitmap("girar_anti.bmp"); if (!botao_girar_antihorario) { fprintf(stderr, "Falha ao criar botão de girar a imagem 90º sentido anti-horario.\n"); al_destroy_bitmap(botao_carregar); al_destroy_bitmap(botao_gravar); al_destroy_bitmap(botao_girar_horario); al_destroy_display(janela); return -1; } /*cria uma janela 640x480*/ janela = al_create_display(640, 50); /*registra os eventos*/ al_register_event_source(filaEvento, al_get_display_event_source(janela)); al_register_event_source(filaEvento, al_get_mouse_event_source()); al_register_event_source(filaEvento, al_get_keyboard_event_source()); /*preenche a janela com a cor branca*/ al_clear_to_color(al_map_rgb(255, 255, 255)); /*atualiza tela*/ al_flip_display(); /*fluxo principal da janela*/ while(fechaJanela == false){ /*pega evento da fila*/ al_wait_for_event(filaEvento, &evento); switch (evento.type) { /*fecha a janela (termina aplicacao)*/ case ALLEGRO_EVENT_DISPLAY_CLOSE: fechaJanela = true; break; /*carrega imagem em mostra na tela*/ case ALLEGRO_EVENT_MOUSE_BUTTON_UP: if (evento.mouse.x >= 0 && evento.mouse.x <= 70 && evento.mouse.y <= 50 && evento.mouse.y >= 0) { /*caso algum arquivo estiver aberto, limpa dados*/ if(arquivoAberto==true) { desalocaMatriz(data, altura); altura =0; largura =0; maxCor =0; arquivoAberto = false; } if(arquivoAberto==false) { /*carrega imagem na matriz*/ if(carregaImagem (janela, &altura,&largura, &maxCor, tipo, &data)==-1) { printf("Erro ao desenhar imagem!\n"); break; } /*sinaliza como arquivo aberto*/ arquivoAberto = true; /*desenha a imagem na janela*/ desenha(janela, data, altura, largura); } } if (evento.mouse.x >= 71 && evento.mouse.x <= 140 && evento.mouse.y <= 50 && evento.mouse.y >= 0 && arquivoAberto== true){ if(arquivoAberto == true) { if(gravaImagem(janela, tipo, altura, largura, maxCor, data)==-1) { printf("Erro ao salvar imagem!\n"); break; } } else { printf("Nenhum arquivo aberto!\n"); } } if (evento.mouse.x >= 141 && evento.mouse.x <= 210 && evento.mouse.y <= 50 && evento.mouse.y >= 0 && arquivoAberto== true) { data = rotacao(data, &altura, &largura, 'D'); desenha(janela, data, altura, largura); } if (evento.mouse.x >= 211 && evento.mouse.x <= 280 && evento.mouse.y <= 50 && evento.mouse.y >= 0 && arquivoAberto== true){ data = rotacao(data, &altura, &largura, 'E'); desenha(janela, data, altura, largura); } break; case ALLEGRO_EVENT_KEY_DOWN: switch(evento.keyboard.keycode) { case ALLEGRO_KEY_ENTER: if(arquivoAberto == true) { if(gravaImagem(janela, tipo, altura, largura, maxCor, data)==-1) { printf("Erro ao salvar imagem!\n"); break; } } else { printf("Nenhum arquivo aberto!\n"); } break; case ALLEGRO_KEY_SPACE: data = rotacao(data, &altura, &largura, 'D'); desenha(janela, data, altura, largura); break; } default: break; } al_set_target_bitmap(botao_gravar); al_set_target_bitmap(botao_carregar); al_set_target_bitmap(botao_girar_horario); al_set_target_bitmap(botao_girar_antihorario); al_set_target_bitmap(al_get_backbuffer(janela)); al_draw_bitmap(botao_carregar, 0,0, 0); al_draw_bitmap(botao_gravar, 71,0, 0); al_draw_bitmap(botao_girar_horario, 141,0, 0); al_draw_bitmap(botao_girar_antihorario, 211,0, 0); /*atualiza tela*/ al_flip_display(); } /*limpeza*/ if(data!=NULL && arquivoAberto == true){ desalocaMatriz(data, altura); } al_destroy_event_queue(filaEvento); al_uninstall_mouse(); al_uninstall_keyboard(); al_destroy_bitmap(botao_carregar); al_destroy_bitmap(botao_gravar); al_destroy_bitmap(botao_girar_horario); al_destroy_bitmap(botao_girar_antihorario); al_destroy_display(janela); return 0; }
int main(void) { int X_ROOMS=13; int Y_ROOMS=16; int X_ROOM_SIZE=256; int Y_ROOM_SIZE=128; int SCALE_FACTOR=4; int X_TILE_SIZE=8; int Y_TILE_SIZE=8; int LAST_OBJECT=0; int actid=0; int error=0; ALLEGRO_CONFIG *cfg; ALLEGRO_BITMAP *bmp,*virt,*tmp=NULL; ALLEGRO_DISPLAY *display; ALLEGRO_KEYBOARD_STATE key; ALLEGRO_FONT *font; signed int xcursor=0; signed int ycursor=0; signed char x=0; signed char y=0; signed char finex=0; signed char finey=0; char finish=0; ALLEGRO_COLOR black,white,red,color; int scale_cursor_x=0; int scale_cursor_y=0; int i=0; int a=0; unsigned char r,g,b=0; char pngfilename[20]; char *tmpbuf; char buf[5]; char buf2[5]; /* Iniciar el rollo */ tmpbuf=(char *)malloc(sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); al_init(); al_init_image_addon(); al_init_primitives_addon(); al_init_font_addon(); al_init_ttf_addon(); cfg=al_load_config_file("sacagraf.cfg"); if (cfg==NULL) { cfg=al_create_config(); al_add_config_section(cfg,"Ajustes"); al_add_config_section(cfg,"Objetos"); al_set_config_value(cfg,"Ajustes","Habitaciones en horizontal","13"); al_set_config_value(cfg,"Ajustes","Habitaciones en vertical","16"); al_set_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels","256"); al_set_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels","128"); al_set_config_value(cfg,"Ajustes","Ancho minimo del caracter original","8"); al_set_config_value(cfg,"Ajustes","Alto minimo del caracter original","8"); al_set_config_value(cfg,"Ajustes","Factor de escalado","4"); al_set_config_value(cfg,"Objetos","Ultimo","0"); al_save_config_file("sacagraf.cfg",cfg); } X_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en horizontal")); Y_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en vertical")); X_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels")); Y_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels")); SCALE_FACTOR=atoi(al_get_config_value(cfg,"Ajustes","Factor de escalado")); X_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto minimo del caracter original")); Y_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho minimo del caracter original")); LAST_OBJECT=atoi(al_get_config_value(cfg,"Objetos","Ultimo")); actid=LAST_OBJECT; al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED); display=al_create_display(X_ROOM_SIZE*SCALE_FACTOR,192*SCALE_FACTOR); bmp=al_load_bitmap("map.png"); virt=al_create_bitmap(X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR); font=al_load_ttf_font("proggy.ttf",6*SCALE_FACTOR,0); al_install_keyboard(); black=al_map_rgb(0,0,0); white=al_map_rgba_f(1,1,1,1); red=al_map_rgba_f(1,0,0,0.7); /* Que empiece la fiesta */ while(!finish) { al_get_keyboard_state(&key); if (al_key_down(&key,ALLEGRO_KEY_ESCAPE)) { finish=1; } if (al_key_down(&key,ALLEGRO_KEY_LCTRL)) { finex=0; finey=0; if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { x++; if (x==X_ROOMS) x=X_ROOMS-1; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { x--; if (x<0) x=0; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { y--; if (y<0) y=0; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { y++; if (y>Y_ROOMS-1) y=Y_ROOMS-1; } } else if (al_key_down(&key,ALLEGRO_KEY_LSHIFT)) { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { finex++; if (finex>X_TILE_SIZE) finex=X_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { finex--; if (finex<-X_TILE_SIZE) finex=-X_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { finey--; if (finey<-Y_TILE_SIZE) finey=-Y_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { finey++; if (finey>Y_TILE_SIZE) finey=Y_TILE_SIZE; } } else if (al_key_down(&key,ALLEGRO_KEY_ALT)) { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { scale_cursor_x++; //if (finex>8) finex=8; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { scale_cursor_x--; //if (finex<0) finex=0; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { scale_cursor_y--; //if (finey<0) finey=0; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { scale_cursor_y++; //if (finey>8) finey=8; } } else { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { xcursor+=X_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { xcursor-=X_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { ycursor-=Y_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { ycursor+=Y_TILE_SIZE*SCALE_FACTOR; } } al_clear_to_color(black); al_set_target_bitmap(virt); //al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,white); al_draw_bitmap_region(bmp,0+(x*X_ROOM_SIZE)+finex,0+(y*Y_ROOM_SIZE)+finey,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,0); al_set_target_bitmap(al_get_backbuffer(display)); al_draw_scaled_bitmap(virt,0,0,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR,0); al_draw_line(0,512,1024,512,white,0); al_draw_textf(font,al_map_rgba(200,200,200,200),0,520,0,"mapa x: %d mapa y: %d habitacion nº: %d ajuste fino x: %d ajuste fijo y: %d",x,y,x+(y*13),finex,finey); if (error) { al_draw_textf(font,al_map_rgba(200,200,200,200),0,540,0,"Patron repetido"); al_flip_display(); al_rest(1); error=0; } if (al_key_down(&key,ALLEGRO_KEY_ENTER)) { tmp=al_create_bitmap((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x),(Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)); al_set_target_bitmap(tmp); al_draw_bitmap_region(al_get_backbuffer(display),xcursor,ycursor,(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)+(X_TILE_SIZE*SCALE_FACTOR),(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)+(Y_TILE_SIZE*SCALE_FACTOR),0,0,0); memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); memset(buf,0,5); for (i=0;i<(Y_TILE_SIZE*scale_cursor_y*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR);i+=SCALE_FACTOR) { for (a=0;a<(X_TILE_SIZE*scale_cursor_x*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR);a+=SCALE_FACTOR) { color=al_get_pixel(tmp,a,i); al_unmap_rgb(color,&r,&g,&b); if (!r && !g && !b) { strcat(tmpbuf,"0"); } else { strcat(tmpbuf,"1"); } } } /* Ya está la secuencia del gráfico en tmpbuf, examinamos todas las secuencias anteriores */ error=0; for (i=0;i<actid;i++) { memset(buf2,0,5); sprintf(buf2,"%d",i); if (!strcmp(al_get_config_value(cfg,"Objetos",buf2),tmpbuf)) { error=i; } } /* Si no hay secuencias repetidas lo grabamos */ if (!error) { sprintf(buf,"%d",actid); al_set_config_value(cfg,"Objetos",buf,tmpbuf); memset(pngfilename,0,20); sprintf(pngfilename,"dec%d.png",actid); al_save_bitmap(pngfilename,tmp); actid++; } al_destroy_bitmap(tmp); } al_set_target_bitmap(al_get_backbuffer(display)); //al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,red); al_draw_filled_rectangle(xcursor,ycursor,xcursor+((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)),ycursor+((Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)),red); al_flip_display(); al_rest(0.1); } memset(buf,0,5); sprintf(buf,"%d",actid); al_set_config_value(cfg,"Objetos","Ultimo",buf); al_save_config_file("sacagraf.cfg",cfg); al_destroy_font(font); al_uninstall_keyboard(); al_destroy_bitmap(bmp); al_destroy_bitmap(virt); al_destroy_display(display); al_destroy_config(cfg); al_shutdown_ttf_addon(); al_shutdown_font_addon(); al_shutdown_image_addon(); al_shutdown_primitives_addon(); free(tmpbuf); return 0; }