From b9a6443d1d4a62c2d7d283c90a8bab631b90751e Mon Sep 17 00:00:00 2001 From: kdx Date: Mon, 1 Jan 2024 19:11:44 +0100 Subject: goty (tru) --- inc/player.h | 1 + inc/world.h | 1 + res/tset.bmp | Bin 8330 -> 16522 bytes res/world/0.csv | 4 ++-- res/world/1.csv | 4 ++-- res/world/world.csv | 2 +- src/cell.c | 2 +- src/main.c | 5 ++++- src/player.c | 24 +++++++++++++++++++----- src/world.c | 10 +++++++++- 10 files changed, 40 insertions(+), 13 deletions(-) diff --git a/inc/player.h b/inc/player.h index de9c762..33b9d78 100644 --- a/inc/player.h +++ b/inc/player.h @@ -1,4 +1,5 @@ #pragma once +void player_init(void); void player_update(void); void player_draw(void); diff --git a/inc/world.h b/inc/world.h index d4c56f0..e7af998 100644 --- a/inc/world.h +++ b/inc/world.h @@ -17,4 +17,5 @@ void world_init(const char *path, const char *cell_pattern); void world_deinit(void); void world_draw(void); int world_get(int x, int y); +int2 world_find_cell(int tile); int2 world_find(int tile); diff --git a/res/tset.bmp b/res/tset.bmp index e3d780d..0efca43 100644 Binary files a/res/tset.bmp and b/res/tset.bmp differ diff --git a/res/world/0.csv b/res/world/0.csv index 0dd9d13..ea4724a 100644 --- a/res/world/0.csv +++ b/res/world/0.csv @@ -4,14 +4,14 @@ 0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,1,1,1,2,1,1,0,0,0,0,0 0,0,0,1,1,1,1,1,1,1,0,0,2,2,1,1,0,0,0,0 -0,0,1,1,0,0,0,0,0,0,0,0,2,2,0,1,0,0,0,0 +0,0,1,1,3,0,0,0,0,0,0,0,2,2,0,1,0,0,0,0 0,0,0,1,0,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0 0,0,0,1,0,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0 0,0,0,1,1,0,0,0,0,2,0,0,0,0,0,0,1,0,0,0 0,0,0,0,1,0,0,0,2,2,0,0,0,0,2,0,1,0,0,0 0,0,0,0,1,1,0,0,2,2,0,0,0,2,2,0,1,1,0,0 0,0,0,0,0,1,0,0,2,0,0,0,2,2,0,0,0,1,0,0 -0,0,0,0,0,1,0,2,2,0,0,0,2,0,0,0,0,1,0,0 +0,0,0,0,0,1,0,2,2,0,0,0,2,0,0,0,0,4,0,0 0,0,0,0,0,0,1,2,0,0,1,1,1,1,1,1,1,1,0,0 0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,0 0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/res/world/1.csv b/res/world/1.csv index 253af22..5dff3f4 100644 --- a/res/world/1.csv +++ b/res/world/1.csv @@ -9,8 +9,8 @@ 0,0,0,0,1,2,0,0,0,2,2,0,0,0,2,1,1,0,0,0 0,0,0,0,1,0,0,0,0,0,1,2,0,0,2,2,1,1,0,0 0,0,0,0,1,0,0,0,0,0,1,2,0,0,2,0,0,1,0,0 -0,0,0,1,0,0,0,0,2,2,1,0,0,0,0,0,0,1,0,0 -0,0,0,1,0,0,0,0,2,1,0,0,1,2,2,0,1,1,0,0 +0,0,0,1,0,0,0,0,2,2,1,0,0,0,0,0,0,4,0,0 +0,0,0,1,3,0,0,0,2,1,0,0,1,2,2,0,1,1,0,0 0,0,0,1,1,1,1,0,1,0,0,0,1,1,1,1,0,0,0,0 0,0,0,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/res/world/world.csv b/res/world/world.csv index 573796d..92d5ec0 100644 --- a/res/world/world.csv +++ b/res/world/world.csv @@ -1,3 +1,3 @@ -2,0,0 +2,1,0 0,0,0 1,1,0 diff --git a/src/cell.c b/src/cell.c index b90d1ee..543cea1 100644 --- a/src/cell.c +++ b/src/cell.c @@ -96,7 +96,7 @@ cell_find(Cell *this, int tile) { rfor (y, 0, this->height) rfor (x, 0, this->width) - if (this->data[x + y * this->width] == tile) + if (this->data[x + y * this->width] == tile + 1) return I2(x, y); return I2R(-1); } diff --git a/src/main.c b/src/main.c index 9ac5985..96cc993 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,9 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) defer(config_deinit); world_init("res/world/world.csv", "res/world/%d.csv"); defer(world_deinit); + g_world.x = world_find_cell(2).x; + g_world.y = world_find_cell(2).y; + player_init(); assert(TZR_Init(.interlace=true, .width=640, .height=640, @@ -54,7 +57,7 @@ _main_loop([[maybe_unused]] void *udata) TZR_DrawSetColor(0, 0, 0); - if (rand() % 4) { + if (rand() % 128) { TZR_DrawImage(TZR_RES("res/title.bmp"), ___tzr_config.width / 2 + 255 - rand() % 512, ___tzr_config.height / 2 + 255 - rand() % 512, 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); diff --git a/src/world.c b/src/world.c index a0f25fc..be6d5d0 100644 --- a/src/world.c +++ b/src/world.c @@ -110,7 +110,7 @@ world_get(int x, int y) } int2 -world_find(int tile) +world_find_cell(int tile) { rfor (y, 0, g_world.height) { rfor (x, 0, g_world.width) { @@ -126,3 +126,11 @@ world_find(int tile) return I2(-1, -1); } + +int2 +world_find(int tile) +{ + with (cell, g_world.cells[g_world.x + g_world.y * g_world.width]) + return cell_find(cell, tile); + return I2(-1, -1); +} -- cgit v1.2.3