commit 279eb78cd28b110178b685537c06b0df169aba98 Author: _N3m0 Date: Mon Mar 11 12:43:20 2024 +0100 huge init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ac255c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.wakatime-project diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7688645 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +all: + gcc -Wall -Wextra -ggdb main.c -o mineur -lraylib + +run: all + ./mineur + +clean: + rm -f mineur diff --git a/main.c b/main.c new file mode 100644 index 0000000..946d00c --- /dev/null +++ b/main.c @@ -0,0 +1,69 @@ +#include "raylib.h" + +static inline int min(int a, int b) { + return a < b ? a : b; +} + +int screen_width = 500; +int screen_height = 550; + +Rectangle menu; +int grid_len = 0; +int nb_cell = 16; + +Rectangle grid = {0}; + +Image mine_image_orig = {0}; +Texture mine_texture = {0}; + +void screen_resize_handle(void) { + screen_width = GetScreenWidth(); + screen_height = GetScreenHeight(); + + menu.width = screen_width; + grid_len = min(screen_width, screen_height - menu.height); + grid = (Rectangle){(screen_width - grid_len) / 2, + screen_height - grid_len, + grid_len, grid_len}; + + Image mine_copy = ImageCopy(mine_image_orig); + ImageResize(&mine_copy, grid.width/nb_cell, grid.height/nb_cell); + mine_texture = LoadTextureFromImage(mine_copy); +} + +int main(void) { + SetConfigFlags(FLAG_WINDOW_RESIZABLE); + + menu = (Rectangle){0, 0, screen_width, screen_height - screen_width}; + mine_image_orig = LoadImage("ressources/mine.png"); + + InitWindow(screen_width, screen_height, "mineur"); + + screen_resize_handle(); + + while (!WindowShouldClose()) { + if (IsWindowResized()) + screen_resize_handle(); + + BeginDrawing(); + { + ClearBackground(RAYWHITE); + + DrawRectangleRec(menu, RED); + DrawRectangleRec(grid, GRAY); + + for (int x=0; x + + + + + + + + + + + + + + +