Domanda

no events work in my "game" if I test the actions themselves that should happen (like if I put the moving function into the loop itself or the firing function, it works perfectly), but no event works, closing the display, with esc or pressing X, any pressed key, nothing is seen.

I cannot find the mistake in my code, could anyone please help? The game loop is bellow and all of the main function is here : http://pastebin.ca/2468619

while(!done)
{
    ALLEGRO_EVENT ev;

    al_wait_for_event(event_queue, &ev);

    if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
    {
        std::cout << "EXITING MOFO";
        done= true;
    }

    else if(ev.type == ALLEGRO_KEY_DOWN)
    {
        switch(ev.keyboard.keycode)
{
        case ALLEGRO_KEY_ESCAPE:
            done = true;
            break;
case ALLEGRO_KEY_A:
    keys[A] = true;
    break;
case ALLEGRO_KEY_S:
    keys[S] = true;
    break;
case ALLEGRO_KEY_D:
    keys[D] = true;
    break;
case ALLEGRO_KEY_W:
    keys[W] = true;
    break;
case ALLEGRO_KEY_SPACE:
    fireWeapon(0);
    break;
case ALLEGRO_KEY_LEFT:
    keys[LEFT] = true;
    break;
case ALLEGRO_KEY_RIGHT:
    keys[RIGHT] = true;
    break;
case ALLEGRO_KEY_UP:
    keys[UP] = true;
    break;
case ALLEGRO_KEY_DOWN:
    keys[DOWN] = true;
    break;
case ALLEGRO_KEY_ENTER:
    std::cout << "FUCK";
    fireWeapon(1);
    break;
}
    }
    else if(ev.type == ALLEGRO_KEY_UP)
    {
        switch(ev.keyboard.keycode)
{
case ALLEGRO_KEY_A:
    keys[A] = false;
    break;
case ALLEGRO_KEY_S:
    keys[S] = false;
    break;
case ALLEGRO_KEY_D:
    keys[D] = false;
    break;
case ALLEGRO_KEY_W:
    keys[W] = false;
    break;
case ALLEGRO_KEY_LEFT:
    keys[LEFT] = false;
    break;
case ALLEGRO_KEY_RIGHT:
    keys[RIGHT] = false;
    break;
case ALLEGRO_KEY_UP:
    keys[UP] = false;
    break;
case ALLEGRO_KEY_DOWN:
    keys[DOWN] = false;
    break;
}
    }
    else if(ev.type == ALLEGRO_EVENT_TIMER)
    {
        render = true;
        moveTank();
        updateBullet(0);
        updateBullet(1);
    }
    if(render && al_is_event_queue_empty(event_queue))
    {
        render = false;
        //al_set_target_bitmap(back);
        //al_clear_to_color(al_map_rgb(0,0,0));
        drawTank(0);
        drawTank(1);
        drawBullet(0);
        drawBullet(1);

        //setupDebris();
        al_flip_display();
        al_clear_to_color(al_map_rgb(0,0,0));


    }
È stato utile?

Soluzione

I watched the same tutorial. You have to add al_register_event_source(event_queue, al_get_display_event_source(display)) to main.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top