discoverable grid
This commit is contained in:
parent
226b88500a
commit
aada552e6a
17
main.c
17
main.c
|
@ -15,6 +15,7 @@ static inline int max(int a, int b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char game[16][30] = {0};
|
char game[16][30] = {0};
|
||||||
|
char discover[16][30] = {0};
|
||||||
|
|
||||||
typedef enum GameType {
|
typedef enum GameType {
|
||||||
BEGINNER,
|
BEGINNER,
|
||||||
|
@ -108,6 +109,7 @@ int count_bomb(int x, int y)
|
||||||
void fill_game(GameType type)
|
void fill_game(GameType type)
|
||||||
{
|
{
|
||||||
memset(game, 0, 16*30);
|
memset(game, 0, 16*30);
|
||||||
|
memset(discover, 0, 16*30);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BEGINNER:
|
case BEGINNER:
|
||||||
|
@ -203,10 +205,11 @@ int main(void)
|
||||||
for (int x=0; x<game_size.x; x++) {
|
for (int x=0; x<game_size.x; x++) {
|
||||||
for (int y=0; y<game_size.y; y++) {
|
for (int y=0; y<game_size.y; y++) {
|
||||||
Texture *tex;
|
Texture *tex;
|
||||||
|
if (discover[y][x]) {
|
||||||
switch (game[y][x]) {
|
switch (game[y][x]) {
|
||||||
default:
|
default:
|
||||||
case 'X': tex = &mine_texture; break;
|
case 'X': tex = &mine_texture; break;
|
||||||
case '0': tex = &tile_texture; break;
|
case '0': continue;
|
||||||
case '1': tex = &t1_texture; break;
|
case '1': tex = &t1_texture; break;
|
||||||
case '2': tex = &t2_texture; break;
|
case '2': tex = &t2_texture; break;
|
||||||
case '3': tex = &t3_texture; break;
|
case '3': tex = &t3_texture; break;
|
||||||
|
@ -216,6 +219,9 @@ int main(void)
|
||||||
case '7': tex = &t7_texture; break;
|
case '7': tex = &t7_texture; break;
|
||||||
case '8': tex = &t8_texture; break;
|
case '8': tex = &t8_texture; break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
tex = &tile_texture;
|
||||||
|
}
|
||||||
|
|
||||||
DrawTexture(
|
DrawTexture(
|
||||||
*tex,
|
*tex,
|
||||||
|
@ -237,14 +243,11 @@ int main(void)
|
||||||
mouse_y = max(mouse_y, grid_y);
|
mouse_y = max(mouse_y, grid_y);
|
||||||
mouse_y = min(mouse_y, grid_y + grid.height - (grid_len/game_size.y));
|
mouse_y = min(mouse_y, grid_y + grid.height - (grid_len/game_size.y));
|
||||||
|
|
||||||
// remove extra
|
mouse_x = ((float) (mouse_x - grid_x) / grid_len) * game_size.x;
|
||||||
mouse_x -= (mouse_x - grid_x) % (grid_len/game_size.x);
|
mouse_y = ((float) (mouse_y - grid_y) / grid_len) * game_size.y;
|
||||||
mouse_y -= (mouse_y - grid_y) % (grid_len/game_size.y);
|
|
||||||
|
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||||
DrawTexture(mine_texture, mouse_x, mouse_y, WHITE);
|
discover[mouse_y][mouse_x] = 1;
|
||||||
} else {
|
|
||||||
DrawTexture(tile_hover_texture, mouse_x, mouse_y, WHITE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
Loading…
Reference in New Issue