void ApagaLocalidade(DIST *distrito)
{
	LOCAL *aux, *ante = NULL;
	int dist, conta = 0;
	char nomelocal[SSIZE];
	printf("Insira a localidade a apagar:");
	fgets(nomelocal,SSIZE,stdin);
	nomelocal[strlen(nomelocal)-1] = '\0';
	for(dist = 0;dist < NDIST;dist++)
	{
		aux = distrito[dist].local;
		ante = distrito[dist].local;
		while(aux != NULL)
		{
			if(strcmp(aux->localidade,nomelocal) == 0)
			{
				allegro_init();
				allegro_message("Localidade %s apagada do distrito %s.",aux->localidade,distrito[dist].nomedist);
				allegro_exit();
				distrito[dist].local = ApagaProx(distrito[dist].local,ante,aux);
				conta++;
			}
			ante = aux;
			aux = aux->prox;
		}
	}
	if(conta == 0)
	{
		allegro_init();
		allegro_message("Não foram encontradas localidades com o nome \"%s\".",nomelocal);
		allegro_exit();
	}
}
void MostraLocals(DIST *distrito)
{
	LOCAL *aux;
	int dist;
	char nomedist[SSIZE];
	printf("Insira o distrito:");
	fgets(nomedist,SSIZE,stdin);
	nomedist[strlen(nomedist)-1] = '\0';
	for(dist = 0;dist < NDIST;dist++)			/*Corre os distritos*/
		if(strcmp(distrito[dist].nomedist,nomedist) == 0)	/*Pára no distrito com o nome igual ao inserido.("dist" guarda o numero do distrito)*/
			break;
	if(strcmp(distrito[dist].nomedist,nomedist) != 0)       /*se sair do ciclo anterior sem encontrar o distrito*/
	{
		allegro_init();
		allegro_message("Não foram encontradas distrito com o nome \"%s\".",nomedist);
		allegro_exit();
		return;
	}
	if(distrito[dist].local == NULL)
	{
		allegro_init();
		allegro_message("Distrito vazio.");
		allegro_exit();
		return;
	}
	aux = distrito[dist].local;
	while(aux != NULL)			/*corre todas as localidades do distrito*/
	{
		MostraInfo(aux->localidade,aux->latitude,aux->longitude);
		aux = aux->prox;
	}
	printf("Enter para continuar...");
	while(getchar() != '\n');
}
Exemple #3
0
void draw_matrix(matrix_t *m, char *name, char *dirname){
    	
	allegro_init();
    	set_color_depth( 16 );
	BITMAP * obrazek1 = NULL;
	obrazek1 = create_bitmap( m->cn*10, m->rn*10 );
	if( !obrazek1 )
	{
	    set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
	    allegro_message( "nie mogę załadować obrazka 1 !" );
	    allegro_exit();
	}
	clear_to_color( obrazek1, makecol( 255, 255, 255 ) );
	int i,j;
	for (i = 0; i < m->rn; i++) 
    		for (j = 0; j < m->cn ; j++)
				if(m->e[i*m->cn+j]==1)
					rectfill( obrazek1, j*10, i*10,  (j*10)+10,(i*10)+10,makecol( 0, 0, 0 ) );
	
	chdir(dirname);
	save_bitmap(name, obrazek1, default_palette);	
	chdir(PARENT_DIRECTORY);	
	
	destroy_bitmap( obrazek1 );
	allegro_exit();

}
void MenuMapas(DIST *distrito, CTD *contorno)
{
	char esc, nomelocal[SSIZE];
	float zoom = 1;
	LOCAL *locref = NULL;
	while(1){
		system("clear");
		printf("0 – Regressar ao menu anterior\n");
		printf("1 – Seleccao da localidade de referência\n");
		printf("2 – Seleccao da escala\n");
		printf("3 – Visualizar as localidades em redor da referencia\n");
		printf("4 – Apresentar uma rota\n");
		printf("	Opção: ");
		esc = getchar();			/*le o primeiro caracter inserido*/
		if(getchar() != '\n'){
			while(getchar() != '\n');		/*descarta todos os outros*/
			esc = 'x';
		}
		switch(esc)
		{
			case '0':
				return;
			case '1':
				printf("Insira a localidade:");
				fgets(nomelocal,SSIZE,stdin);
				nomelocal[strlen(nomelocal)-1] = '\0';
				locref = RetLocal(distrito,nomelocal);
				break;	
			case '2':
				printf("Insira a escala (pixeis/km):");
				scanf("%f",&zoom);
				getchar();
				if(zoom < 0){
					zoom = 1;
					allegro_init();
					allegro_message("O zoom deve ser um valor superior a zero.");
					allegro_exit();
				}
				break;
			case '3':
				if(locref == NULL){		/*verifica se esta definida uma localidade de referencia*/
					allegro_init();
					allegro_message("Deve defenir primeiro uma localidade de referencia.");
					allegro_exit();
				}
				else
					VerMapa(distrito,contorno,zoom,locref);
				break;
			case '4':		
				DesenhaRota(distrito,contorno);
				break;
		}
	}
}
void CriaLocalidade(DIST *distrito)
{
	char ndist[SSIZE], local[SSIZE];
	float latitude, longitude;
	int dist;
	LOCAL *aux;
	printf("Insira o distrito:");
	fgets(ndist,SSIZE,stdin);
	ndist[strlen(ndist)-1] = '\0';
	for(dist = 0;dist < NDIST;dist++)			/*procura pelo nome do distrito*/
		if(strcmp(distrito[dist].nomedist,ndist) == 0)
			break;
	if(strcmp(distrito[dist].nomedist,ndist) != 0)
	{
		allegro_init();
		allegro_message("Distrito não encontrado");
		allegro_exit();
		return;
	}
	printf("Insira o nome da localidade a criar:");
	fgets(local,SSIZE,stdin);
	local[strlen(local)-1] = '\0';
		for(dist = 0;dist < NDIST;dist++)
	{
		aux = distrito[dist].local;
		while(aux != NULL)
		{
			if(strcmp(aux->localidade,local) == 0)
			{
				allegro_init();
				allegro_message("Localidade ja existente!!");
				allegro_exit();
				return;
			}
			aux = aux->prox;
		}
	}
	printf("Latitude:");
	scanf("%f",&latitude);
	printf("Longitude:");
	scanf("%f",&longitude);
	getchar();
	if(latitude > 90 || latitude < -90 || longitude > 180 || longitude < -180)
	{
		allegro_init();
		allegro_message("Coordenadas invalidas!");
		allegro_exit();
		return;
	}
	distrito[dist].local = InsereLocalidade(distrito[dist].local,local,latitude,longitude);		/*insere no fim da lista distrito[dist].local*/
}
Exemple #6
0
int main(int argc, char *argv[]) { 
  allegro_init();

  if (argc < 2) {
    allegro_message("Usage: %s files ...\n", argv[0]);
    return 1;
  }

  install_timer();
  install_keyboard();

  if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) < 0) {
    allegro_message("Error setting video mode.\n");
    return 1;
  }
  clear_to_color(screen, makecol(255, 255, 255));

  /* to achieve the max possible volume */
  set_volume_per_voice(0);

  if (install_sound(DIGI_AUTODETECT, MIDI_NONE, 0) < 0) {
    set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
    allegro_message("Error installing sound.\n");
    return 1;
  }

  do_example(argc-1, argv+1);

  allegro_exit();

  return 0;
}
Exemple #7
0
int main(void)
{
 allegro_init();
 install_timer();
 install_keyboard();

 rgb_map = malloc(sizeof(RGB_MAP));
 create_rgb_table(rgb_map, desktop_palette, NULL);

 set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0);

 buffer = create_bitmap(SCREEN_W, SCREEN_H);
 set_projection_viewport(0, 0, SCREEN_W, SCREEN_H);

 init_shape();

 while (!key[KEY_ESC]) {
   move_shape();
   translate_shape();
   vsync();
   draw();
 }

 destroy_bitmap(buffer);
 free(rgb_map);
 allegro_exit();
 return 0;
}
Exemple #8
0
void OSD::Exit (bool fReInit_/*=false*/)
{
    remove_int(TimerCallback);

    if (!fReInit_)
        allegro_exit();
}
Exemple #9
0
int main()
{
    SetupAll();
    SetupBalls();
    DoTimers();
    LoadBitmaps();
    DoBlock();
    while (!key[KEY_ESC] && GoGame == 1)
    {
        CheckDead();
        CheckBlock();
        MoveBall();
        if (BallsToDrop > 0)
            DropBalls();
        if (Lives <= 0)
            GoGame = 0;
        DrawBack();
        CheckExplode();
        DrawBalls();
        MoveMouse();
        MoveStoneBlock();
        WaitTimer();
        flip();
    }
    EndOfGame();
    allegro_exit(); //Clean up allegro
    return 0;
}
void MusicDriver_Allegro::Stop()
{
    if (_midi != NULL) destroy_midi(_midi);
    _midi = NULL;

    if (--_allegro_instance_count == 0) allegro_exit();
}
Exemple #11
0
int main ()
{
    // initialize Allegro
    if (allegro_init () < 0)
    {
        allegro_message ("Error: Could not initialize Allegro");
        return -1;
    }
    // initialize gfx mode
    if (set_gfx_mode (GFX_AUTODETECT, 320, 200, 0, 0) < 0)
    {
        allegro_message ("Error: Could not set graphics mode");
        return -1;
    }
    // initialize keyboard
    install_keyboard ();
    clear_keybuf ();

    // call the example function
    test_mode_7 ();

    // exit Allegro
    allegro_exit ();

    return 0;

} END_OF_MAIN ();
Exemple #12
0
  ~Alleg4System() {
    clock_exit();
    remove_timer();
    allegro_exit();

    g_instance = nullptr;
  }
Exemple #13
0
station station_init(float _a)
{
	station s;
	s.h = rskala() * 230.0 * 2.0;
	s.a = _a;
	s.hpmax = get_config_int("stacje_kosmiczne", "wytrzymalosc", 5);
	s.hp = s.hpmax;
	s.zywa = 1;

	s.budynek = load_bitmap("media/stacja.bmp", NULL);

	int d = diagonal(s.budynek->w, s.budynek->h);
	s.budynek_rot = create_bitmap(d, d);

	s.szkoda = load_bitmap("media/uszkodzenie.bmp", NULL);
	if (!s.szkoda)
	{
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Nie moge zaladowac grafiki ( uszkodzenie )");
		allegro_exit();
	}

	s.uszkodzenia = (int*) malloc(sizeof(int*) * (s.hp - 1));
	for (int i = 0; i < (s.hp - 1); ++i)
	{
		s.uszkodzenia[i] = (int) malloc(sizeof(int) * 2);
		s.uszkodzenia[i][0] = (int) ((s.budynek->w - s.szkoda->w)
				* (((float) rand() / (float) RAND_MAX) - 0.5));
		s.uszkodzenia[i][1] = (int) ((s.budynek->h - s.szkoda->h)
				* (((float) rand() / (float) RAND_MAX) - 0.5));
	}

	return s;
}
Exemple #14
0
int
main()
{
	int i, wid, col, offset = 10, w = 800, h = 600;

	allegro_init();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, w, h, 0, 0);
	install_timer();
	install_keyboard();

	for (col = 0, i = 0, wid = 0; i < 256; i++, col++)
	{
		if ((offset * col) >= screen->h)
		{
			wid += 150;
			col = 0;
		}

		textprintf_ex(screen, font, wid, offset * col, i, -1,
			"This is color %d.", i);
	}

	readkey();
	allegro_exit();
	return 0;
}
Exemple #15
0
//Main function
int main(){
	//Allegro init
	allegro_init();
	set_color_depth(32); 
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1280, 960, 0, 0);
	set_window_title("Chuckie Egg");
	srand(time(NULL));

	//Installations
	install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,0);
	install_timer();
	install_keyboard();
	install_mouse();

	//Close button
    LOCK_FUNCTION(close_button_handler);
    set_close_button_callback(close_button_handler);

	//Show menu
	ce_menu *menu = new ce_menu();
	menu->setupMenu();
	menu->showMenu();
	delete menu;

	allegro_exit();

	return 1;
}
Exemple #16
0
void	init(int policy, int prot)
{
	allegro_init();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, XMAX, YMAX, 0, 0);
	clear_to_color(screen, BGC);
	install_keyboard();
	print_grid(policy, prot);
	
	if (prot == PIP) ptask_init(policy, GLOBAL, PRIO_INHERITANCE);
	else if (prot == PCP) ptask_init(policy, GLOBAL, PRIO_CEILING);
	else {
	  allegro_exit();
	  ptask_syserror("pcp.c", "Wrong protocol");
	}

	if (prot == PIP) { 
	  pmux_create_pi(&mxa);
	  pmux_create_pi(&muxA);
	  pmux_create_pi(&muxB);
	}
	else if (prot == PCP) {
	  pmux_create_pc(&mxa, prio[1]);
	  pmux_create_pc(&muxA, prio[1]);
	  pmux_create_pc(&muxB, prio[1]);
	}
}
void VerMapa(DIST *distrito, CTD *contorno,float zoom,LOCAL *localref)
{
	int ret,cod;
	COORD *aux, *coordenadas;
	double oldlatitude, oldlongitude;
	double latitude, longitude;
	allegro_init();
	ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, LARGURA_JANELA, ALTURA_JANELA, 0, 0);
	if (ret != 0)
	{
		allegro_message("Graphic error- Exiting");
		return;
	}
	floodfill(screen,1,1,BGCOL);							/*Pinta a tela (cor do fundo) com a cor defenida em BGCOL*/
	textprintf_ex(screen, font,3,3,TCOL, -1,"Centrado em: \"%s\" Zoom = %.2f px/km",localref->localidade,zoom);
	for(cod = 0 ; cod < NFRON; cod++)		/*Corre todas as listas de contornos*/
	{	
		coordenadas = contorno[cod].coord;
		aux = coordenadas;
		while(aux->prox != NULL)		/*Le a lista do contorno ate ao fim*/
		{
			oldlatitude = transf_lat(aux->latitude,zoom,localref->latitude,SCREEN_H);
			oldlongitude = transf_lon(aux->latitude,aux->longitude,zoom,localref->longitude,SCREEN_W);
			aux = aux->prox;
			latitude = transf_lat(aux->latitude,zoom,localref->latitude,SCREEN_H);
			longitude = transf_lon(aux->latitude,aux->longitude,zoom,localref->longitude, SCREEN_W);
			line(screen,oldlongitude,oldlatitude,longitude,latitude,contorno[cod].cor);
		}
	}
	DesenhaTodasLocal(distrito,localref->latitude,localref->longitude,zoom);
	install_keyboard();	
	readkey();              /*Espera que uma tecla seja clicada*/
	allegro_exit();
}
Exemple #18
0
void allegroexit() {
  allegrostarted=0;
#ifdef ALLEGRO
#ifndef NOGRAPHICS
  allegro_exit();
#endif
#endif
}
Exemple #19
0
int main(void) {

    int ret = 0, nc;
    int c;
    int key = 0;
    int part = PARTITIONED; // PARTITIONED, GLOBAL
    int sched = SCHED_FIFO;

    get_data();
    init();
    ret = select_prot();
    if (ret == -1) {
        allegro_exit();
        return 0;
    }

    print_grid(ret);
    ptask_init(sched, part, ret);
    t_start = ptask_gettime(MILLI);
    set_sem_sezC(ret);

    nc = ptask_getnumcores();
    textprintf_ex(screen, font, 480, 10, 7, BGC, "(NumCores = %d)", nc);

    int gen_id = ptask_create_prio(gen, 100, 30, NOW);
    if (gen_id < 0) {
        printf("Could not create task gen\n");
        exit(-1);
    }

    while (key != KEY_ESC) {

        if (keypressed()) {
            c = readkey();
            key = c >> 8;
        }
    }

    pmux_destroy(&mx_sezNorm);
    pmux_destroy(&mx_sezA);
    pmux_destroy(&mx_sezB);

    allegro_exit();
    return 0;
}
void TextureUtil::stopGrx() {
  cerr << "Stopping graphics...";
#if EM_USE_SDL
  SDL_Quit();
#endif
#if EM_USE_ALLEGRO
  allegro_exit();
#endif
  cerr << "ok." << endl;
}
Exemple #21
0
void textgfx_end()
{
	if (!virt_screen)
		return;
	destroy_bitmap(virt_screen);
	virt_screen = NULL;
	if (font8x16 != font)
		destroy_font(font8x16);
	allegro_exit();
}
Exemple #22
0
void out_of_mem(char const *msg)
{
   allegro_exit();

   if (msg)
      fprintf(stderr,"Out of memory: %s",msg);
   else
      fprintf(stderr,"Out of memory");
   exit(1);
}
Exemple #23
0
static int deinit_vidmode (void)
{
	set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);
	destroy_bitmap (screen_buffer);
	remove_int (tick_increment);

	allegro_exit();

	return err_OK;
}
void SoundDriver_Allegro::Stop()
{
	if (_stream != NULL) {
		stop_audio_stream(_stream);
		_stream = NULL;
	}
	remove_sound();

	if (--_allegro_instance_count == 0) allegro_exit();
}
void ProcuraLocal(DIST *distrito)
{
	LOCAL *aux;
	int dist,conta = 0;
	char nomelocal[2*SSIZE];
	printf("Insira a localidade:");
	fgets(nomelocal,2*SSIZE,stdin);
	if(nomelocal[strlen(nomelocal)-1] == '\n')			/*Retira o \n no fim da str se este existir*/
		nomelocal[strlen(nomelocal)-1] = '\0';
	else						/*se nao existir quer dizer que o fgets nao leu tudo o que foi inserido na consola*/
	{
		allegro_init();
		allegro_message("ERRO: tamanho de string excedido.");
		allegro_exit();
		return;
	}
	FormatStr(nomelocal);						/*retira os espaços desnecessarios*/
	for(dist = 0;dist < NDIST;dist++)
	{
		aux = distrito[dist].local;
		while(aux != NULL)
		{
			if(strcmp(aux->localidade,nomelocal) == 0)
			{
				printf("\nDistrito: %s\n",distrito[dist].nomedist);
				MostraInfo(aux->localidade,aux->latitude,aux->longitude);
				conta++;
			}
			aux = aux->prox;
		}
	}
	if(conta == 0)
	{
		allegro_init();
		allegro_message("Não foram encontradas localidades com o nome \"%s\".",nomelocal);
		allegro_exit();
	}
	else
	{
		printf("Enter para continuar...");
		while(getchar() != '\n');
	}
}
static int destroyAllegroComponents(rtSimulationThread_t *p_thread)
{
	int ret;
	ret = destroySimulationDrawer();
	if(ret != 0)
		PRINT_ERR("Failed to destroy SimulationDrawer (%d).\n", ret);
	
	allegro_exit();
	return ret;
}
Exemple #27
0
int main()
{
    int koseler[8];
    int kirmizi, yesil, mavi, renk;

    // Allegro'yu ilklendir
    allegro_init();

    // klavyeyi ilklendir
    install_keyboard();

    // rastgele sayı üretecini ilklendir
    srand(time(NULL));

    // ekran kipini ayarla
    int donen = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
    if (donen != 0) {
        allegro_message(allegro_error);
        return;
    }

    // ekran çözünürlüğünü göster
    textprintf(screen, font, 0, 0, 15,
               "Cokgen cizme programı - %dx%d - Cikmak icin ESC tusuna basiniz",
               SCREEN_W, SCREEN_H);

    // çıkış tusuna basılana kadar devam et
    while (!key[KEY_ESC]) {

        // rastgele bir nokta seç
        koseler[0] = 10 + rand() / (RAND_MAX / (SCREEN_W - 20));
        koseler[1] = 10 + rand() / (RAND_MAX / (SCREEN_H - 20));
        koseler[2] = koseler[0] + rand() / (RAND_MAX / 30) + 50;
        koseler[3] = koseler[1] + rand() / (RAND_MAX / 30) + 50;
        koseler[4] = koseler[2] + rand() / (RAND_MAX / 30) - 100;
        koseler[5] = koseler[3] + rand() / (RAND_MAX / 30) + 50;
        koseler[6] = koseler[4] + rand() / (RAND_MAX / 30);
        koseler[7] = koseler[5] + rand() / (RAND_MAX / 30) - 100;

        // rastgele bir renk seç
        kirmizi = rand() / (RAND_MAX / 255 + 1);
        yesil   = rand() / (RAND_MAX / 255 + 1);
        mavi    = rand() / (RAND_MAX / 255 + 1);
        renk = makecol(kirmizi, yesil, mavi);

        // çokgen çiz
        polygon(screen, 4, koseler, renk);

        rest(50);

    }

    // programı sonlandır
    allegro_exit();
}
Exemple #28
0
void printerror(char const *format, ...)
{
   va_list arg;
   va_start(arg, format);
   vsprintf(buffer, format, arg);
   va_end(arg);
   
   allegro_exit();
   fprintf(stderr, "ERROR:%s\n",buffer);
   exit(1);
}
Exemple #29
0
int main()
{
  std::srand(std::time(NULL));

  allegro_init();
  install_timer();
  install_keyboard();
//   install_mouse();
  install_joystick(JOY_TYPE_AUTODETECT);

  override_config_file(redir("defnot.ini").c_str());

  gfx_widescreen = get_config_int("Game", "Widescreen", gfx_widescreen);
  gfx_fullscreen = get_config_int("Game", "Fullscreen", gfx_fullscreen);

  if (!setup_gfx() != 0) {
    allegro_message("Unable to setup the graphics mode\n");
    return 1;
  }

//   if (gfx_capabilities & GFX_HW_CURSOR) {
//     enable_hardware_cursor();
//     select_mouse_cursor(MOUSE_CURSOR_ARROW);
//     show_mouse(screen);
//   }

  if (!load_media()) {
    allegro_message("Unable to load data files to play the game\n");
    return 1;
  }

  // install the timer to control the game speed
  LOCK_VARIABLE(beats);
  LOCK_FUNCTION(timer_control);

  beats = 0;
  install_int_ex(timer_control, BPS_TO_TIMER(BPS));

  // insert the callback routine for the close-button
  LOCK_VARIABLE(continuing);
  LOCK_FUNCTION(close_button);

  set_close_button_callback(close_button);

  // play the game
  game_loop();

  set_config_int("Game", "Widescreen", gfx_widescreen);
  set_config_int("Game", "Fullscreen", gfx_fullscreen);

  remove_int(timer_control);
  allegro_exit();
  return 0;
}
Exemple #30
0
void GameExit(void)
{

	remove_keyboard();
	remove_timer();
	remove_mouse();

	allegro_exit();

 	return;
}