Пример #1
0
bool Graphic::init()
{
    set_color_depth(m_depth); // profondeur des couleurs 8, 16, 24 ou 32
    set_uformat(U_ASCII); // pour gérer les accents

    allegro_init();

    if (install_mouse() == -1)
    {
        std::cerr << ("Failed to install mouse") << std::endl;
        return false;
    }
    if (install_keyboard() != 0)
    {
        std::cerr << ("Failed to install keyboard") << std::endl;
        return false;
    }
    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, m_resX, m_resY, 0, 0) != 0)
    {
        std::cerr << ("Failed to enter in graphic mode") << std::endl;
        return false;
    }

    set_keyboard_rate(500, 100);

    show_mouse(screen);

    return this->_imageLoadSprites();
}
Пример #2
0
int main(int argc, char **argv)
{
	if (allegro_init() != 0)
		return 1;

	install_keyboard();

	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 200, 0, 0) != 0) {
		if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
			set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
			allegro_message("Unable to set any graphics mode:\n"
					"%s\n", allegro_error);
			return 1;
		}
	}

	black = makecol(0,0,0);
	white = makecol(255,255,255);

	clear_to_color(screen, black);
	test_unicode();
	readkey();

	set_uformat(U_ASCII);

	clear_to_color(screen, black);
	test_cp437();
	readkey();

	clear_to_color(screen, black);
	test_ascii();
	readkey();

	return 0;
}
Пример #3
0
  Alleg4System()
  {
    if (allegro_init() < 0)
      throw base::Exception("Cannot initialize Allegro library: %s", allegro_error);

    set_uformat(U_UTF8);
#if MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION) >= MAKE_VERSION(4, 4, 0)
    _al_detect_filename_encoding();
#endif
    install_timer();

    // Register PNG as a supported bitmap type
    register_bitmap_file_type("png", load_png, save_png);

    // Init event sources
    clock_init();
    display_events_init();
#ifdef USE_KEY_POLLER
    key_poller_init();
#endif
#ifdef USE_MOUSE_POLLER
    mouse_poller_init();
#endif

    g_instance = this;
  }
Пример #4
0
  Alleg4System()
    : m_font(font, Alleg4Font::None)       // Default Allegro font
  {
    allegro_init();
    set_uformat(U_UTF8);
    _al_detect_filename_encoding();
    install_timer();

    // Register PNG as a supported bitmap type
    register_bitmap_file_type("png", load_png, save_png);
  }
Пример #5
0
// Procédure d'ouverture du mode graphique Allegro
void initAllegro()
{
    set_uformat(U_ASCII);
    allegro_init();
    // Souris allegro
    install_mouse();
    install_keyboard();
    install_timer();
    set_color_depth(32);
    if (set_gfx_mode(GFX_AUTODETECT_WINDOWED,1000,550,0,0)!=0)
    {
        set_color_depth(24);
        if (set_gfx_mode(GFX_AUTODETECT_WINDOWED,1000,550,0,0)!=0)
        {
            allegro_message("probleme ouverture mode graphique");
            allegro_exit();
            exit(EXIT_FAILURE);
        }
    }
    // Souris allegro
    show_mouse(screen);
    //initialisation du temps de prise de saisie
    set_keyboard_rate(300,100);
}
Пример #6
0
int main(int argc, char *argv[])
{
   int c, w, h;
   char buf[256], buf2[256];
   ANIMATION_TYPE type;

   for (c = 1; c < argc; c++) {
      if (stricmp(argv[c], "-cheat") == 0)
         cheat = TRUE;

      if (stricmp(argv[c], "-jumpstart") == 0)
         jumpstart = TRUE;
   }

   /* The fonts we are using don't contain the full latin1 charset (not to
    * mention Unicode), so in order to display correctly author names in
    * the credits with 8-bit characters, we will convert them down to 7
    * bits with a custom mapping table. Fortunately, Allegro comes with a
    * default custom mapping table which reduces Latin-1 and Extended-A
    * characters to 7 bits. We don't even need to call set_ucodepage()!
    */
   set_uformat(U_ASCII_CP);
   
   srand(time(NULL));
   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();
   install_mouse();

   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
      allegro_message("Error initialising sound\n%s\n", allegro_error);
      install_sound(DIGI_NONE, MIDI_NONE, NULL);
   }

   if (install_joystick(JOY_TYPE_AUTODETECT) != 0) {
      allegro_message("Error initialising joystick\n%s\n", allegro_error);
      install_joystick(JOY_TYPE_NONE);
   }

   if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
         set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
         allegro_message("Unable to set any graphic mode\n%s\n",
                         allegro_error);
         return 1;
      }
   }

   get_executable_name(buf, sizeof(buf));
   replace_filename(buf2, buf, "demo.dat", sizeof(buf2));
   set_color_conversion(COLORCONV_NONE);
   data = load_datafile(buf2);
   if (!data) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s\n", buf2);
      exit(1);
   }

   if (!jumpstart) {
      intro_screen();
   }

   clear_bitmap(screen);
   set_gui_colors();
   set_mouse_sprite(NULL);

   if (!gfx_mode_select(&c, &w, &h))
      exit(1);

   if (pick_animation_type(&type) < 0)
      exit(1);

   init_display(c, w, h, type);

   generate_explosions();

   //stop_sample(data[INTRO_SPL].dat);

   clear_bitmap(screen);

   while (title_screen())
      play_game();

   destroy_display();

   destroy_explosions();

   stop_midi();

   set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);

   end_title();

   unload_datafile(data);

   allegro_exit();

   return 0;
}
Пример #7
0
void inicia_allegro() {
	int profundidade, res;
	allegro_init();
	install_timer();
	install_keyboard();
	clear_keybuf();
	install_mouse();

	set_uformat(U_ASCII); // Habilita acentuação em ALGUMAS FONTES
	/*profundidade = desktop_color_depth();
	if (profundidade == 0) profundidade = 32;
	   set_color_depth(profundidade);*/

	//roda configuracao de um arquivo
	set_config_file("config.txt");

	profundidade = get_config_int("Inicializacao", "colordepth",32);
	int v = GetVersion() & 65535;
    float versao = (v%256) + (v/256)/10.;
    /*if (versao<=5.1) //5.1 = XP, 6.0 = Vista, 6.1 Win7
        profundidade=16;
    else
        profundidade=32;*/

	set_color_depth(profundidade); //padrao é 32 bits, no XP é 16

	volume=get_config_int("Inicializacao", "volume", 128); //usa as config de volume do arquivo
	exibirFPS=get_config_int("Inicializacao", "exibirFps", 0);

	#define GFX_BWINDOWSCREEN_ACCEL AL_ID('B','W','S','A')
	#define GFX_BWINDOWSCREEN        AL_ID('B','W','S',' ')
    AL_VAR(GFX_DRIVER, gfx_beos_bwindowscreen_accel);
    AL_VAR(GFX_DRIVER, gfx_beos_bwindowscreen);

	vSync = get_config_int("Inicializacao", "vsync",0);
	resolucaoX = get_config_int("Inicializacao", "resolucaox",800);
	resolucaoY = get_config_int("Inicializacao", "resolucaoy",600);
    //Fullscreen
    //res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN & GFX_BWINDOWSCREEN_ACCEL, resolucaoX, resolucaoY, 0, 0);
    //Janela
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, resolucaoX, resolucaoY, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}
	if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL))
    {
        allegro_message("Sound Error: %s", allegro_error);
    }

	//inicializa o metodo de atualizacao
	initialize_screen_updating(get_config_int("Inicializacao", "updatemethod", UPDATE_TRIPLE_BUFFER));

    set_window_title("Snake Criado por Arthur Assuncao"); //nome da Janela

    set_display_switch_mode(SWITCH_BACKGROUND); //roda o allegro em segundo plano

    //Botao fechar
    LOCK_FUNCTION(BotaoFechar);
    set_close_button_callback(BotaoFechar);

	//Contador de frames
	// Faz o lock das variaveis usadas pela funcao de timer e da propria funcao
    LOCK_VARIABLE(fps);
    LOCK_VARIABLE(contFrames);
    LOCK_FUNCTION(funcFPS);
	//chama a funcao funcFPS
	install_int_ex(funcFPS,BPS_TO_TIMER(MAXFPS)); //Frames por segundo, 60FPS
	//chama a funcao funcTempo
	LOCK_VARIABLE(contTempo);
    LOCK_FUNCTION(funcTempo);
	install_int(funcTempo, 1000); //Timer "ticks" a cada mil milisegundos, ou seja, 1 segundo

	/* adicione outras iniciacoes aqui */
}
Пример #8
0
int main(int argc, char *argv[])
{
   DATAFILE *data;
   FONT *f;
   BITMAP *buffer;
   int i, j, k, height;
   char buf[256], tmp[256], tmp2[256];
   int counter = 0, drawn = 0;
   int scroll_w, scroll_h;
   int background_color;

   /* set the text encoding format BEFORE initializing the library */
   set_uformat(U_UNICODE);

   /*  past this point, every string that we pass to or retrieve
    *  from any Allegro API call must be in 16-bit Unicode format
    */

   srand(time(NULL));
   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();

   /* load the datafile containing the Unicode font */
   replace_filename(buf, uconvert_ascii(argv[0], tmp), uconvert_ascii(DATAFILE_NAME, tmp2), sizeof(buf));
   data = load_datafile(buf);
   if (!data) {
      allegro_message(uconvert_ascii("Unable to load %s\n", tmp), buf);
      return -1;
   }

   /* set the graphics mode */
   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message(uconvert_ascii("Unable to set any graphic mode\n%s\n", tmp), allegro_error);
	 return 1;
      }
   }

   /* set the window title for windowed modes */
   set_window_title(uconvert_ascii("Unicode example program", tmp));

   /* create a buffer for drawing */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);

   /* get a handle to the Unicode font */
   f = data[0].dat;
   height = text_height(f);

   /* The are for the text messages. If it gets too crowded once we have more
    * languages, this can be increased.
    */
   scroll_w = SCREEN_W * 2;
   scroll_h = SCREEN_H + height;

   /* one of the bright colors in the default palette */
   background_color = 56 + AL_RAND() % 48;

   /* prepare the messages */
   for (i = 0; i < NLANGUAGES; i++) {

      /* the regular Standard C string manipulation functions don't work
       * with 16-bit Unicode, so we use the Allegro Unicode API
       */
      message[i].str = malloc(ustrsize(message[i].data) + ustrsizez(allegro_str));

      if (message[i].prefix_allegro) {
         ustrcpy(message[i].str, allegro_str);
         ustrcat(message[i].str, message[i].data);
      }
      else {
         ustrcpy(message[i].str, message[i].data);
         ustrcat(message[i].str, allegro_str);
      }

      message[i].w = text_length(f, message[i].str);
      message[i].h = text_height(f);

      /* one of the dark colors in the default palette */
      message[i].c = 104 + AL_RAND() % 144;

      message[i].dx *= 1 + AL_RAND() % 4;
      message[i].dy = AL_RAND() % 3 - 1;

      /* find not-overlapped position, try 1000 times */
      for (k = 0; k < 1000; k++) {
         message[i].x = AL_RAND() % scroll_w;
         /* make sure the message is not sliced by a screen edge */
         message[i].y = 10 + AL_RAND() % (SCREEN_H - height - 20);
         for (j = 0; j < i; j++) {
            if (overlap(i, j, 10))
               break;
         }
         if (j == i)
            break;
      }
   }

   install_int_ex(ticker, BPS_TO_TIMER(30));
   /* do the scrolling */
   while (!keypressed()) {
      /* Animation. */
      while (counter <= ticks) {
         for (i = 0; i < NLANGUAGES; i++) {
            message[i].x += message[i].dx;
            if (message[i].x >= scroll_w)
               message[i].x -= scroll_w;
            if (message[i].x < 0)
               message[i].x += scroll_w;
            message[i].y += message[i].dy;
            if (message[i].y >= scroll_h)
               message[i].y -= scroll_h;
            if (message[i].y < 0)
               message[i].y += scroll_h;
         }
         counter++;
      }

      /* Draw current frame. */
      if (drawn < counter) {
         clear_to_color(buffer, background_color);
         for (i = 0; i < NLANGUAGES; i++) {
            char *str = message[i].str;
            int x = message[i].x;
            int y = message[i].y;
            int c = message[i].c;
            /* draw it 4 times to get the wrap-around effect */
            textout_ex(buffer, f, str, x, y, c, -1);
            textout_ex(buffer, f, str, x - scroll_w, y, c, -1);
            textout_ex(buffer, f, str, x, y - scroll_h, c, -1);
            textout_ex(buffer, f, str, x - scroll_w, y - scroll_h, c, -1);
         }
         blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
         drawn = counter;
      }
      else {
         rest(10); /* We are too fast, give time to the OS. */
      }
   }

   destroy_bitmap(buffer);

   unload_datafile(data);

   return 0;
}
Пример #9
0
static void init()
{
   char temp_buf[256];

   is_not_genuine_scan_tool = FALSE;
   
   /* initialize some varaibles with default values */
   strcpy(options_file_name, "scantool.cfg");
   strcpy(data_file_name, "scantool.dat");
   strcpy(code_defs_file_name, "codes.dat");
   
   datafile = NULL;
   comport.status = NOT_OPEN;
   display_mode = 0;

   set_uformat(U_ASCII);
   
   /* initialize hardware */
   write_log("\nInitializing Allegro... ");
   allegro_init();
   write_log("OK");
   
   set_window_title(WINDOW_TITLE);
   
   write_log("\nInstalling Timers... ");
   if (install_timer() != 0)
   {
      write_log("Error!");
      fatal_error("Error installing timers");
   }
   write_log("OK");
   write_log("\nInstalling Keyboard... ");
   install_keyboard();
   write_log("OK");
   write_log("\nInstalling Mouse... ");
   install_mouse();
   write_log("OK");

   /* load options from file, the defaults will be automatically substituted if file does not exist */
   write_log("\nLoading Preferences... ");
   set_config_file(options_file_name);
   /* if config file doesn't exist or is of an incorrect version */
   if (strcmp(get_config_string(NULL, "version", ""), SCANTOOL_VERSION_STR) != 0)
   {
      /* update config file */
      remove(options_file_name);
      set_config_file(options_file_name);
      set_config_string(NULL, "version", SCANTOOL_VERSION_STR);
      load_program_options();  // Load defaults
      save_program_options();
   }
   else
      load_program_options();
   write_log("OK");

   display_mode |= FULLSCREEN_MODE_SUPPORTED;
   
   write_log("\nTrying Windowed Graphics Mode... ");
   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) == 0)
   {
      display_mode |= WINDOWED_MODE_SUPPORTED;
      write_log("OK");
   }
   else
   {
      display_mode &= ~(WINDOWED_MODE_SUPPORTED | WINDOWED_MODE_SET);
      write_log(allegro_error);
   }

   if (!(display_mode & WINDOWED_MODE_SET))
   {
      write_log("\nTrying Full Screen Graphics Mode... ");
      if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) == 0)
      {
         display_mode |= FULLSCREEN_MODE_SUPPORTED;
         write_log("OK");
      }
      else
      {
         display_mode &= ~FULLSCREEN_MODE_SUPPORTED;
         write_log(allegro_error);
      }
   }
   
   if (!(display_mode & (FULLSCREEN_MODE_SUPPORTED | WINDOWED_MODE_SUPPORTED)))
      fatal_error(allegro_error);
   else if ((display_mode & WINDOWED_MODE_SUPPORTED) && !(display_mode & FULLSCREEN_MODE_SUPPORTED))
   {
      set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
      display_mode &= WINDOWED_MODE_SET;
   }
   
   write_log("\nLoading Data File... ");
   packfile_password(PASSWORD);
   datafile = load_datafile(data_file_name);
   packfile_password(NULL);
   if (datafile == NULL)
   {
      sprintf(temp_buf, "Error loading %s!", data_file_name);
      write_log(temp_buf);
      fatal_error(temp_buf);
   }
   write_log("OK");

   set_pallete(datafile[MAIN_PALETTE].dat);
   font = datafile[ARIAL12_FONT].dat;
   gui_fg_color = C_BLACK;  // set the foreground color
   gui_bg_color = C_WHITE;  // set the background color
   gui_mg_color = C_GRAY;   // set the disabled color
   set_mouse_sprite(NULL); // make mouse use current palette

   write_log("\nInitializing Serial Module... ");
   serial_module_init();
   write_log("OK");

   sprintf(temp_buf, "\nOpening COM%i... ", comport.number + 1);
   write_log(temp_buf);
   /* try opening comport (comport.status will be set) */
   open_comport();
   switch (comport.status)
   {
      case READY:
         write_log("OK");
         break;

      case NOT_OPEN:
         write_log("Error!");
         break;
         
      default:
         write_log("Unknown Status");
         break;
   }
}
Пример #10
0
int main()
{
    // Ressources
    unsigned long t_debut, t_fin;
    float dt, waitShoot = 0;
    BITMAP *buffer;
    int fin = 0, v = 200;
    Map *map;
    DepthList *depthList;
    Rect screen_pos, map_pos;
    Actor *joueur;

    // Initialisation
    fprintf(stderr,"Initialisation ...\n");
    timeBeginPeriod(1);
    set_uformat(U_ASCII);
    set_color_depth(32);
    allegro_init();
    install_keyboard();
    install_mouse();
    srand(time(NULL));

    if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0))
        ERREUR("Echec du lancement du mode graphique.");
    buffer = create_bitmap(SCREEN_W, SCREEN_H);
    resman_loadSprites();

    fprintf(stderr,"Chargement des ressources ...\n");
    map = new_map("media/map/test1");
    map_pos.x = map_pos.y = 0;
    map_pos.w = map->w;
    map_pos.h = map->h;
    actList = new_glist();
    root = new_tree(map_pos);
    map_addEntities(map, actList, root);
    depthList = new_dlist();
    screen_pos.w = SCREEN_W;
    screen_pos.h = SCREEN_H;

    // Ajout du joueur
    joueur = actor_addJoueur(actList, root, 500, 500);

    // Intro
    debut();

    // Boucle principale
    fprintf(stderr,"Debut !\n");
    t_debut = timeGetTime();
    while(!fin)
    {
        // Gestion clavier
        if(key[KEY_ESC])
        {
            fin = 1;
        }
        if(key[KEY_W])
        {
            joueur->vit_y = -v;
            joueur->direction_regard = HAUT;
            joueur->etat = ETAT_MARCHE;
        }
        else if(key[KEY_S])
        {
            joueur->vit_y = v;
            joueur->direction_regard = BAS;
            joueur->etat = ETAT_MARCHE;
        }
        else
            joueur->vit_y = 0;
        if(key[KEY_A])
        {
            joueur->vit_x = -v;
            joueur->direction_regard = GAUCHE;
            joueur->etat = ETAT_MARCHE;
        }
        else if(key[KEY_D])
        {
            joueur->vit_x = v;
            joueur->direction_regard = DROITE;
            joueur->etat = ETAT_MARCHE;
        }
        else
            joueur->vit_x = 0;
        if(joueur->vit_x != 0 && joueur->vit_y != 0)
        {
            joueur->vit_x /= sqrt(2);
            joueur->vit_y /= sqrt(2);
        }
        if(!key[KEY_W] && !key[KEY_D] && !key[KEY_S] && !key[KEY_A])
            joueur->etat = ETAT_REPOS;
        if(key[KEY_Q])
        {
            if(waitShoot <= 0)
            {
                waitShoot = .1;
                actor_addTree(actList, root, mouse_x + screen_pos.x, mouse_y + screen_pos.y);
            }
        }
        waitShoot -= dt;
        if(mouse_b&1)
        {
            float vx, vy, v;
            if(waitShoot <= 0)
            {
                waitShoot = .3;
                vx = mouse_x - (joueur->pos_x - screen_pos.x);
                vy = mouse_y - (joueur->pos_y - screen_pos.y);
                v = sqrt(vx*vx + vy*vy);
                vx = vx/v;
                vy = vy/v;
                actor_addMissile(actList, root, joueur->pos_x + vx*joueur->w*1.5, joueur->pos_y + vy*joueur->h*1.5, vx*300, vy*300);
            }
        }
        if(key[KEY_P])
        {
            FILE *fd = fopen("arbres.txt", "w+");
            Actor *act;
            glist_startIter(actList);
            while(!glist_endIter(actList))
            {
                act = glist_getCurrentData(actList);
                if(act->type == ACT_TREE)
                    fprintf(fd, "%d\n%d\n", (int) act->pos_x, (int) act->pos_y);
                glist_iter(actList);
            }
            fclose(fd);
        }


        // Double buffer
        clear_bitmap(buffer);
        render_map(buffer, map, screen_pos.x, screen_pos.y);


        // Mises à jour
        resman_updateSprites(&dt);
        actor_spawnMonster(actList, root);
        actor_ia(actList, joueur);
        // Deplacement
        glist_startIter(actList);
        while(!glist_endIter(actList))
        {
            actor_update(glist_getCurrentData(actList), map_pos, map, dt);
            if( ((Actor*) glist_getCurrentData(actList))->deleting)
            {
                glist_remCell(actList, glist_getCurrentId(actList));
            }
            else
                glist_iter(actList);
        }
        // Cadrage ecran
        screen_pos.x = joueur->pos_x - SCREEN_W/2;
        screen_pos.y = joueur->pos_y - SCREEN_H/2;

        // Collision
        tree_collisionDetection(root);

        // Affichage
        tree_update(root);
        dlist_getActorsFromTree(depthList, root, screen_pos);
        dlist_update(depthList, screen_pos);
        dlist_blit(depthList, buffer, screen_pos);
        draw_cursor(buffer);
        textprintf_centre_ex(buffer, font, SCREEN_W/2, 5, makecol(0, 0, 0), makecol(255, 0, 0), "   Vies restantes : %d   |   Score : %d   ", joueur->vie, score);

        // Rafraichissement écran
        vsync();
        blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

        // Gestion du temps
        t_fin = timeGetTime();
        dt = ((float)t_fin - t_debut)/1000;
        t_debut = t_fin;

        // Test fin de jeu
        if(joueur->deleting)
            fin = 1;
        resman_freeList();
    }
    // Game over
    gameover();

    // Fin
    timeEndPeriod(1);
    delete_map(map);
    del_tree(root);
    del_dlist(depthList);
    del_glist(actList);
    destroy_bitmap(buffer);
    resman_freeSprites();
    allegro_exit();
    return 0;
}