summaryrefslogtreecommitdiff
path: root/src/room.c
blob: a51c712911eedbddb367736bbcc469171801d4db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "room.h"

int tt_room_collide(tt_room *room, SDL_Rect *box)
{
    SDL_Rect r = { 0, 0, 32, 16 };
    int      i, j;
    for (i = 0; i != TT_ROOM_H; ++i) {
        r.y = 32 * i;
        for (j = 0; j != TT_ROOM_W; ++j) {
            r.x = 32 * j;
            if (SDL_HasIntersection(box, room->walls[i][j] ? &r : 0))
                return 1;
        }
    }
    return 0;
}

int tt_room_out(tt_room *room, SDL_Rect *box)
{
    if (!box) return 0;
    if (box->y < 0) return 1;
    if (box->x + box->w > TT_ROOM_W * 32) return 2;
    if (box->y + box->h > TT_ROOM_H * 32) return 3;
    if (box->x < 0) return 4;
    return 0;
}