Enter the matrix

This commit is contained in:
KikooDX 2021-06-01 22:49:16 +02:00
parent 6adbc83c86
commit f0001a7809
8 changed files with 35 additions and 3 deletions

View File

@ -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

View File

@ -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);

View File

@ -10,5 +10,6 @@ enum Tile {
TILE_OBSTACLE_3,
TILE_SOLID,
TILE_ZONE_TRANSITION,
TILE_CONTRACTS,
};
#define TILE_OOB TILE_SOLID

View File

@ -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;

View File

@ -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);
}
}

10
src/grid/shop.c Normal file
View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 */