summaryrefslogtreecommitdiff
path: root/src/player.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/player.c b/src/player.c
index 71a8c30..5954cf8 100644
--- a/src/player.c
+++ b/src/player.c
@@ -3,15 +3,30 @@
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)
{
- if (input_pressed("action")) {
+ // rotate counterclockwise
+ if (input_pressed("action"))
dir = I2(dir.y, -dir.x);
- int2_log(log, dir);
- }
- pos = int2_add(pos, dir);
+ // 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
@@ -20,3 +35,9 @@ 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;
+}