summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-04-25 12:05:14 +0200
committerkdx <kikoodx@paranoici.org>2023-04-25 12:05:14 +0200
commit6c8801429466c8bcf176cddede7a2c3e38bd9a42 (patch)
tree77c1b1c7c9e17be6401325148ac084b0afef58dc
parentd8f6cc615a0c856b017c7112ec7e7c8088227c5f (diff)
downloadpx-6c8801429466c8bcf176cddede7a2c3e38bd9a42.tar.gz
spr flip
-rw-r--r--src/main.c2
-rw-r--r--src/px.c8
-rw-r--r--src/px.h5
3 files changed, 11 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 5202e2b..2ed9528 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
diff --git a/src/px.c b/src/px.c
index 7aedac9..c7a3573 100644
--- a/src/px.c
+++ b/src/px.c
@@ -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);
diff --git a/src/px.h b/src/px.h
index 35ea8ba..dbbfc94 100644
--- a/src/px.h
+++ b/src/px.h
@@ -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. */