diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/game/cell.c | 14 | ||||
-rw-r--r-- | src/main/game/cell.h | 3 | ||||
-rw-r--r-- | src/main/game/game.c | 3 |
3 files changed, 19 insertions, 1 deletions
diff --git a/src/main/game/cell.c b/src/main/game/cell.c index 53d051a..c8151b2 100644 --- a/src/main/game/cell.c +++ b/src/main/game/cell.c @@ -45,6 +45,7 @@ cell_new(float left, float right, float top, float bottom) cell->right = right; cell->top = top; cell->bottom = bottom; + cell->filled = false; return cell; } @@ -54,3 +55,16 @@ cell_within_bounds(Cell *cell, float x, float y) { return x >= cell->left && x <= cell->right && y <= cell->top && y >= cell->bottom; } + +void +cell_set_filled(Cell *cell, bool filled) +{ + if (cell == NULL) return; + cell->filled = filled; +} + +bool +cell_is_filled(Cell *cell) { + if (cell == NULL) return false; + return cell->filled; +} diff --git a/src/main/game/cell.h b/src/main/game/cell.h index 50a5606..000edfb 100644 --- a/src/main/game/cell.h +++ b/src/main/game/cell.h @@ -24,9 +24,12 @@ typedef struct Cell { float left, right, top, bottom; + bool filled; } Cell; Cell *cell_new(float left, float right, float top, float bottom); bool cell_within_bounds(Cell *cell, float x, float y); +void cell_set_filled(Cell *cell, bool filled); +bool cell_is_filled(Cell *cell); #endif /* __GAME_CELL_H__ */ diff --git a/src/main/game/game.c b/src/main/game/game.c index 25de722..2e2db8f 100644 --- a/src/main/game/game.c +++ b/src/main/game/game.c @@ -77,7 +77,8 @@ loop_cells(list_t *cells, float x, float y) list_node_t *current = cells->head; do { Cell *cell = current->data; - if (cell_within_bounds(cell, x, y)) { + if (!cell_is_filled(cell) && cell_within_bounds(cell, x, y)) { + cell_set_filled(cell, true); } current = current->next; } while (current != NULL); |