From 102e4722a3ddcc3702c4445f4e746bc888b83335 Mon Sep 17 00:00:00 2001 From: Juan Manuel Tomas Date: Sun, 23 Jan 2022 00:42:51 -0300 Subject: Parameterize PainMask on mask dimensions --- main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 464bcf4..ebae9da 100644 --- a/main.c +++ b/main.c @@ -33,14 +33,14 @@ SDL_Texture *CreateTiledTexture(SDL_Renderer *context, const char *filename, int return texture; } -void PaintMask(float *mask, float x, float y, float color, float size) { +void PaintMask(float *mask, int width, int height, float x, float y, float color, float size) { for (int j = y - size; j < y + size; j++) { for (int i = x - size; i < x + size; i++) { float dj = y - j; float di = x - i; - if (i > 0 && i < WINDOW_W && j > 0 && j < WINDOW_H + if (i > 0 && i < width && j > 0 && j < height && dj * dj + di * di <= size * size / 2) { - size_t index = i + j * WINDOW_W; + size_t index = i + j * width; mask[index] = color; } } @@ -92,9 +92,9 @@ void GameMain(SDL_Renderer *context) { Uint32 mouse_state = SDL_GetMouseState(&mouse_x, &mouse_y); float size = 20; if (mouse_state & SDL_BUTTON_LMASK) { - PaintMask(mask, mouse_x, WINDOW_H - mouse_y, 1.0, size); + PaintMask(mask, WINDOW_W, WINDOW_H, mouse_x, WINDOW_H - mouse_y, 1.0, size); } else if (mouse_state & SDL_BUTTON_RMASK) { - PaintMask(mask, mouse_x, WINDOW_H - mouse_y, 0.0, size); + PaintMask(mask, WINDOW_W, WINDOW_H, mouse_x, WINDOW_H - mouse_y, 0.0, size); } const Uint8 *keys = SDL_GetKeyboardState(0); -- cgit v1.2.3