I am working on a game in allegro 5 in which I want to create rectangular objects dynamically on screen and make them clickable with mouse buttons
al_register_event_source( event_queue, al_get_timer_event_source(timer));
al_register_event_source( event_queue, al_get_mouse_event_source());
al_clear_to_color(al_map_rgb(0, 0, 0));
al_flip_display();
al_start_timer(timer);
while ( !exit )
{
ALLEGRO_EVENT ev;
al_wait_for_event( event_queue, &ev);
if (ev.type == ALLEGRO_EVENT_TIMER)
;
else if ( ev.type == ALLEGRO_EVENT_MOUSE_AXES )
{
x = ev.mouse.x;
y = ev.mouse.y;
}
else if ( ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN )
{
if ( x >= rect.x && x <= rect.maxx && y >= rect.y && y <= rect.maxy )
destory ( rect );
}
else if ( ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE )
break;
if ( redraw && al_event_queue_is_empty(event_queue)){
redraw = false;
al_draw_rectangle ( rect.x, rect.y, rect.maxx, rect.maxy, blue, 1 );
al_flip_display();
al_clear_to_color(al_map_rgb(0, 0, 0));
}
}
But this is hardcoded for only one rectangle. How can I make an event for this which can handle rectangles like button.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)