diff options
Diffstat (limited to 'src/player.c')
-rw-r--r-- | src/player.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/player.c b/src/player.c index 5954cf8..b7dcde5 100644 --- a/src/player.c +++ b/src/player.c @@ -1,26 +1,40 @@ #include "player.h" static int2 pos = I2(0, 0); -static int2 dir = I2(1, 0); +static int2 dir = I2(0, 0); static bool collide(int tile, int2 p); void player_init(void) { - + pos = world_find(2); + pos.x *= cfg.tile_width; + pos.x += cfg.tile_width / 2; + pos.y *= cfg.tile_height; + pos.y += cfg.tile_height / 2; + dir = I2R(0); } void player_update(void) { // rotate counterclockwise - if (input_pressed("action")) - dir = I2(dir.y, -dir.x); + if (input_pressed("action")) { + if (dir.x + dir.y) + dir = I2(dir.y, -dir.x); + else + dir = I2(1, 0); + } + + if (collide(3, pos)) { + g_world.x += 1; + return player_init(); + } // deth if (collide(1, pos)) - pwrn("U DED"); + return player_init(); // you read mi code?? const auto next_pos = int2_add(pos, dir); |