user2672904
user2672904

Reputation: 61

Functions of Allegro 4 in Allegro 5

I have a code written in Allegro 4 and am converting it to Allegro 5, but I'm having serious problems with functions that no longer exist in allegro 5, one of them is "blit"

BITMAP *bTile; // Bitmap do tile;
BITMAP *bMapa; // Bitmap do mapa;
BITMAP *bTexturas[20]; // Vetor de bitmap das texturas;
BITMAP *bChar; // Bitmap do personagem;
BITMAP *bMario[3];
// ##########################################################

int main()
{
    int vResolucao_x = 640;
    int vResolucao_y = 480;

    init(vResolucao_x, vResolucao_y);

    BITMAP *buffer = create_bitmap(vResolucao_x, vResolucao_y);

    bTile = load_bitmap("Tiles/tile.bmp", NULL);
    bChar = load_bitmap("Tiles/mario.bmp", NULL);
    bMapa = create_bitmap(vResolucao_x, vResolucao_y);

// ############# - Carrega imagens do mario - ############
    bMario[0] = create_bitmap(vTile,vTile);
    bMario[1] = create_bitmap(vTile,vTile);
    bMario[2] = create_bitmap(vTile,vTile);
    blit(bChar, bMario[0],  0, 0, 0, 0, vTile, vTile);
    blit(bChar, bMario[1],  33, 0, 0, 0, vTile, vTile);
    blit(bChar, bMario[2],  66, 0, 0, 0, vTile, vTile);
// #######################################################

    install_int(fGravidade,5);

    fCarrega_Sprites_Mapa();
    fCarrega_Mapa();
    fMostra_Mapa();

    draw_sprite(screen, bMapa, 0, 0 );

    while (!key[KEY_ESC]) {

Virtually nothing of this my old code works with Allegro 5, so I'm doing the conversion as I can learn, but this blit function, can not find its like in allegro 5, another function that I can not find your simulate is: install_int (...)

Upvotes: 3

Views: 1862

Answers (1)

Matthew
Matthew

Reputation: 48294

Allegro 5 is essentially a completely new library. Here's a line-by-line translation, as best as can be done. Note that Allegro 5 uses a fundamentally different concept (event loop) and you should really take the time to learn how that works before diving into trying to convert your code.

ALLEGRO_BITMAP *bMario[3];
// ##########################################################

int main()
{
    int vResolucao_x = 640;
    int vResolucao_y = 480;

    init(vResolucao_x, vResolucao_y);

    ALLEGRO_BITMAP *buffer = al_create_bitmap(vResolucao_x, vResolucao_y);

    bTile = al_load_bitmap("Tiles/tile.bmp");
    bChar = al_load_bitmap("Tiles/mario.bmp");
    bMapa = al_create_bitmap(vResolucao_x, vResolucao_y);

// ############# - Carrega imagens do mario - ############
    bMario[0] = al_create_bitmap(vTile,vTile);
    bMario[1] = al_create_bitmap(vTile,vTile);
    bMario[2] = al_create_bitmap(vTile,vTile);

    al_set_target_bitmap(bMario[0]);
    al_draw_bitmap(bchar, 0, 0, 0);

    al_set_target_bitmap(bMario[1]);
    al_draw_bitmap(bchar, 33, 0, 0);

    al_set_target_bitmap(bMario[2]);
    al_draw_bitmap(bchar, 66, 0, 0);

    al_set_target_backbuffer(display);
// #######################################################

    fGravidade = al_create_timer(5 / 1000.0); // ALLEGRO_TIMER*

    ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
    al_register_event_source(queue, al_get_timer_event_source(gfGravidade));
    al_register_event_source(queue, al_get_keyboard_event_source());

    fCarrega_Sprites_Mapa();
    fCarrega_Mapa();
    fMostra_Mapa();

    al_draw_bitmap(bMapa, 0, 0, 0);
    al_flip_display();

    while (true) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);

      if (event.type == ALLEGRO_EVENT_TIMER) {
        // fGravidade ticked
      }
      else if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
        if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
          break;
        }
      }
    }

Upvotes: 3

Related Questions