diff --git a/CMakeLists.txt b/CMakeLists.txt index 253c620..704dd02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ set(SOURCES src/grid/alloc.c src/grid/random_walker.c src/grid/draw.c + src/grid/shop.c ) set(ASSETS diff --git a/include/grid.h b/include/grid.h index 3269530..d316115 100644 --- a/include/grid.h +++ b/include/grid.h @@ -15,3 +15,4 @@ void grid_set(struct Grid *restrict, int x, int y, enum Tile); enum Tile grid_get(struct Grid, int x, int y); void grid_draw(struct Grid, int scr_x, int scr_y); void grid_random_walker(struct Grid *restrict grid); +void grid_shop(struct Grid *restrict grid); diff --git a/include/tiles.h b/include/tiles.h index 18851a5..e9bf8c0 100644 --- a/include/tiles.h +++ b/include/tiles.h @@ -10,5 +10,6 @@ enum Tile { TILE_OBSTACLE_3, TILE_SOLID, TILE_ZONE_TRANSITION, + TILE_CONTRACTS, }; #define TILE_OOB TILE_SOLID diff --git a/src/grid/draw.c b/src/grid/draw.c index 506cd67..08520e1 100644 --- a/src/grid/draw.c +++ b/src/grid/draw.c @@ -65,6 +65,12 @@ tile_draw(enum Tile tile, int x, int y) case TILE_SOLID: color = C_BLUE; break; + case TILE_ZONE_TRANSITION: + color = C_RGB(0, 31, 31); + break; + case TILE_CONTRACTS: + color = C_RGB(31, 31, 0); + break; default: color = C_RGB(31, 0, 31); break; diff --git a/src/grid/random_walker.c b/src/grid/random_walker.c index b4b8d38..81fe708 100644 --- a/src/grid/random_walker.c +++ b/src/grid/random_walker.c @@ -54,4 +54,12 @@ grid_random_walker(struct Grid *restrict grid) break; } } + + /* place resting points */ + for (x = 64; x < grid->width; x += 64) { + for (y = 0; y < grid->height; y += 1) { + if (!grid_get(*grid, x, y)) break; + } + grid_set(grid, x, y, TILE_ZONE_TRANSITION); + } } diff --git a/src/grid/shop.c b/src/grid/shop.c new file mode 100644 index 0000000..6a61b27 --- /dev/null +++ b/src/grid/shop.c @@ -0,0 +1,10 @@ +#include "grid.h" +#include "tiles.h" + +void grid_shop(struct Grid *restrict grid) { + const int x_middle = grid->width / 2; + const int y_middle = grid->height / 2; + + grid_set(grid, x_middle, y_middle, TILE_CONTRACTS); + grid_set(grid, x_middle + 4, y_middle, TILE_ZONE_TRANSITION); +} diff --git a/src/main.c b/src/main.c index df857fb..7a2c08b 100644 --- a/src/main.c +++ b/src/main.c @@ -57,8 +57,11 @@ main_loop(struct Game *restrict game) clearevents(); switch(game->state) { case GameFloor: - if (player_update(&game->player, &game->floor)) + if (player_update(&game->player, &game->floor)) { game->state = GameRest; + grid_shop(&game->rest); + } + scroll_x -= 1; break; case GameRest: if (player_update(&game->player_rest, &game->rest)) @@ -83,7 +86,5 @@ main_loop(struct Game *restrict game) } dupdate(); - scroll_x -= 1; - return keydown(KEY_EXIT); } diff --git a/src/player/update.c b/src/player/update.c index 7f1f45f..ed870e6 100644 --- a/src/player/update.c +++ b/src/player/update.c @@ -49,7 +49,11 @@ player_update(struct Player *restrict player, struct Grid *restrict grid) player->y = new_y; break; case TILE_ZONE_TRANSITION: + grid_set(grid, new_x, new_y, TILE_VOID); return 1; + case TILE_CONTRACTS: + /* start contracts sequence */ + break; case TILE_OBSTACLE_1: player->cash += 1; /* fallthrough */