diff options
author | kdx <kikoodx@paranoici.org> | 2023-04-25 12:05:14 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-04-25 12:05:14 +0200 |
commit | 6c8801429466c8bcf176cddede7a2c3e38bd9a42 (patch) | |
tree | 77c1b1c7c9e17be6401325148ac084b0afef58dc | |
parent | d8f6cc615a0c856b017c7112ec7e7c8088227c5f (diff) | |
download | px-6c8801429466c8bcf176cddede7a2c3e38bd9a42.tar.gz |
spr flip
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/px.c | 8 | ||||
-rw-r--r-- | src/px.h | 5 |
3 files changed, 11 insertions, 4 deletions
@@ -52,7 +52,7 @@ main(void) pxPal(3, 11); pxPalt(3, true); - pxSpr(&spr, x, y + 8); + pxSpr(&spr, x, y + 8, .flip_x=true, .flip_y=true); pxPset(0, 0, 10); pxPset(1, 0, 10); @@ -140,8 +140,12 @@ _pxSpr(const PxSprArgs *args) for (int x = 0; x < w; x++) { const int dx = x + args->x; const int dy = y + args->y; - const int ix = x + args->ix; - const int iy = y + args->iy; + int ix = args->ix + ((args->flip_x) + ? (w - x - 1) + : (x)); + int iy = args->iy + ((args->flip_y) + ? (h - y - 1) + : (y)); const PxCol c = args->spr->data[ix + iy * args->spr->w]; if (!pxpal[c].t) pxPset(dx, dy, c); @@ -29,6 +29,8 @@ typedef struct { int iy; int w; int h; + bool flip_x; + bool flip_y; } PxSprArgs; typedef struct { @@ -73,7 +75,8 @@ void pxRectfill(int x0, int y0, int x1, int y1, PxCol col); /* Draw sprite. */ #define pxSpr(...) _pxSpr(&(const PxSprArgs){ \ - .ix=0, .iy=0, .w=-1, .h=-1, ._=0, __VA_ARGS__}) + .x=0, .y=0, .ix=0, .iy=0, .w=-1, .h=-1, .flip_x=false, .flip_x=false, \ + ._=0, __VA_ARGS__}) void _pxSpr(const PxSprArgs *args); /* Bind palette index to new color. */ |