grid
This commit is contained in:
parent
70d268edaa
commit
b62dbbc1eb
61
main.c
61
main.c
|
@ -3,6 +3,9 @@
|
|||
static inline int min(int a, int b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
static inline int max(int a, int b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
int screen_width = 500;
|
||||
int screen_height = 550;
|
||||
|
@ -13,6 +16,10 @@ int nb_cell = 16;
|
|||
|
||||
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};
|
||||
|
||||
|
@ -22,9 +29,19 @@ void screen_resize_handle(void) {
|
|||
|
||||
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};
|
||||
grid = (Rectangle){
|
||||
(screen_width - grid_len) / 2,
|
||||
screen_height - grid_len,
|
||||
grid_len, grid_len
|
||||
};
|
||||
|
||||
Image tile_copy = ImageCopy(tile_image_orig);
|
||||
ImageResize(&tile_copy, grid.width/nb_cell, grid.height/nb_cell);
|
||||
tile_texture = LoadTextureFromImage(tile_copy);
|
||||
|
||||
Image tile_hover_copy = ImageCopy(tile_hover_image_orig);
|
||||
ImageResize(&tile_hover_copy, grid.width/nb_cell, grid.height/nb_cell);
|
||||
tile_hover_texture = LoadTextureFromImage(tile_hover_copy);
|
||||
|
||||
Image mine_copy = ImageCopy(mine_image_orig);
|
||||
ImageResize(&mine_copy, grid.width/nb_cell, grid.height/nb_cell);
|
||||
|
@ -35,9 +52,12 @@ int main(void) {
|
|||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
menu = (Rectangle){0, 0, screen_width, screen_height - screen_width};
|
||||
tile_image_orig = LoadImage("ressources/tile.png");
|
||||
tile_hover_image_orig = LoadImage("ressources/tile_hover.png");
|
||||
mine_image_orig = LoadImage("ressources/mine.png");
|
||||
|
||||
InitWindow(screen_width, screen_height, "mineur");
|
||||
SetTargetFPS(60);
|
||||
|
||||
screen_resize_handle();
|
||||
|
||||
|
@ -47,19 +67,42 @@ int main(void) {
|
|||
|
||||
BeginDrawing();
|
||||
{
|
||||
ClearBackground(RAYWHITE);
|
||||
ClearBackground(BLACK);
|
||||
|
||||
DrawRectangleRec(menu, RED);
|
||||
DrawRectangleRec(grid, GRAY);
|
||||
DrawRectangleRec(grid, (Color) {
|
||||
.r = 0xFF, .g = 0xDA, .b = 0x2E, .a = 255
|
||||
});
|
||||
|
||||
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);
|
||||
DrawTexture(
|
||||
tile_texture,
|
||||
grid.x + grid.width/nb_cell * x,
|
||||
grid.y + grid.height/nb_cell * y,
|
||||
WHITE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int mouse_x = GetMouseX();
|
||||
int mouse_y = GetMouseY();
|
||||
int grid_x = (int) grid.x;
|
||||
int grid_y = (int) grid.y;
|
||||
|
||||
mouse_x = max(mouse_x, grid_x);
|
||||
mouse_x = min(mouse_x, grid_x + grid.width - tile_texture.width);
|
||||
mouse_y = max(mouse_y, grid_y);
|
||||
mouse_y = min(mouse_y, grid_y + grid.height - tile_texture.height);
|
||||
|
||||
mouse_x -= (mouse_x - grid_x) % tile_texture.width;
|
||||
mouse_y -= (mouse_y - grid_y) % tile_texture.height;
|
||||
|
||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
DrawTexture(mine_texture, mouse_x, mouse_y, WHITE);
|
||||
} else {
|
||||
DrawTexture(tile_hover_texture, mouse_x, mouse_y, WHITE);
|
||||
}
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
|
Binary file not shown.
Before ![]() (image error) Size: 5.0 KiB After ![]() (image error) Size: 6.5 KiB ![]() ![]() |
|
@ -27,13 +27,13 @@
|
|||
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:zoom="1.5518659"
|
||||
inkscape:cx="162.38517"
|
||||
inkscape:cy="204.27023"
|
||||
inkscape:window-width="1892"
|
||||
inkscape:window-height="1027"
|
||||
inkscape:window-x="10"
|
||||
inkscape:window-y="10"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
|
@ -51,6 +51,13 @@
|
|||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<rect
|
||||
style="fill:#fff0ad;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;paint-order:markers fill stroke"
|
||||
id="rect501"
|
||||
width="162.80766"
|
||||
height="168.88773"
|
||||
x="-16.770073"
|
||||
y="-22.19039" />
|
||||
<ellipse
|
||||
style="fill:#000000;stroke:#000000;stroke-width:0.223074;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers"
|
||||
id="path111"
|
||||
|
|
Before (image error) Size: 2.8 KiB After (image error) Size: 3.1 KiB |
Binary file not shown.
After ![]() (image error) Size: 3.0 KiB |
|
@ -0,0 +1,82 @@
|
|||
<?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.29166 132.29167"
|
||||
version="1.1"
|
||||
id="svg5"
|
||||
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||
sodipodi:docname="tile.svg"
|
||||
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="356.31784"
|
||||
inkscape:cy="373.63252"
|
||||
inkscape:window-width="1892"
|
||||
inkscape:window-height="1027"
|
||||
inkscape:window-x="10"
|
||||
inkscape:window-y="10"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs2" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<rect
|
||||
style="fill:#fff0ae;stroke:#ffffff;stroke-width:0;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers;fill-opacity:1;stroke-dasharray:none"
|
||||
id="rect111"
|
||||
width="158.69943"
|
||||
height="158.15874"
|
||||
x="-14.172204"
|
||||
y="-13.146079" />
|
||||
<rect
|
||||
style="fill:#ffe672;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:markers fill stroke"
|
||||
id="rect11512"
|
||||
width="327.30954"
|
||||
height="57.368855"
|
||||
x="-94.705956"
|
||||
y="-41.261234" />
|
||||
<rect
|
||||
style="fill:#ffe672;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:markers fill stroke"
|
||||
id="rect11512-6"
|
||||
width="327.30954"
|
||||
height="57.368855"
|
||||
x="-81.304237"
|
||||
y="116.49409" />
|
||||
<rect
|
||||
style="fill:#ffd932;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:markers fill stroke"
|
||||
id="rect10047"
|
||||
width="40.782703"
|
||||
height="132.2505"
|
||||
x="-20.619867"
|
||||
y="0.024440518"
|
||||
ry="16.955109"
|
||||
rx="20.391352" />
|
||||
<rect
|
||||
style="fill:#ffd932;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:markers fill stroke"
|
||||
id="rect10047-3"
|
||||
width="40.782703"
|
||||
height="132.2505"
|
||||
x="111.92817"
|
||||
y="0.012594922"
|
||||
ry="16.955109"
|
||||
rx="20.391352" />
|
||||
</g>
|
||||
</svg>
|
After (image error) Size: 2.8 KiB |
Binary file not shown.
After ![]() (image error) Size: 4.4 KiB |
|
@ -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.29166 132.29167"
|
||||
version="1.1"
|
||||
id="svg5"
|
||||
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||
sodipodi:docname="tile_hover.svg"
|
||||
inkscape:export-filename="tile_hover.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96"
|
||||
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="1.0973349"
|
||||
inkscape:cx="230.5586"
|
||||
inkscape:cy="262.45406"
|
||||
inkscape:window-width="1892"
|
||||
inkscape:window-height="1027"
|
||||
inkscape:window-x="10"
|
||||
inkscape:window-y="10"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs2" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<rect
|
||||
style="fill:#ffaeae;stroke:#ffffff;stroke-width:0;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers;fill-opacity:1;stroke-dasharray:none"
|
||||
id="rect111"
|
||||
width="158.69943"
|
||||
height="158.15874"
|
||||
x="-14.172204"
|
||||
y="-13.146079" />
|
||||
<rect
|
||||
style="fill:#ff7272;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:markers fill stroke"
|
||||
id="rect11512"
|
||||
width="327.30954"
|
||||
height="57.368855"
|
||||
x="-95.280823"
|
||||
y="-45.115654" />
|
||||
<rect
|
||||
style="fill:#ff7272;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:markers fill stroke"
|
||||
id="rect11512-6"
|
||||
width="327.30954"
|
||||
height="57.368855"
|
||||
x="-80.904198"
|
||||
y="119.37068" />
|
||||
<rect
|
||||
style="fill:#ff3232;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:markers fill stroke"
|
||||
id="rect10047"
|
||||
width="40.782703"
|
||||
height="138.08026"
|
||||
x="-31.739614"
|
||||
y="-2.9249413"
|
||||
ry="16.955109"
|
||||
rx="20.391352" />
|
||||
<rect
|
||||
style="fill:#ff3232;fill-opacity:1;stroke:#ffffff;stroke-width:0;stroke-linecap:square;stroke-linejoin:bevel;stroke-dasharray:none;paint-order:markers fill stroke"
|
||||
id="rect10047-3"
|
||||
width="42.631603"
|
||||
height="138.24614"
|
||||
x="123.45546"
|
||||
y="-2.9134312"
|
||||
ry="16.955109"
|
||||
rx="20.391352" />
|
||||
</g>
|
||||
</svg>
|
After (image error) Size: 2.9 KiB |
Loading…
Reference in New Issue