diff options
Diffstat (limited to 'sdl3_main.c')
| -rw-r--r-- | sdl3_main.c | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/sdl3_main.c b/sdl3_main.c index 93df535..a2d12f7 100644 --- a/sdl3_main.c +++ b/sdl3_main.c @@ -9,6 +9,9 @@ static void render(void); static void update(float delta); static void process_events(void); +static void renderrect(float p[2], float s[2]); +static void renderfillrect(float p[2], float s[2]); + static SDL_Window *window; static SDL_Renderer *renderer; static bool running; @@ -68,12 +71,14 @@ render(void) if(!map_data[x + map_width * y]) continue; - SDL_RenderFillRect(renderer, &(SDL_FRect) { - .x = 2 * ENTITY_SIZE * x - ENTITY_SIZE - camera_x, - .y = 2 * ENTITY_SIZE * y - ENTITY_SIZE - camera_y, - .w = 2.0 * ENTITY_SIZE, - .h = 2.0 * ENTITY_SIZE, - }); + renderfillrect( + (float[]){ + 2 * ENTITY_SIZE * x, + 2 * ENTITY_SIZE * y + }, (float[]){ + ENTITY_SIZE, + ENTITY_SIZE + }); } for(int i = 0; i < ebufi; i++) { @@ -87,12 +92,7 @@ render(void) SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); else SDL_SetRenderDrawColor(renderer, 0x88, 0x00, 0x00, 0xFF); - SDL_RenderRect(renderer, &(SDL_FRect){ - .x = e->body.pos[0] - ENTITY_SIZE - camera_x, - .y = e->body.pos[1] - ENTITY_SIZE - camera_y, - .w = ENTITY_SIZE * 2.0, - .h = ENTITY_SIZE * 2.0 - }); + renderrect(e->body.pos, e->body.size); break; case EGHOST: @@ -100,22 +100,12 @@ render(void) SDL_SetRenderDrawColor(renderer, 0xAA, 0xAA, 0xAA, 0xFF); else SDL_SetRenderDrawColor(renderer, 0x88, 0x00, 0x00, 0xFF); - SDL_RenderRect(renderer, &(SDL_FRect){ - .x = e->body.pos[0] - ENTITY_SIZE - camera_x, - .y = e->body.pos[1] - ENTITY_SIZE - camera_y, - .w = ENTITY_SIZE * 2.0, - .h = ENTITY_SIZE * 2.0 - }); + renderrect(e->body.pos, e->body.size); break; case EBULLET: SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0x00, 0xFF); - SDL_RenderRect(renderer, &(SDL_FRect){ - .x = e->body.pos[0] - BULLET_SIZE - camera_x, - .y = e->body.pos[1] - BULLET_SIZE - camera_y, - .w = BULLET_SIZE * 2.0, - .h = BULLET_SIZE * 2.0 - }); + renderrect(e->body.pos, e->body.size); break; } } @@ -166,3 +156,25 @@ process_events() } } } + +void +renderrect(float p[2], float s[2]) +{ + SDL_RenderRect(renderer, &(SDL_FRect){ + .x = p[0] - s[0] - camera_x, + .y = p[1] - s[1] - camera_y, + .w = s[0] * 2.0, + .h = s[1] * 2.0 + }); +} + +void +renderfillrect(float p[2], float s[2]) +{ + SDL_RenderFillRect(renderer, &(SDL_FRect){ + .x = p[0] - s[0] - camera_x, + .y = p[1] - s[1] - camera_y, + .w = s[0] * 2.0, + .h = s[1] * 2.0 + }); +} |
