summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-05-04 09:58:31 +0200
committerkdx <kikoodx@paranoici.org>2023-05-04 09:58:31 +0200
commitade15c6bc63cf87f7d20ed5a3893360cd0a8f596 (patch)
treed5fb6148107d8ee9ee15529246bf24682b0496e1
parent082e91190c8dff9393c047444644fc6f7e4280de (diff)
downloadstudy-sttky-ade15c6bc63cf87f7d20ed5a3893360cd0a8f596.tar.gz
lazy freak macros
-rw-r--r--map/game.tmj4
-rw-r--r--src/cfg.h2
-rw-r--r--src/entityimpl.h20
-rw-r--r--src/player.c11
4 files changed, 28 insertions, 9 deletions
diff --git a/map/game.tmj b/map/game.tmj
index f66075c..c1b9354 100644
--- a/map/game.tmj
+++ b/map/game.tmj
@@ -15,8 +15,8 @@
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,
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,
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,
- 1, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
- 2, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ 1, 2, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 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],
"height":14,
"id":1,
"name":"Tile Layer 1",
diff --git a/src/cfg.h b/src/cfg.h
index e5b123c..384d5b2 100644
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -1,7 +1,7 @@
#pragma once
#include "px.h"
-#define TARGET_FPS 30
+#define TARGET_FPS 60
#define TSIZE 9
#define DWIDTH PX_WIDTH
#define DHEIGHT PX_HEIGHT
diff --git a/src/entityimpl.h b/src/entityimpl.h
index 3e27b40..b579753 100644
--- a/src/entityimpl.h
+++ b/src/entityimpl.h
@@ -37,15 +37,15 @@ __attribute__((constructor)) static void silence_unused(void) {
__attribute__((constructor)) static void init_##X() { _##X = X; } \
static void X(Entity *this, Game *g)
-#define IMPL_INIT(X,P) static void init(Entity *, Game *, const char *, \
+#define IMPL_INIT(X,P) static void __init(Entity *, Game *, const char *, \
int, int, int, int); \
__attribute__((constructor)) static void init_tag(void) { \
- entitytags[num_entitytags].init = init; \
+ entitytags[num_entitytags].init = __init; \
entitytags[num_entitytags].parent = P; \
entitytags[num_entitytags++].name = #X; \
} \
static void _init(Entity *this, Game *g); \
-static void init(Entity *this, Game *g, const char *name, int x, int y, int w, int h) { \
+static void __init(Entity *this, Game *g, const char *name, int x, int y, int w, int h) { \
{ \
const __auto_type uuid = this->uuid; \
memset(this, 0, sizeof(*this)); \
@@ -71,3 +71,17 @@ static void init(Entity *this, Game *g, const char *name, int x, int y, int w, i
_init(this, g); \
} \
static void _init(Entity *this, Game *g)
+
+/* helper macros */
+#define entity(type) entity_type(type)
+#define create_entity() game_create_entity(g)
+#define entity_count(t) game_entity_count(g, (t))
+#define get_entity(t) game_get_entity(g, (t))
+#define get_entity_uuid(u) game_get_entity_by_uuid(g, (u))
+#define collide(ox, oy) entity_collide(this, (ox), (oy))
+#define collide_spike(ox, oy) entity_collide_spike(this, (ox), (oy))
+#define oob() entity_oob(this)
+#define meet(o) entity_meet(this, (o))
+#define place_meeting(t) entity_place_meeting(this, g, (t))
+#define move() entity_move(this, g)
+#define init(t, x, y) entity_init(this, g, (t), NULL, (x), (y), w, h)
diff --git a/src/player.c b/src/player.c
index 3fdc7b3..5df62e5 100644
--- a/src/player.c
+++ b/src/player.c
@@ -11,14 +11,19 @@ IMPL(update) {
TZR_IsKeyDown(SDL_SCANCODE_LEFT);
const int kright = TZR_IsKeyDown(SDL_SCANCODE_D) ||
TZR_IsKeyDown(SDL_SCANCODE_RIGHT);
- const int kpjump = TZR_IsKeyPressed(SDL_SCANCODE_Z) ||
+ const int kpjump = TZR_IsKeyPressed(SDL_SCANCODE_W) ||
TZR_IsKeyPressed(SDL_SCANCODE_UP) ||
TZR_IsKeyPressed(SDL_SCANCODE_SPACE);
const int dirx = kright - kleft;
+ const int on_ground = collide(0, 1);
- this->vel[0] = dirx * 2;
+ this->vel[0] = dirx;
+ if (on_ground && kpjump)
+ this->vel[1] = -2;
+ else
+ this->vel[1] += 0.1;
- entity_move(this, g);
+ move();
camera_update(this->vel);
}