diff options
author | kdx <kikoodx@paranoici.org> | 2023-11-24 08:30:06 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-11-24 08:30:21 +0100 |
commit | 659c92f1b6eb6646334e66a4f1204157f5855faa (patch) | |
tree | e04b0e4d44d8f9737e94935b9533c756e7aad50a | |
parent | f6d8a551c902b1e61028eecc8061d5e50a230572 (diff) | |
download | tzr-659c92f1b6eb6646334e66a4f1204157f5855faa.tar.gz |
camera system
-rwxr-xr-x | create_TZR.h.sh | 1 | ||||
-rw-r--r-- | headers/TZR_camera.h | 5 | ||||
-rw-r--r-- | headers/TZR_globals.h | 2 | ||||
-rw-r--r-- | sources/TZR_DestroyResource.c | 6 | ||||
-rw-r--r-- | sources/TZR_DrawImage.c | 4 | ||||
-rw-r--r-- | sources/TZR_DrawLine.c | 4 | ||||
-rw-r--r-- | sources/TZR_DrawPoint.c | 2 | ||||
-rw-r--r-- | sources/TZR_DrawRectangle.c | 4 | ||||
-rw-r--r-- | sources/TZR_GetCameraX.c | 8 | ||||
-rw-r--r-- | sources/TZR_GetCameraY.c | 8 | ||||
-rw-r--r-- | sources/TZR_SetCamera.c | 9 | ||||
-rw-r--r-- | sources/globals.c | 2 |
12 files changed, 51 insertions, 4 deletions
diff --git a/create_TZR.h.sh b/create_TZR.h.sh index 1d1c88e..f40a939 100755 --- a/create_TZR.h.sh +++ b/create_TZR.h.sh @@ -19,6 +19,7 @@ HEADER=TZR_render ProcessHeader HEADER=TZR_keystate ProcessHeader HEADER=TZR_mouse ProcessHeader HEADER=TZR_joystick ProcessHeader +HEADER=TZR_camera ProcessHeader HEADER=TZR ProcessHeader cp _head.h "$BUILDDIR/out" diff --git a/headers/TZR_camera.h b/headers/TZR_camera.h new file mode 100644 index 0000000..16a536a --- /dev/null +++ b/headers/TZR_camera.h @@ -0,0 +1,5 @@ +#pragma once + +void TZR_SetCamera(float x, float y); +int TZR_GetCameraX(void); +int TZR_GetCameraY(void); diff --git a/headers/TZR_globals.h b/headers/TZR_globals.h index 3c2758e..208ad0b 100644 --- a/headers/TZR_globals.h +++ b/headers/TZR_globals.h @@ -29,6 +29,8 @@ extern TZR_Joystick *___tzr_joysticks; extern size_t ___tzr_joysticks_capacity; extern size_t ___tzr_joysticks_size; extern SDL_BlendMode ___tzr_blendmode; +extern int ___tzr_camera_x; +extern int ___tzr_camera_y; #ifdef TZR_SOLOUD extern Soloud ___tzr_soloud; diff --git a/sources/TZR_DestroyResource.c b/sources/TZR_DestroyResource.c index 7536017..de235e4 100644 --- a/sources/TZR_DestroyResource.c +++ b/sources/TZR_DestroyResource.c @@ -24,6 +24,12 @@ TZR_DestroyResource(TZR_Resource *res, int free_path) Mix_FreeChunk(res->sound.ptr); #endif break; + case TZR_RES_FONT: +#ifdef TZR_TTF + if (res->ttf.ptr != NULL) + TTF_CloseFont(res->ttf.ptr); +#endif + break; default: fprintf(stderr, "unknown resource type %u\n", res->type); break; diff --git a/sources/TZR_DrawImage.c b/sources/TZR_DrawImage.c index c968a52..6d9ce1f 100644 --- a/sources/TZR_DrawImage.c +++ b/sources/TZR_DrawImage.c @@ -64,8 +64,8 @@ _TZR_DrawImage(const TZR_DrawImageArgs *args) const int y = args->y - (scale_y < 0.0f ? height : 0); const SDL_Rect dest = { - x - (args->center ? (simg_width * scale_x / 2) : 0), - y - (args->center ? (simg_height * scale_y / 2) : 0), + x - (args->center ? (simg_width * scale_x / 2) : 0) + TZR_GetCameraX(), + y - (args->center ? (simg_height * scale_y / 2) : 0) + TZR_GetCameraY(), width, height }; diff --git a/sources/TZR_DrawLine.c b/sources/TZR_DrawLine.c index 274bcbc..78c218f 100644 --- a/sources/TZR_DrawLine.c +++ b/sources/TZR_DrawLine.c @@ -6,6 +6,10 @@ int TZR_DrawLine(int x0, int y0, int x1, int y1) { + x0 += TZR_GetCameraX(); + y0 += TZR_GetCameraY(); + x1 += TZR_GetCameraX(); + y1 += TZR_GetCameraY(); if (SDL_RenderDrawLine(___tzr_renderer, x0, y0, x1, y1) < 0) return sdl_error(-1); return 0; diff --git a/sources/TZR_DrawPoint.c b/sources/TZR_DrawPoint.c index 0d44c96..f33bc74 100644 --- a/sources/TZR_DrawPoint.c +++ b/sources/TZR_DrawPoint.c @@ -6,6 +6,8 @@ int TZR_DrawPoint(int x, int y) { + x += TZR_GetCameraX(); + y += TZR_GetCameraY(); if (SDL_RenderDrawPoint(___tzr_renderer, x, y) < 0) return sdl_error(-1); return 0; diff --git a/sources/TZR_DrawRectangle.c b/sources/TZR_DrawRectangle.c index 0ea81fa..e5ecf5f 100644 --- a/sources/TZR_DrawRectangle.c +++ b/sources/TZR_DrawRectangle.c @@ -7,8 +7,8 @@ int _TZR_DrawRectangle(const TZR_DrawRectangleArgs *args) { const SDL_Rect rect = { - args->x - args->center * (args->w / 2), - args->y - args->center * (args->h / 2), + args->x - args->center * (args->w / 2) + TZR_GetCameraX(), + args->y - args->center * (args->h / 2) + TZR_GetCameraY(), args->w, args->h }; diff --git a/sources/TZR_GetCameraX.c b/sources/TZR_GetCameraX.c new file mode 100644 index 0000000..ee9c63d --- /dev/null +++ b/sources/TZR_GetCameraX.c @@ -0,0 +1,8 @@ +#include "TZR_camera.h" +#include "TZR_globals.h" + +int +TZR_GetCameraX(void) +{ + return ___tzr_camera_x; +} diff --git a/sources/TZR_GetCameraY.c b/sources/TZR_GetCameraY.c new file mode 100644 index 0000000..19bf229 --- /dev/null +++ b/sources/TZR_GetCameraY.c @@ -0,0 +1,8 @@ +#include "TZR_camera.h" +#include "TZR_globals.h" + +int +TZR_GetCameraY(void) +{ + return ___tzr_camera_y; +} diff --git a/sources/TZR_SetCamera.c b/sources/TZR_SetCamera.c new file mode 100644 index 0000000..19479e8 --- /dev/null +++ b/sources/TZR_SetCamera.c @@ -0,0 +1,9 @@ +#include "TZR_camera.h" +#include "TZR_globals.h" + +void +TZR_SetCamera(float x, float y) +{ + ___tzr_camera_x = -(int)(x + 0.5f); + ___tzr_camera_y = -(int)(y + 0.5f); +} diff --git a/sources/globals.c b/sources/globals.c index b683500..a67ebc0 100644 --- a/sources/globals.c +++ b/sources/globals.c @@ -29,6 +29,8 @@ TZR_Joystick *___tzr_joysticks = NULL; size_t ___tzr_joysticks_capacity = 0; size_t ___tzr_joysticks_size = 0; SDL_BlendMode ___tzr_blendmode = SDL_BLENDMODE_BLEND; +int ___tzr_camera_x = 0; +int ___tzr_camera_y = 0; #ifdef TZR_SOLOUD Soloud ___tzr_soloud = NULL; |