diff options
| author | Juan Manuel Tomas <jtomas1815@gmail.com> | 2022-01-23 00:42:51 -0300 | 
|---|---|---|
| committer | Juan Manuel Tomas <jtomas1815@gmail.com> | 2022-01-23 00:42:51 -0300 | 
| commit | 102e4722a3ddcc3702c4445f4e746bc888b83335 (patch) | |
| tree | a8131d9c382907454772894de4a92ef6d027ece4 | |
| parent | aadd4703f6b8381f1218f4bb9f6c2de25f340f2c (diff) | |
| download | cannons-102e4722a3ddcc3702c4445f4e746bc888b83335.tar.gz cannons-102e4722a3ddcc3702c4445f4e746bc888b83335.zip | |
Parameterize PainMask on mask dimensions
| -rw-r--r-- | main.c | 10 | 
1 files changed, 5 insertions, 5 deletions
| @@ -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); | 
