Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ or c only and use ALLEGRO 5 Particle System (based on ParticleSystem sample)

ID: 3849732 • Letter: C

Question

C++ or c only and use ALLEGRO 5

Particle System (based on ParticleSystem sample) Functional Requirements • The program will have a display size of 640x480. • A player object with a bitmap that looks like a rocket is displayed (bitmap background must be transparent). • The player object has 4 versions of the rocket image for 4 directions and is controlled by keyboard. The rocket moves constantly. Player can only change direction. • An array of particles follows the rocket in proper direction. They will be a constant stream of particles coming out at the end of rocket and going backward a little before they disappear. Every particle that disappears, will appear again at the end of rocket to create the constant stream. Direction of this stream is always the opposite of rocket’s direction. • All particles have a small random movement in addition to base movement described above. Implementation Requirements • Include Objective/Requirements/Algorithm at top of the code • Use arrays for particles and structures for particles and player. You can use one GameObject structure, or define two for Player and Particle

Explanation / Answer

int main()

{

    int mouseX = 0, mouseY = 0;

    int randNum = 0;

    std::vector <Particle *> Particles;

    bool running = false, redraw = false, mouseHold = false;

    int particleCount = 0;

    al_init();

    al_init_image_addon();

    al_install_mouse();

    al_init_font_addon();

    al_init_ttf_addon();

    ALLEGRO_DISPLAY* display = al_create_display(800, 600);

    ALLEGRO_EVENT_QUEUE* event_queue = al_create_event_queue();

    ALLEGRO_TIMER* myTimer = al_create_timer(1.0 / 60);

    ALLEGRO_TIMER* pTimer = al_create_timer(1.0 / 120);

    ALLEGRO_FONT* myFont = al_load_ttf_font("MyFont.ttf", 20, NULL);

    al_register_event_source(event_queue, al_get_display_event_source(display));

    al_register_event_source(event_queue, al_get_timer_event_source(myTimer));

    al_register_event_source(event_queue, al_get_timer_event_source(pTimer));

    al_register_event_source(event_queue, al_get_mouse_event_source());

    running = true;

    al_start_timer(myTimer);

    while(running)

    {

        ALLEGRO_EVENT ev;

        al_wait_for_event(event_queue, &ev);

        if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)

            running = false;

        if(ev.type == ALLEGRO_EVENT_MOUSE_AXES)

        {

            mouseX = ev.mouse.x;

            mouseY = ev.mouse.y;

        }

        if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)

        {

            if(ev.mouse.button == 1)

                mouseHold = true;

        }

        if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)

        {

            if(ev.mouse.button == 1)

                mouseHold = false;

        }

        if(ev.type == ALLEGRO_EVENT_TIMER)

        {

            randNum = (std::rand()+1 * ev.timer.count) % 50;

            std::cout << randNum << std::endl;

            if(mouseHold)

            {

                Particle* particle = new Particle(mouseX + randNum, mouseY + randNum);

                Particles.push_back(particle);

            }

            particleCount = Particles.size();

            for(auto i : Particles)

                i->Update();

            redraw = true;

        }

        for(auto iter = Particles.begin(); iter != Particles.end(); )

            {

                if(!(*iter)->GetAlive())

                {

                    delete (*iter);

                    iter = Particles.erase(iter);

                }

                else

                    iter++;

            }

        if(redraw && al_event_queue_is_empty(event_queue))

        {

            for(auto i : Particles)

                i->Draw();

            al_draw_textf(myFont, al_map_rgb(0,200,0), 0, 10, NULL, "Mouse X: %i", mouseX);

            al_draw_textf(myFont, al_map_rgb(0,200,0), 0, 30, NULL, "Mouse Y: %i", mouseY);

            al_draw_textf(myFont, al_map_rgb(0,200,0), 0, 60, NULL, "Particle Count: %i", particleCount);

            al_flip_display();

            al_clear_to_color(al_map_rgb(0,0,0));

            redraw = false;

        }

    }

    al_destroy_display(display);

    al_destroy_event_queue(event_queue);

    al_destroy_timer(myTimer);

    for(auto i : Particles)

        delete i;

    Particles.clear();

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote