Allegro5 C++ Cannot draw the map

  allegro5, c++

Sorry for my english. I followed this tutorial https://www.youtube.com/watch?v=shTvg2lbjjA to draw a map with rectangle but my problem is it seems to just draw at position (0,0).
Here is my code.

Firstly, i load the map with a text file.

void Carte::loadMap(const char*filename)
{
    std::ifstream openfile(filename);
    if(openfile.fail())
    {
        cout <<"Failed to open this file!" << endl;
    }

    string line;

    getline(openfile, line);
    stringstream lar(line);
    lar >> largeur;
    getline(openfile, line);

    stringstream hau(line);
    hau >> hauteur;
    cout << largeur << endl;
    cout << hauteur << endl;

    char x;
    for(int i = 0;i < largeur; i++){
        for(int j = 0;j<hauteur; j++){
            openfile.get(x);
            mazeChar[i][j] = x;
            mazeInt[j][i] = (int) x;
            cout << mazeInt[j][i] << " ";

        }
        cout << endl;
        openfile.ignore(numeric_limits<streamsize>::max(),'n');

    }
    openfile.close();
}


void Carte::drawMap()
{
    //al_draw_filled_rectangle(10, 10, 20 , 20 , al_map_rgb(0,0,255));

    for(int i = 0;i < largeur; i++)
    {
        for(int j = 0;j<hauteur; j++)
        {
            if(mazeInt[i][j] == 35)
            {
                //cout << i << " " << j << endl;
                cout << mazeInt[1][4] << endl;

                Position p(j,i);
                ajout(Obstacle(p));[enter image description here][1]
                cout << 0 << endl;
                al_draw_rectangle(j,i,j+20,i+20, al_map_rgb(255,0,0), 0.0);
           
            }

            if(mazeInt[i][j] >= 49 && mazeInt[i][j] <= 57)
            {
                int a(mazeInt[i][j] - 48);
                ajout(ObjetRamassable(Position(i,j),a));
                cout << i << " " << j << endl;
                al_draw_rectangle(i,j,i+20,j+20, al_map_rgb(255,0,0), 0.0);
                cout << "1" << endl;
            }

            if(mazeInt[i][j] == 83 || mazeInt[i][j] == 67)
            {
               ajout(Guerrier(Position(i,j)));
               al_draw_rectangle(i,j,i+20,j+20, al_map_rgb(0,255,0), 0.0);

            }

        }

    }
}
int main()
{
    float FPS = 60.0;
    bool done = false;
    if(!al_init())
    {
        al_show_native_message_box(NULL,NULL, NULL, "Could not initialize Allegro 5", NULL, NULL);
        return -1;
    }
    al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE);
    ALLEGRO_DISPLAY *display = al_create_display(800,600);
    al_set_window_title(display, "RPG_PROJET_C++");

    if(!display)
    {
        al_show_native_message_box(display, "Sample Title", "Display Settings", "Display Window was not created succesfully", NULL, ALLEGRO_MESSAGEBOX_ERROR);
        return -1;
    }

    //int value = al_show_native_message_box(display, "Message Title", "Error", "Display Window was not be showed", NULL,ALLEGRO_MESSAGEBOX_QUESTION| ALLEGRO_MESSAGEBOX_YES_NO);
    al_init_primitives_addon();

    ALLEGRO_COLOR electricBlue = al_map_rgb(44,117,255);
    ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS);
    ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_display_event_source(display));
    Carte c("carte1.txt");
    //al_draw_triangle(0,0,20,10,15, 50, al_map_rgb(255,0,0), 1.0);

    al_start_timer(timer);

    while(!done){
    ALLEGRO_EVENT events;
    al_wait_for_event(event_queue, &events);
    if(events.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
    {
        done = true;
    }
    else if(events.type == ALLEGRO_EVENT_TIMER)
    {

    }

    c.drawMap();
    al_flip_display();
    al_clear_to_color(al_map_rgb(0,0,0));

    }


    al_destroy_display(display);
    al_destroy_timer(timer);
    al_destroy_event_queue(event_queue);
    return 0;
}

File carte.txt: # is the wall, 1 -> 9 Obstacles, S and C are fighter

10 // largeur
10 // hauteur
##########
##   ##C##
##5  2#  #
#8 ## ##3#
##  #  4 #
### #### #
##S  9## #
##  # ##7#
#2 ## 6  #
##########

https://i.stack.imgur.com/YRpe9.png [1]

Thanks for your answer.

Source: Windows Questions C++

LEAVE A COMMENT