summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-05-04 15:33:26 +0200
committerkdx <kikoodx@paranoici.org>2023-05-04 15:33:26 +0200
commit963183139997c2fe26a50399451bb47c3a3e9efc (patch)
tree5140cb0aab077052cb802a2a3d80adc323811e32
parent27a17adee2cbd332efef35e276672090c51afbf4 (diff)
downloadstudy-sttky-963183139997c2fe26a50399451bb47c3a3e9efc.tar.gz
lol
-rw-r--r--map/game.tmj38
-rw-r--r--res/font.pngbin0 -> 5690 bytes
-rw-r--r--src/camera.c7
-rw-r--r--src/font.c39
-rw-r--r--src/font.h9
-rw-r--r--src/px.c8
6 files changed, 78 insertions, 23 deletions
diff --git a/map/game.tmj b/map/game.tmj
index c1b9354..940f24f 100644
--- a/map/game.tmj
+++ b/map/game.tmj
@@ -1,29 +1,31 @@
{ "compressionlevel":-1,
- "height":14,
+ "height":16,
"infinite":false,
"layers":[
{
- "data":[2, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 1,
- 2, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 1, 0,
- 2, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0,
- 2, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 2, 0, 2, 0, 0, 1, 1, 1, 0, 1, 1, 0,
- 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 2, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0,
- 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0,
- 2, 0, 1, 0, 0, 0, 1, 0, 0, 2, 0, 1, 1, 1, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0,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0, 0, 1, 0, 0,
+ 2, 0, 1, 0, 0, 0, 1, 0, 0, 2, 0, 1, 1, 1, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0,
+ 2, 0, 1, 0, 0, 0, 1, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1,
+ 2, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
+ 2, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 2, 0, 0, 0, 0,
+ 2, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2, 2, 0, 0,
+ 1, 1, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2, 0,
+ 1, 2, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0,
+ 2, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
+ 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
+ "height":16,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
- "width":25,
+ "width":26,
"x":0,
"y":0
},
@@ -63,5 +65,5 @@
"tilewidth":9,
"type":"map",
"version":"1.10",
- "width":25
+ "width":26
} \ No newline at end of file
diff --git a/res/font.png b/res/font.png
new file mode 100644
index 0000000..9be5b5a
--- /dev/null
+++ b/res/font.png
Binary files differ
diff --git a/src/camera.c b/src/camera.c
index 87d1f2c..a862133 100644
--- a/src/camera.c
+++ b/src/camera.c
@@ -8,6 +8,8 @@
static double cam[2] = {0, 0};
static double off[2] = {0, 0};
+int flip_offset;
+
void
camera_init(void)
{
@@ -29,10 +31,7 @@ camera_update(double dest[2])
cam[i] += 0.1 * (dest[i] - cam[i]);
cam[0] = clamp(DWIDTH/2.0, map_width() * TSIZE - DWIDTH/2.0, cam[0]);
cam[1] = clamp(DHEIGHT/2.0, map_height() * TSIZE - DHEIGHT/2.0, cam[1]);
- if (rand() % 60 == 0)
- off[1] = rand() % 10;
- else
- off[1] -= (off[1] > 0);
+ flip_offset += rand();
}
int
diff --git a/src/font.c b/src/font.c
new file mode 100644
index 0000000..eddac69
--- /dev/null
+++ b/src/font.c
@@ -0,0 +1,39 @@
+#include "font.h"
+#include "px.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+void
+font_draw(const char *s, int x, int y)
+{
+ extern const PxSpr spr_font;
+ for (int i = 0; s[i] != '\0'; i++) {
+ const int ix = s[i] % FONT_LINE * FONT_WIDTH;
+ const int iy = s[i] / FONT_LINE * FONT_HEIGHT;
+ pxSpr(&spr_font, x, y, ix, iy, FONT_WIDTH, FONT_HEIGHT);
+ x += FONT_WIDTH;
+ }
+}
+
+void
+font_print(int x, int y, const char *fmt, ...)
+{
+ char buf[256] = {};
+ va_list va;
+ va_start(va, fmt);
+ vsnprintf(buf, sizeof(buf) - 1, fmt, va);
+ va_end(va);
+ font_draw(buf, x, y);
+}
+
+void
+font_center(int x, int y, const char *fmt, ...)
+{
+ char buf[256] = {};
+ va_list va;
+ va_start(va, fmt);
+ vsnprintf(buf, sizeof(buf) - 1, fmt, va);
+ va_end(va);
+ font_draw(buf, x - strlen(buf) * FONT_WIDTH / 2, y - FONT_HEIGHT / 2);
+}
diff --git a/src/font.h b/src/font.h
new file mode 100644
index 0000000..45f2635
--- /dev/null
+++ b/src/font.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#define FONT_WIDTH 30
+#define FONT_HEIGHT 33
+#define FONT_LINE 16
+
+void font_draw(const char *s, int x, int y);
+void font_print(int x, int y, const char *fmt, ...);
+void font_center(int x, int y, const char *fmt, ...);
diff --git a/src/px.c b/src/px.c
index 694c789..6397386 100644
--- a/src/px.c
+++ b/src/px.c
@@ -57,6 +57,8 @@ pxDeinit(void)
int
pxFlip(void)
{
+ extern int flip_offset;
+
uint8_t *pixels = NULL;
int pitch = 0;
if (SDL_LockTexture(pxtexture, NULL, (void **)&pixels, &pitch)) {
@@ -64,10 +66,13 @@ pxFlip(void)
return -1;
}
+ printf("--------------\n");
for (int y = 0; y < PX_HEIGHT; y++) {
+ const int iy = (y + flip_offset) % PX_HEIGHT;
+ printf("%d\n", iy);
for (int x = 0; x < PX_WIDTH; x++) {
const int ix = x << 2;
- PxCol col = pxbuf[x + y * PX_WIDTH];
+ PxCol col = pxbuf[x + iy * PX_WIDTH];
if (pxpal[col].spal)
col = pxpal[col].spal - 1;
pixels[ix + y * pitch + 0] = pxpal[col].b;
@@ -79,6 +84,7 @@ pxFlip(void)
SDL_UnlockTexture(pxtexture);
SDL_RenderCopy(___tzr_renderer, pxtexture, NULL, NULL);
+ return 0;
}
void