diff --git a/Makefile b/Makefile index 7688645..f0b9b16 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ all: gcc -Wall -Wextra -ggdb main.c -o mineur -lraylib +release: + gcc -Wall -Wextra -O3 main.c -o mineur -lraylib + run: all ./mineur diff --git a/main.c b/main.c index 1410901..df1fdd4 100644 --- a/main.c +++ b/main.c @@ -34,17 +34,25 @@ int screen_width = 500; int screen_height = 550; Rectangle menu; -Vec2i nb_cell = {9, 9}; // 9-9 16-16 16-30 int grid_len = 0; Rectangle grid = {0}; -Image tile_image_orig = {0}; -Texture tile_texture = {0}; -Image tile_hover_image_orig = {0}; -Texture tile_hover_texture = {0}; -Image mine_image_orig = {0}; -Texture mine_texture = {0}; +#define INIT_TEXTURE(img, tex) \ + Image img = {0}; \ + Texture tex = {0} + +INIT_TEXTURE(tile_image_orig, tile_texture); +INIT_TEXTURE(tile_hover_image_orig, tile_hover_texture); +INIT_TEXTURE(mine_image_orig, mine_texture); +INIT_TEXTURE(t1_image_orig, t1_texture); +INIT_TEXTURE(t2_image_orig, t2_texture); +INIT_TEXTURE(t3_image_orig, t3_texture); +INIT_TEXTURE(t4_image_orig, t4_texture); +INIT_TEXTURE(t5_image_orig, t5_texture); +INIT_TEXTURE(t6_image_orig, t6_texture); +INIT_TEXTURE(t7_image_orig, t7_texture); +INIT_TEXTURE(t8_image_orig, t8_texture); void screen_resize_handle(void) { @@ -59,17 +67,42 @@ void screen_resize_handle(void) grid_len, grid_len }; - Image tile_copy = ImageCopy(tile_image_orig); - ImageResize(&tile_copy, grid.width/nb_cell.x, grid.height/nb_cell.y); - tile_texture = LoadTextureFromImage(tile_copy); +#define RESIZE_TEXTURE(name, copy, orig) \ + do { \ + Image copy = ImageCopy(orig); \ + ImageResize(&(copy), grid.width/game_size.x, grid.height/game_size.y);\ + name = LoadTextureFromImage(copy); \ + } while (0) - Image tile_hover_copy = ImageCopy(tile_hover_image_orig); - ImageResize(&tile_hover_copy, grid.width/nb_cell.x, grid.height/nb_cell.y); - tile_hover_texture = LoadTextureFromImage(tile_hover_copy); + RESIZE_TEXTURE(tile_texture, tile_copy, tile_image_orig); + RESIZE_TEXTURE(tile_hover_texture, tile_hover_copy, tile_hover_image_orig); + RESIZE_TEXTURE(mine_texture, mine_copy, mine_image_orig); + RESIZE_TEXTURE(t1_texture, t1_copy, t1_image_orig); + RESIZE_TEXTURE(t2_texture, t2_copy, t2_image_orig); + RESIZE_TEXTURE(t3_texture, t3_copy, t3_image_orig); + RESIZE_TEXTURE(t4_texture, t4_copy, t4_image_orig); + RESIZE_TEXTURE(t5_texture, t5_copy, t5_image_orig); + RESIZE_TEXTURE(t6_texture, t6_copy, t6_image_orig); + RESIZE_TEXTURE(t7_texture, t7_copy, t7_image_orig); + RESIZE_TEXTURE(t8_texture, t8_copy, t8_image_orig); +} - Image mine_copy = ImageCopy(mine_image_orig); - ImageResize(&mine_copy, grid.width/nb_cell.x, grid.height/nb_cell.y); - mine_texture = LoadTextureFromImage(mine_copy); +int count_bomb(int x, int y) +{ + int count = 0; + for (int i=-1; i<=1; i++) { + if (x+i < 0 || x+i > game_size.x) + continue; + for (int j=-1; j<=1; j++) { + if (y+j < 0 || y+j > game_size.y) + continue; + if (i == 0 && j == 0) + continue; + if (game[y+j][x+i] == 'X') + count++; + } + } + return count; } void fill_game(GameType type) @@ -115,24 +148,6 @@ void fill_game(GameType type) } } -int count_bomb(int x, int y) -{ - int count = 0; - for (int i=-1; i<=1; i++) { - if (x+i < 0 || x+i > game_size.x) - continue; - for (int j=-1; j<=1; j++) { - if (y+j < 0 || y+j > game_size.y) - continue; - if (i == 0 && j == 0) - continue; - if (game[y+j][x+i] == 'X') - count++; - } - } - return count; -} - int main(void) { srand(time(NULL)); @@ -143,6 +158,15 @@ int main(void) tile_image_orig = LoadImage("ressources/tile.png"); tile_hover_image_orig = LoadImage("ressources/tile_hover.png"); mine_image_orig = LoadImage("ressources/mine.png"); + mine_image_orig = LoadImage("ressources/mine.png"); + t1_image_orig = LoadImage("ressources/1.png"); + t2_image_orig = LoadImage("ressources/2.png"); + t3_image_orig = LoadImage("ressources/3.png"); + t4_image_orig = LoadImage("ressources/4.png"); + t5_image_orig = LoadImage("ressources/5.png"); + t6_image_orig = LoadImage("ressources/6.png"); + t7_image_orig = LoadImage("ressources/7.png"); + t8_image_orig = LoadImage("ressources/8.png"); InitWindow(screen_width, screen_height, "mineur"); SetTargetFPS(60); @@ -162,40 +186,43 @@ int main(void) if (IsKeyPressed(KEY_R)) { fill_game(BEGINNER); } + if (IsKeyPressed(KEY_P)) { + for (int x=0; x + + + + + + + + + + + 1 + + + diff --git a/ressources/2.png b/ressources/2.png new file mode 100644 index 0000000..4a36687 Binary files /dev/null and b/ressources/2.png differ diff --git a/ressources/2.svg b/ressources/2.svg new file mode 100644 index 0000000..ed0268c --- /dev/null +++ b/ressources/2.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + 2 + + diff --git a/ressources/3.png b/ressources/3.png new file mode 100644 index 0000000..aac567c Binary files /dev/null and b/ressources/3.png differ diff --git a/ressources/3.svg b/ressources/3.svg new file mode 100644 index 0000000..8bd9b7a --- /dev/null +++ b/ressources/3.svg @@ -0,0 +1,65 @@ + + + + + + + + + 3 + + diff --git a/ressources/4.png b/ressources/4.png new file mode 100644 index 0000000..1cd18b5 Binary files /dev/null and b/ressources/4.png differ diff --git a/ressources/4.svg b/ressources/4.svg new file mode 100644 index 0000000..e835a89 --- /dev/null +++ b/ressources/4.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + 4 + + diff --git a/ressources/5.png b/ressources/5.png new file mode 100644 index 0000000..558230e Binary files /dev/null and b/ressources/5.png differ diff --git a/ressources/5.svg b/ressources/5.svg new file mode 100644 index 0000000..aedaeda --- /dev/null +++ b/ressources/5.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + 5 + + diff --git a/ressources/6.png b/ressources/6.png new file mode 100644 index 0000000..85880c7 Binary files /dev/null and b/ressources/6.png differ diff --git a/ressources/6.svg b/ressources/6.svg new file mode 100644 index 0000000..802c4ce --- /dev/null +++ b/ressources/6.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + 6 + + diff --git a/ressources/7.png b/ressources/7.png new file mode 100644 index 0000000..264282d Binary files /dev/null and b/ressources/7.png differ diff --git a/ressources/7.svg b/ressources/7.svg new file mode 100644 index 0000000..8e9b078 --- /dev/null +++ b/ressources/7.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + 7 + + diff --git a/ressources/8.png b/ressources/8.png new file mode 100644 index 0000000..4fad181 Binary files /dev/null and b/ressources/8.png differ diff --git a/ressources/8.svg b/ressources/8.svg new file mode 100644 index 0000000..6844de5 --- /dev/null +++ b/ressources/8.svg @@ -0,0 +1,66 @@ + + + + + + + + + 8 + +