summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-05-03 13:30:44 +0200
committerkdx <kikoodx@paranoici.org>2023-05-03 13:30:44 +0200
commit082e91190c8dff9393c047444644fc6f7e4280de (patch)
tree95619f7d2a6aab0111c8c5aaa373842a3d38860d
parentca2f55ac494245422e27fe272dddc5092ce0afc6 (diff)
downloadstudy-sttky-082e91190c8dff9393c047444644fc6f7e4280de.tar.gz
px rendering
-rw-r--r--Tupfile7
-rw-r--r--map/game.tmj12
-rw-r--r--map/tset.tsj14
-rw-r--r--res/pal.pngbin0 -> 75 bytes
-rw-r--r--res/player.pngbin0 -> 89 bytes
-rw-r--r--res/tset.pngbin98 -> 86 bytes
-rw-r--r--src/cfg.h2
-rw-r--r--src/entityimpl.h1
-rw-r--r--src/main.c15
-rw-r--r--src/map.c6
-rw-r--r--src/player.c8
-rw-r--r--src/px.c9
-rw-r--r--src/px.h8
13 files changed, 50 insertions, 32 deletions
diff --git a/Tupfile b/Tupfile
index 5b0cbd1..0c918cb 100644
--- a/Tupfile
+++ b/Tupfile
@@ -1,16 +1,17 @@
CC = gcc
LD = $(CC) -fuse-ld=mold
-CFLAGS = -O3 -std=c99 -Wall -Wextra -Wno-override-init \
- -DPX_WIDTH=400 -DPX_HEIGHT=224
+CFLAGS = -O0 -g3 -std=c99 -Wall -Wextra -Wno-override-init \
+ -DPX_WIDTH=234 -DPX_HEIGHT=144
LDFLAGS = -lm -lSDL2 -lSDL2_image -lSDL2_mixer
# codebase
: foreach map/*.tmj |> tiled2c %f embed_%B_tmj >%o |> build/embed_%B_tmj.c
: foreach map/*.tsj |> tiled2c %f embed_%B_tsj >%o |> build/embed_%B_tsj.c
+: foreach res/*.png res/pal.png |> pximg spr_%B %f res/pal.png >%o |> build/spr_%B.c
+: res/pal.png |> pxpal res/pal.png >%o |> build/pxpal.c
: foreach src/*.c |> $(CC) $(CFLAGS) -c -o %o %f |> build/%B.o
: foreach build/*.c |> $(CC) $(CFLAGS) -Isrc -c -o %o %f |> build/%B.o
: build/*.o |> $(LD) -o %o %f $(LDFLAGS) |> build/study-sttky
# assets
: foreach res/*.wav |> cp %f %o |> build/%f
-: foreach res/*.png |> convert %f %o |> build/res/%B.bmp
diff --git a/map/game.tmj b/map/game.tmj
index f4c7dde..f66075c 100644
--- a/map/game.tmj
+++ b/map/game.tmj
@@ -33,15 +33,15 @@
"name":"Object Layer 1",
"objects":[
{
- "height":16,
+ "height":5,
"id":1,
"name":"player",
"rotation":0,
"type":"",
"visible":true,
- "width":16,
- "x":176,
- "y":144
+ "width":5,
+ "x":103.5,
+ "y":94.5
}],
"opacity":1,
"type":"objectgroup",
@@ -54,13 +54,13 @@
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.10.1",
- "tileheight":16,
+ "tileheight":9,
"tilesets":[
{
"firstgid":1,
"source":"tset.tsj"
}],
- "tilewidth":16,
+ "tilewidth":9,
"type":"map",
"version":"1.10",
"width":25
diff --git a/map/tset.tsj b/map/tset.tsj
index 54a7ecf..e455c7c 100644
--- a/map/tset.tsj
+++ b/map/tset.tsj
@@ -1,13 +1,19 @@
-{ "columns":2,
+{ "columns":3,
+ "grid":
+ {
+ "height":16,
+ "orientation":"orthogonal",
+ "width":16
+ },
"image":"..\/res\/tset.png",
"imageheight":16,
"imagewidth":32,
"margin":0,
"name":"tset",
"spacing":0,
- "tilecount":2,
+ "tilecount":3,
"tiledversion":"1.10.1",
- "tileheight":16,
+ "tileheight":9,
"tiles":[
{
"id":0,
@@ -17,7 +23,7 @@
"id":1,
"type":"spike"
}],
- "tilewidth":16,
+ "tilewidth":9,
"type":"tileset",
"version":"1.10"
} \ No newline at end of file
diff --git a/res/pal.png b/res/pal.png
new file mode 100644
index 0000000..e35b859
--- /dev/null
+++ b/res/pal.png
Binary files differ
diff --git a/res/player.png b/res/player.png
new file mode 100644
index 0000000..1b00f2d
--- /dev/null
+++ b/res/player.png
Binary files differ
diff --git a/res/tset.png b/res/tset.png
index 3cc3164..f4193a3 100644
--- a/res/tset.png
+++ b/res/tset.png
Binary files differ
diff --git a/src/cfg.h b/src/cfg.h
index 97d457b..e5b123c 100644
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -2,6 +2,6 @@
#include "px.h"
#define TARGET_FPS 30
-#define TSIZE 16
+#define TSIZE 9
#define DWIDTH PX_WIDTH
#define DHEIGHT PX_HEIGHT
diff --git a/src/entityimpl.h b/src/entityimpl.h
index a8b0f75..3e27b40 100644
--- a/src/entityimpl.h
+++ b/src/entityimpl.h
@@ -4,6 +4,7 @@
#include "TZR.h"
#include "entitytag.h"
#include "camera.h"
+#include "px.h"
#include <string.h>
#define IMPL_UNUSED (void)this, (void)g
diff --git a/src/main.c b/src/main.c
index 388fb02..e8bbc60 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,15 +29,17 @@ main(int argc, char **argv)
.light_system=false,
.title="goty of the day"))
return 1;
- srand(time(NULL));
-
- Mix_AllocateChannels(32);
-
if (atexit(deinit)) {
perror("main:atexit");
deinit();
return 1;
}
+ if (pxInit())
+ return 1;
+
+ srand(time(NULL));
+
+ Mix_AllocateChannels(32);
if ((game = malloc(sizeof(*game))) == NULL) {
perror("main:malloc");
@@ -54,6 +56,7 @@ deinit(void)
{
if (game != NULL)
free(game);
+ pxDeinit();
TZR_Quit();
}
@@ -79,9 +82,9 @@ main_loop(void *udata)
if (TZR_DrawBegin())
return 1;
- TZR_DrawSetColor8(0x03, 0x06, 0x16, 0xff);
- TZR_DrawClear();
+ pxCls(0);
game_draw(game);
+ pxFlip();
if (TZR_DrawEnd())
return 1;
return 0;
diff --git a/src/map.c b/src/map.c
index 311db7f..af25e74 100644
--- a/src/map.c
+++ b/src/map.c
@@ -82,8 +82,8 @@ map_get_px(int x, int y, unsigned int type)
static void
draw_layer(const Tiled2cLayer *layer)
{
- const int tset = TZR_RES("res/tset.bmp");
- const int tset_w = TZR_GetImageWidth(tset);
+ extern const PxSpr spr_tset;
+ const int tset_w = spr_tset.w;
const int ox = camera_x(layer->parallaxx);
const int oy = camera_y(layer->parallaxy);
for (int y = 0; y < map_height(); y++)
@@ -97,7 +97,7 @@ draw_layer(const Tiled2cLayer *layer)
const int dy = oy + y * TSIZE;
const int ix = vtile % (tset_w / TSIZE) * TSIZE;
const int iy = vtile / (tset_w / TSIZE) * TSIZE;
- TZR_DrawImage(tset, dx, dy, ix, iy, TSIZE, TSIZE);
+ pxSpr(&spr_tset, dx, dy, ix, iy, TSIZE, TSIZE);
}
}
diff --git a/src/player.c b/src/player.c
index d98bdee..3fdc7b3 100644
--- a/src/player.c
+++ b/src/player.c
@@ -2,6 +2,7 @@
IMPL_INIT(player, 0) {
IMPL_UNUSED;
+ this->height = this->width = 5;
}
IMPL(update) {
@@ -23,7 +24,8 @@ IMPL(update) {
IMPL(draw) {
IMPL_UNUSED;
- TZR_DrawSetColor(1, 1, 1);
- TZR_DrawRectangle(this->pos[0], this->pos[1], this->width, this->height,
- .center=true);
+ extern const PxSpr spr_player;
+ const int dx = this->pos[0] - 2 - camera_x(1);
+ const int dy = this->pos[1] - 2 - camera_y(1);
+ pxSpr(&spr_player, dx, dy, 0, 0, -1, -1, false, false);
}
diff --git a/src/px.c b/src/px.c
index 5c1af9b..694c789 100644
--- a/src/px.c
+++ b/src/px.c
@@ -40,7 +40,7 @@ pxInit(void)
PX_WIDTH, PX_HEIGHT);
if (pxtexture == NULL) {
fprintf(stderr, "%s\n", SDL_GetError());
- return 1;
+ return -1;
}
return 0;
}
@@ -54,12 +54,15 @@ pxDeinit(void)
}
}
-void
+int
pxFlip(void)
{
uint8_t *pixels = NULL;
int pitch = 0;
- SDL_LockTexture(pxtexture, NULL, (void **)&pixels, &pitch);
+ if (SDL_LockTexture(pxtexture, NULL, (void **)&pixels, &pitch)) {
+ fprintf(stderr, "%s\n", SDL_GetError());
+ return -1;
+ }
for (int y = 0; y < PX_HEIGHT; y++) {
for (int x = 0; x < PX_WIDTH; x++) {
diff --git a/src/px.h b/src/px.h
index f413bdc..cc59c7f 100644
--- a/src/px.h
+++ b/src/px.h
@@ -52,14 +52,16 @@ typedef struct {
extern PxCol pxbuf[PX_WIDTH * PX_HEIGHT];
extern PxPal pxpal[256];
-/* Return -1 on error. Should be called after TZR_Init. */
+/* Return -1 on error.
+ * Should be called after TZR_Init. */
int pxInit(void);
/* Should be called before TZR_Quit. */
void pxDeinit(void);
-/* Should be called between TZR_DrawBegin and TZR_DrawEnd. */
-void pxFlip(void);
+/* Return -1 on error.
+ * Should be called between TZR_DrawBegin and TZR_DrawEnd. */
+int pxFlip(void);
/*** DRAW ***/
/* Fill the clipping region with color 'c'. */