Advertisement
Le_BuG63

Untitled

May 17th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. RECTCollision
  2. moveRect(MAP *map, float vx, float vy, RECT *rect) {
  3.     if (vx != 0.f && vy != 0.f) {
  4.         const RECTCollision xCol = moveRect(map, vx, 0.f, rect);
  5.         const RECTCollision yCol = moveRect(map, 0.f, vy, rect);
  6.  
  7.         const RECTCollision rectCol = { xCol.left, xCol.right, yCol.top, yCol.bottom };
  8.  
  9.         return rectCol;
  10.     }
  11.  
  12.     RECTCollision rcol = { .left = false,
  13.         .right = false,
  14.         .top = false,
  15.         .bottom = false };
  16.  
  17.     unsigned int tries = 2;
  18.  
  19.     while (tries > 0) {
  20.         RECT newRect = *rect;
  21.  
  22.         newRect.x += vx;
  23.         newRect.y += vy;
  24.  
  25.         if (rectCollision(&newRect, *map)) {
  26.             if (vx > 0.f)
  27.                 rcol.right = true;
  28.             else if (vx < 0.f)
  29.                 rcol.left = true;
  30.  
  31.             if (vy > 0.f)
  32.                 rcol.bottom = true;
  33.             else if (vy < 0.f)
  34.                 rcol.top = true;
  35.  
  36.             vx *= 0.65f;
  37.             vy *= 0.65f;
  38.         }
  39.         else {
  40.             *rect = newRect;
  41.             break;
  42.         }
  43.         --tries;
  44.     }
  45.     return rcol;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement