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
|
#include "player.h"
static int2 pos = I2(0, 0);
static int2 dir = I2(1, 0);
static bool collide(int tile, int2 p);
void
player_init(void)
{
}
void
player_update(void)
{
// rotate counterclockwise
if (input_pressed("action"))
dir = I2(dir.y, -dir.x);
// deth
if (collide(1, pos))
pwrn("U DED");
// you read mi code??
const auto next_pos = int2_add(pos, dir);
// thx and sry i guess
if (!collide(0, next_pos))
pos = next_pos;
}
void
player_draw(void)
{
TZR_DrawSetColor(0, 0, 0);
TZR_DrawRectangle(UNPACK(pos), 3, 4, true, true);
}
static bool
collide(int tile, int2 p)
{
return world_get(p.x, p.y) == tile;
}
|