commit 279eb78cd28b110178b685537c06b0df169aba98 Author: _N3m0 <n3m0o7@hotmail.com> 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<nb_cell; x++) { + for (int y=0; y<nb_cell; y++) { + DrawTexture(mine_texture, + grid.x + grid.width/nb_cell * x, + grid.y + grid.height/nb_cell * y, + WHITE); + } + } + } + EndDrawing(); + } + + CloseWindow(); + return 0; +} diff --git a/mineur b/mineur new file mode 100755 index 0000000..93a310b Binary files /dev/null and b/mineur differ diff --git a/ressources/mine.png b/ressources/mine.png new file mode 100644 index 0000000..9f8726a Binary files /dev/null and b/ressources/mine.png differ diff --git a/ressources/mine.svg b/ressources/mine.svg new file mode 100644 index 0000000..3c4aa6c --- /dev/null +++ b/ressources/mine.svg @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + width="500" + height="500" + viewBox="0 0 132.29167 132.29167" + version="1.1" + id="svg5" + inkscape:version="1.2.2 (b0a8486541, 2022-12-01)" + sodipodi:docname="mine.svg" + inkscape:export-filename="mine.png" + inkscape:export-xdpi="42.760944" + inkscape:export-ydpi="42.760944" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <sodipodi:namedview + id="namedview7" + pagecolor="#505050" + bordercolor="#eeeeee" + borderopacity="1" + inkscape:showpageshadow="0" + inkscape:pageopacity="0" + inkscape:pagecheckerboard="0" + inkscape:deskcolor="#505050" + inkscape:document-units="mm" + showgrid="false" + inkscape:zoom="0.54866744" + inkscape:cx="-27.338965" + inkscape:cy="231.4699" + inkscape:window-width="1912" + inkscape:window-height="1047" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:window-maximized="1" + inkscape:current-layer="layer1" /> + <defs + id="defs2"> + <linearGradient + id="linearGradient1502" + inkscape:swatch="solid"> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop1500" /> + </linearGradient> + </defs> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <ellipse + style="fill:#000000;stroke:#000000;stroke-width:0.223074;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers" + id="path111" + cx="62.799694" + cy="72.270866" + rx="56.635628" + ry="54.199226" /> + <path + sodipodi:type="spiral" + style="fill:none;fill-rule:evenodd;stroke:#ffffff;stroke-width:8.74093;stroke-dasharray:none;stroke-opacity:1" + id="path341" + sodipodi:cx="28.490538" + sodipodi:cy="45.3279" + sodipodi:expansion="1" + sodipodi:revolution="0.48942739" + sodipodi:radius="29.633478" + sodipodi:argument="-18.138201" + sodipodi:t0="0.43865359" + d="M 22.3788,56.800314 C 9.0687208,58.790669 1.8870045,43.112185 3.6587879,32.099198 3.9093976,30.541467 4.2971025,29.006294 4.8091046,27.514064" + transform="matrix(-0.43060005,0.65234095,-0.65851537,-0.4265626,146.99062,27.717028)" /> + <rect + style="fill:#000000;stroke:#000000;stroke-width:0.294461;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers" + id="rect286" + width="32.785309" + height="14.191555" + x="78.330818" + y="-41.435642" + ry="0" + rx="0" + transform="matrix(0.8383838,0.54508037,-0.54856161,0.83611013,0,0)" /> + </g> +</svg>