smiley clickable
This commit is contained in:
parent
55b27a1be9
commit
116ad70894
71
main.c
71
main.c
|
@ -214,6 +214,23 @@ void zero_click(int x, int y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int collision(Rectangle rec, int x, int y)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
x > rec.x && x < rec.x + rec.width &&
|
||||||
|
y > rec.y && y < rec.y + rec.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reload_game(void)
|
||||||
|
{
|
||||||
|
game_state = PLAYING;
|
||||||
|
memset(game, 0, game_cap);
|
||||||
|
memset(discover, 0, game_cap);
|
||||||
|
memset(zero, 0, game_cap);
|
||||||
|
fill_game();
|
||||||
|
screen_resize_handle();
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
@ -282,12 +299,7 @@ int main(void)
|
||||||
resize = 1;
|
resize = 1;
|
||||||
}
|
}
|
||||||
if (resize || IsKeyPressed(KEY_R)) {
|
if (resize || IsKeyPressed(KEY_R)) {
|
||||||
game_state = PLAYING;
|
reload_game();
|
||||||
memset(game, 0, game_cap);
|
|
||||||
memset(discover, 0, game_cap);
|
|
||||||
memset(zero, 0, game_cap);
|
|
||||||
fill_game();
|
|
||||||
screen_resize_handle();
|
|
||||||
resize = 0;
|
resize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,12 +321,9 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawRectangleRec(menu, menu_color);
|
DrawRectangleRec(menu, menu_color);
|
||||||
DrawTexture(
|
|
||||||
*menu_smiley,
|
Vec2i smiley_coord = {menu.width/2 - menu_smiley->width/2, 0};
|
||||||
menu.width/2 - menu_smiley->width/2,
|
DrawTexture( *menu_smiley, smiley_coord.x, smiley_coord.y, WHITE);
|
||||||
0,
|
|
||||||
WHITE
|
|
||||||
);
|
|
||||||
DrawTexture(
|
DrawTexture(
|
||||||
camera_texture,
|
camera_texture,
|
||||||
menu.width/2 - menu_smiley->width/2 - camera_texture.width -10,
|
menu.width/2 - menu_smiley->width/2 - camera_texture.width -10,
|
||||||
|
@ -368,21 +377,25 @@ int main(void)
|
||||||
int mouse_y = GetMouseY();
|
int mouse_y = GetMouseY();
|
||||||
int grid_x = (int) grid.x;
|
int grid_x = (int) grid.x;
|
||||||
int grid_y = (int) grid.y;
|
int grid_y = (int) grid.y;
|
||||||
|
int mouse_in_grid = 0;
|
||||||
|
int mouse_in_menu = 0;
|
||||||
|
|
||||||
mouse_x = max(mouse_x, grid_x);
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
mouse_x = min(mouse_x, grid_x + grid.width -
|
if (grid_x < mouse_x && mouse_x < grid_x + grid.width &&
|
||||||
(grid_len/game_size.x));
|
grid_y < mouse_y && mouse_y < grid_y + grid.height)
|
||||||
|
{
|
||||||
|
mouse_in_grid = 1;
|
||||||
|
} else if (0 < mouse_x && mouse_x < menu.width &&
|
||||||
|
0 < mouse_y && mouse_y < menu.height)
|
||||||
|
{
|
||||||
|
mouse_in_menu = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mouse_y = max(mouse_y, grid_y);
|
if (mouse_in_grid && game_state == PLAYING) {
|
||||||
mouse_y = min(mouse_y, grid_y + grid.height -
|
mouse_x = ((float)(mouse_x - grid_x) / grid_len) * game_size.x;
|
||||||
(grid_len/game_size.y));
|
mouse_y = ((float)(mouse_y - grid_y) / grid_len) * game_size.y;
|
||||||
|
|
||||||
mouse_x = ((float) (mouse_x - grid_x) / grid_len) * game_size.x;
|
|
||||||
mouse_y = ((float) (mouse_y - grid_y) / grid_len) * game_size.y;
|
|
||||||
|
|
||||||
if (game_state == PLAYING &&
|
|
||||||
IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
|
||||||
{
|
|
||||||
discover[mouse_y][mouse_x] = 1;
|
discover[mouse_y][mouse_x] = 1;
|
||||||
|
|
||||||
zero_click(mouse_x, mouse_y);
|
zero_click(mouse_x, mouse_y);
|
||||||
|
@ -402,6 +415,16 @@ int main(void)
|
||||||
memset(discover, 1, game_cap);
|
memset(discover, 1, game_cap);
|
||||||
game_state = LOSE;
|
game_state = LOSE;
|
||||||
}
|
}
|
||||||
|
} else if (mouse_in_menu) {
|
||||||
|
if (collision(
|
||||||
|
(Rectangle){
|
||||||
|
smiley_coord.x, smiley_coord.y,
|
||||||
|
playing_texture.width, playing_texture.height
|
||||||
|
}, mouse_x, mouse_y)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
reload_game();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
Loading…
Reference in New Issue