summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomas <jtomas1815@gmail.com>2022-01-20 05:18:00 -0300
committerJuan Manuel Tomas <jtomas1815@gmail.com>2022-01-20 05:18:00 -0300
commitaca708aa91f9db51a69f27e3e855b24144bd26ed (patch)
treeed0ae21dbf421ea115809c78bae1cf2fd69ccc60
parent9384448fd3e54d9d787d7c35bc1069487ab07d88 (diff)
downloadcannons-aca708aa91f9db51a69f27e3e855b24144bd26ed.tar.gz
cannons-aca708aa91f9db51a69f27e3e855b24144bd26ed.zip
Make mask brush a circle
-rwxr-xr-xbuild.sh4
-rw-r--r--main.c11
-rw-r--r--platform.c6
3 files changed, 12 insertions, 9 deletions
diff --git a/build.sh b/build.sh
index 287fd6c..8bc5d4f 100755
--- a/build.sh
+++ b/build.sh
@@ -1,4 +1,4 @@
-flags=-Wall -pedantic -O0
-gcc $flags -O0 -c main.c -o main.o && \
+flags='-Wall -pedantic -O0'
+gcc $flags -c main.c -o main.o && \
gcc main.o -lSDL2 -o main && \
./main
diff --git a/main.c b/main.c
index 9d53b94..407a1cd 100644
--- a/main.c
+++ b/main.c
@@ -4,9 +4,12 @@
#include "platform.c"
void PaintMask(float *mask, float x, float y, float color, float size) {
- for (int j = y - size / 2; j < y + size / 2; j++) {
- for (int i = x - size / 2; i < x + size / 2; i++) {
- if (i > 0 && i < WINDOW_W && j > 0 && j < WINDOW_H) {
+ 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
+ && dj * dj + di * di <= size * size / 2) {
size_t index = i + j * WINDOW_W;
mask[index] = color;
}
@@ -41,7 +44,7 @@ void GameMain() {
}
int mouse_x, mouse_y;
Uint32 mouse_state = SDL_GetMouseState(&mouse_x, &mouse_y);
- float size = 100;
+ float size = 20;
if (mouse_state & SDL_BUTTON_LMASK) {
PaintMask(mask, mouse_x, WINDOW_H - mouse_y, 1.0, size);
} else if (mouse_state & SDL_BUTTON_RMASK) {
diff --git a/platform.c b/platform.c
index 7ba6d53..24f5394 100644
--- a/platform.c
+++ b/platform.c
@@ -13,7 +13,7 @@ double GetCurrentTimestamp() {
return (double) SDL_GetTicks64() / 1000.0;
}
-SDL_Texture *createTiledTexture(SDL_Renderer *context, const char *filename, int width, int height) {
+SDL_Texture *CreateTiledTexture(SDL_Renderer *context, const char *filename, int width, int height) {
SDL_Surface *texture_surface = SDL_LoadBMP(filename);
SDL_Texture *texture_tile = SDL_CreateTextureFromSurface(context, texture_surface);
int tile_w = texture_surface->w;
@@ -48,9 +48,9 @@ void PlatformMain(void (*GameMain)(void)) {
context = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- background = createTiledTexture(context, "background.bmp", WINDOW_W, WINDOW_H);
+ background = CreateTiledTexture(context, "background.bmp", WINDOW_W, WINDOW_H);
- foreground = createTiledTexture(context, "foreground.bmp", WINDOW_W, WINDOW_H);
+ foreground = CreateTiledTexture(context, "foreground.bmp", WINDOW_W, WINDOW_H);
SDL_SetTextureBlendMode(foreground, SDL_BLENDMODE_MOD);
terrain = SDL_CreateTexture(context,