diff options
author | kdx <kikoodx@paranoici.org> | 2023-04-16 12:58:50 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-04-16 12:58:50 +0200 |
commit | 25b45b7354db9c9a36c56cf6aeee58dca02a1b73 (patch) | |
tree | b942b1f46084fcf9cb9d92204edd22d1455fc315 | |
parent | dbe29daa8287a0adf67edc77c42efb6505b2399a (diff) | |
download | px-25b45b7354db9c9a36c56cf6aeee58dca02a1b73.tar.gz |
transparency
-rw-r--r-- | src/main.c | 13 | ||||
-rw-r--r-- | src/px.c | 46 | ||||
-rw-r--r-- | src/px.h | 13 |
3 files changed, 47 insertions, 25 deletions
@@ -33,16 +33,17 @@ main(void) y -= TZR_IsKeyDown(SDL_SCANCODE_W); y += TZR_IsKeyDown(SDL_SCANCODE_S); - pxClipReset(); pxCls(1); + + pxPalt(); + pxSpr(&spr, x, y); + + pxPalt(0); + pxSpr(&spr, x, y + 8); + pxPset(0, 0, 10); pxPset(1, 0, 10); pxPset(0, 1, pxPget(0, 0)); - pxClip(25, 12, 32, 69); - pxCls(2); - pxClipReset(); - pxSpr(&spr, x, y); - pxSpr(&spr, 24, 8, .iy=1, .h=2); TZR_DrawBegin(); pxRender(); @@ -4,22 +4,22 @@ PxCol pxbuf[PX_WIDTH * PX_HEIGHT] = {0}; PxPal pxpal[256] = { /* PICO-8 palette */ - {0x00, 0x00, 0x00}, - {0x1d, 0x2b, 0x53}, - {0x7e, 0x25, 0x53}, - {0x00, 0x87, 0x51}, - {0xab, 0x52, 0x36}, - {0x5f, 0x57, 0x4f}, - {0xc2, 0xc3, 0xc7}, - {0xff, 0xf1, 0xe8}, - {0xff, 0x00, 0x4d}, - {0xff, 0xa3, 0x00}, - {0xff, 0xec, 0x27}, - {0x00, 0xe4, 0x36}, - {0x29, 0xad, 0xff}, - {0x83, 0x76, 0x9c}, - {0xff, 0x77, 0xa8}, - {0xff, 0xcc, 0xaa}, + {0x00, 0x00, 0x00, false}, + {0x1d, 0x2b, 0x53, false}, + {0x7e, 0x25, 0x53, false}, + {0x00, 0x87, 0x51, false}, + {0xab, 0x52, 0x36, false}, + {0x5f, 0x57, 0x4f, false}, + {0xc2, 0xc3, 0xc7, false}, + {0xff, 0xf1, 0xe8, false}, + {0xff, 0x00, 0x4d, false}, + {0xff, 0xa3, 0x00, false}, + {0xff, 0xec, 0x27, false}, + {0x00, 0xe4, 0x36, false}, + {0x29, 0xad, 0xff, false}, + {0x83, 0x76, 0x9c, false}, + {0xff, 0x77, 0xa8, false}, + {0xff, 0xcc, 0xaa, false}, }; static struct { int x; @@ -90,8 +90,6 @@ _pxSpr(const PxSprArgs *args) int h = (args->h < 0) ? (args->spr->h) : (args->h); h = pxMin(h, args->spr->h - args->iy); - printf("%d %d\n", w, h); - for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { const int dx = x + args->x; @@ -99,12 +97,22 @@ _pxSpr(const PxSprArgs *args) const int ix = x + args->ix; const int iy = y + args->iy; const PxCol c = args->spr->data[ix + iy * args->spr->w]; - if (c) + if (!pxpal[c].t) pxPset(dx, dy, c); } } } +void +_pxPalt(const PxPaltArgs *args) +{ + if (args->col < 0 || args->col > 255) + for (int i = 0; i < 256; i++) + pxpal[i].t = false; + else + pxpal[args->col].t = args->t; +} + int pxMin(int a, int b) { @@ -1,5 +1,6 @@ #pragma once #include <stdint.h> +#include <stdbool.h> enum { PX_WIDTH = 128, @@ -10,6 +11,7 @@ typedef uint8_t PxCol; typedef struct { uint8_t r, g, b; + bool t; /* tranparency */ } PxPal; typedef struct { @@ -28,6 +30,12 @@ typedef struct { int h; } PxSprArgs; +typedef struct { + int _; + int col; + bool t; +} PxPaltArgs; + extern PxCol pxbuf[PX_WIDTH * PX_HEIGHT]; extern PxPal pxpal[256]; @@ -54,6 +62,11 @@ PxCol pxPget(int x, int y); .ix=0, .iy=0, .w=-1, .h=-1, ._=0, __VA_ARGS__}) void _pxSpr(const PxSprArgs *args); +/* Set palette tranparency. */ +#define pxPalt(...) _pxPalt(&(const PxPaltArgs){ \ + .col=-1, .t=true, ._=0, __VA_ARGS__}) +void _pxPalt(const PxPaltArgs *args); + /*** MATH ***/ int pxMin(int a, int b); int pxMax(int a, int b); |