|
Need simple collision and hit box |
matsumoto
Member #16,849
April 2018
|
Hi , I searched on several sites but there was too much detail and I could not find a subject that describes a simple collision code. That's why I did not understand how can I hit the boxes with ball and then bounce the ball ? ----------------- This is my code : ---------------------- #include <stdio.h> const int width = 1024; enum KEYS { LEFT, RIGHT }; struct ball { //KEEPS TRACK OF BALL VARIABLES }; int FPS = 60; bool done = true; ball myBall; //Make a ball image = al_load_bitmap("image.png"); display = al_create_display(width, height); event_queue = al_create_event_queue(); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_start_timer(timer); myBall.y += myBall.vely; if (myBall.y + myBall.radius > 600 && myBall.vely > 0) { //Ball has hit the floor and is moving downward } if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { imageh += 3; } al_clear_to_color(al_map_rgb(0, 0, 0)); } |
Edgar Reynaldo
Major Reynaldo
May 2007
|
You can use <code>code goes here</code> tags to post code, and the paper and pencil icon on your post to edit it. You're looking for AABB or Rectangle vs Circle collision detection. Rectangle overlap checks are fairly easy, the second is harder. For an AABB check, the algorithm goes : My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|