//flip the x direction
bouncer_dx = -bouncer_dx;
}
if (bouncer_y < 0 || bouncer_y > 480 - 32) {
bouncer_dy = -bouncer_dy;
}
if (bouncer2_x < 0 || bouncer2_x > 640 - 32) {
bouncer2_dx = -bouncer2_dx;
}
if (bouncer2_y < 0 || bouncer2_y > 480 - 32) {
bouncer2_dy = -bouncer2_dy;
}
//really important code!
//move the box in a diagonal
bouncer_x += bouncer_dx;
bouncer_y += bouncer_dy;
bouncer2_x += bouncer2_dx;
bouncer2_y += bouncer2_dy;
//if an event happened, you better redraw
redraw = true;
}
//////////////////////////////////////////////////////////////////
//kill program if the user clicks the exit button
else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
break;
}
//if you were supposed to redraw but there wasn't an event, don't redraw
if (redraw && al_is_event_queue_empty(event_queue)) {
redraw = false;
}
al_clear_to_color(al_map_rgb(0, 0, 0));
the code tells the object in this case "bouncer" to only bounce after he has hit one of the corners or walls. this basically describes the outer walls and edges of the walls in your "game" with words and out of words a program is created. like the code is describing to the program what to create.
No comments:
Post a Comment