Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RECTCollision
- moveRect(MAP *map, float vx, float vy, RECT *rect) {
- if (vx != 0.f && vy != 0.f) {
- const RECTCollision xCol = moveRect(map, vx, 0.f, rect);
- const RECTCollision yCol = moveRect(map, 0.f, vy, rect);
- const RECTCollision rectCol = { xCol.left, xCol.right, yCol.top, yCol.bottom };
- return rectCol;
- }
- RECTCollision rcol = { .left = false,
- .right = false,
- .top = false,
- .bottom = false };
- unsigned int tries = 2;
- while (tries > 0) {
- RECT newRect = *rect;
- newRect.x += vx;
- newRect.y += vy;
- if (rectCollision(&newRect, *map)) {
- if (vx > 0.f)
- rcol.right = true;
- else if (vx < 0.f)
- rcol.left = true;
- if (vy > 0.f)
- rcol.bottom = true;
- else if (vy < 0.f)
- rcol.top = true;
- vx *= 0.65f;
- vy *= 0.65f;
- }
- else {
- *rect = newRect;
- break;
- }
- --tries;
- }
- return rcol;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement