After scoring a point, my pong clone does not continue (c++ and allegro) [closed]

  allegro, c++, pong

I have written the following program, utilising the allegro library, however i can’t seem to figure out, why it does not continue after scoring a point. Can anyone maybe tell me, what i did wrong or what to look out for?

Since i tend to use German and English names for variables, here are their translations:

screenweite : screen widht

screenhoehe : screen height

richtung : direction

#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <iostream>

#define screenweite  1000
#define screenhoehe  600

#define down_right  1
#define up_right    2
#define down_left   3
#define up_left     4

using namespace std;

int main()
{
    bool done = false;
    bool goal = false;
    bool goaldone = false;

    int x1 = 10, y1 = 200;
    int x2 = 970, y2 = 200;
    int x3 = 500, y3 = 300;

    int score1 = 0, score2 = 0;

    double speed = 5.0;
    int richtung = 4;

    al_init();
    al_init_image_addon();
    al_init_primitives_addon();
    al_install_keyboard();
    al_init_font_addon();
    al_init_ttf_addon();

    ALLEGRO_DISPLAY* display = al_create_display(screenweite, screenhoehe);
    ALLEGRO_BITMAP* blocklinks = al_load_bitmap("sprites/expressionismus.bmp");
    ALLEGRO_BITMAP* blockrechts = al_load_bitmap("sprites/expressionismus.bmp");
    ALLEGRO_EVENT_QUEUE* eventqueue = al_create_event_queue();
    ALLEGRO_TIMER* timer = al_create_timer(1.0 / 60);
    ALLEGRO_FONT* font = al_load_font("fonts/PTS76F.ttf", 20, NULL);

    al_register_event_source(eventqueue, al_get_keyboard_event_source());
    al_register_event_source(eventqueue, al_get_timer_event_source(timer));
    al_set_window_position(display, 0, 0);

    while (!done)
    {
        al_start_timer(timer);
        ALLEGRO_EVENT block;

        al_wait_for_event(eventqueue, &block);

        al_draw_textf(font, al_map_rgb(255, 255, 255), 10, 10, NULL, "Score Player 1: %d", score1);
        al_draw_textf(font, al_map_rgb(255, 255, 255), 800, 10, NULL, "Score Player 2: %d", score2);

        if (goaldone)
        {
            if (x3 <= 15)
            {
                score2 += 1;
                goaldone = false;
                y3 = screenhoehe / 2;
                x3 = screenweite / 2;
                richtung = 4;

            }
            if (x3 <= 985)
            {
                score1 += 1;
                goaldone = false;
                y3 = screenhoehe / 2;
                x3 = screenweite / 2;
                richtung = 3;
            }
        }

        if (block.type == ALLEGRO_EVENT_KEY_DOWN)
        {
            if (y1 >= 0 && y1 <= 400)
            {
                switch (block.keyboard.keycode)
                {
                case ALLEGRO_KEY_S:
                    y1 += 30;
                    break;
                case ALLEGRO_KEY_W:
                    y1 -= 30;
                    break;
                }
            }
            if (y1 < 0)
            {
                y1 = 0;
            }
            if (y1 > 400)
            {
                y1 = 400;
            }



            if (y2 >= 0 && y2 <= 400)
            {
                switch (block.keyboard.keycode)
                {
                case ALLEGRO_KEY_DOWN:
                    y2 += 30;
                    break;
                case ALLEGRO_KEY_UP:
                    y2 -= 30;
                    break;
                }
            }
            if (y2 < 0)
            {
                y2 = 0;
            }
            if (y2 > 400)
            {
                y2 = 400;
            }

            switch (block.keyboard.keycode)
            {
            case ALLEGRO_KEY_ESCAPE:
                done = true;
                break;
            }
        }

        if (block.type == ALLEGRO_EVENT_TIMER)
        {
            if (!goal)
            {
                if (richtung == 1)
                {
                    y3 += speed;
                    x3 += speed;
                }
                if (richtung == 2)
                {
                    y3 -= speed;
                    x3 += speed;
                }
                if (richtung == 3)
                {
                    if (x3 <= 45 && y3 >= y1 && y3 <= y1 + 200 && richtung == 4)
                    {
                        richtung = 2;
                    }
                    y3 += speed;
                    x3 -= speed;
                }
                if (richtung == 4)
                {
                    y3 -= speed;
                    x3 -= speed;
                }
            }
        }

        if (richtung == 1 && y3 >= 585)
        {
            richtung = 2;
        }
        if (richtung == 3 && y3 >= 585)
        {
            richtung = 4;
        }

        if (richtung == 2 && y3 <= 15)
        {
            richtung = 1;
        }
        if (richtung == 4 && y3 <= 15)
        {
            richtung = 3;
        }

        if (x3 <= 45 && y3 >= y1 && y3 <= y1 + 200 && richtung == 4)
        {
            richtung = 2;
        }
        if (x3 <= 45 && y3 >= y1 && y3 <= y1 + 200 && richtung == 3)
        {
            richtung = 1;
        }
        if (x3 >= 955 && y3 >= y2 && y3 <= y2 + 200 && richtung == 2)
        {
            richtung = 4;
        }
        if (x3 >= 955 && y3 >= y2 && y3 <= y2 + 200 && richtung == 1)
        {
            richtung = 3;
        }

        if (x3 <= 15 || x3 >= 985)
        {
            goal = true;
            goaldone = true;
        }


        al_draw_filled_rectangle(x1, y1, x1 + 20, y1 + 200, al_map_rgb(255, 255, 255));
        al_draw_filled_rectangle(x2, y2, x2 + 20, y2 + 200, al_map_rgb(255, 255, 255));
        al_draw_filled_circle(x3, y3, 15, al_map_rgb(255, 255, 255));

        al_flip_display();
        al_clear_to_color(al_map_rgb(0, 0, 0));
        al_start_timer(timer);
    }

    al_destroy_bitmap(blocklinks);
    al_destroy_bitmap(blockrechts);
    al_destroy_display(display);
    al_destroy_timer(timer);
    al_destroy_event_queue(eventqueue);
}

Source: Windows Questions C++

LEAVE A COMMENT