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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include "body.h"
#include "globals.h"
#include "room.h"
#include <SDL2/SDL_ttf.h>
static void move(tt_body *b, int d)
{
b->xrem += b->xvel * d;
b->yrem += b->yvel * d;
b->x += b->xrem / 1000;
b->y += b->yrem / 1000;
b->xrem = b->xrem % 1000;
b->yrem = b->yrem % 1000;
}
void tt_body_move(int d)
{
tt_room *r = ttplayer.room;
int i, j;
for (i = 0; i != TT_ROOM_H; ++i) {
for (j = 0; j != TT_ROOM_W; ++j) {
tt_body *w = r->walls[i][j];
if (w) w->rem += d;
}
}
for (i = 0; i != r->bodies_count; ++i) {
tt_body *b = r->bodies + i;
b->rem += d;
int ex = b->x;
int exr = b->xrem;
int ey = b->y;
int eyr = b->yrem;
move(b, d);
{
SDL_Rect box = { b->x + 5, b->y + 2, 24, 24 };
if (!tt_room_collide(r, &box) && !tt_room_out(r, &box)) continue;
}
b->x = ex;
b->y = ey;
b->xrem = exr;
b->yrem = eyr;
b->xvel *= -1;
move(b, d);
{
SDL_Rect box = { b->x + 5, b->y + 2, 24, 24 };
if (!tt_room_collide(r, &box) && !tt_room_out(r, &box)) continue;
}
b->x = ex;
b->y = ey;
b->xrem = exr;
b->yrem = eyr;
b->xvel *= -1;
b->yvel *= -1;
move(b, d);
{
SDL_Rect box = { b->x + 5, b->y + 2, 24, 24 };
if (!tt_room_collide(r, &box) && !tt_room_out(r, &box)) continue;
}
b->x = ex;
b->y = ey;
b->xrem = exr;
b->yrem = eyr;
b->xvel *= -1;
move(b, d);
}
}
|