From 42a222e998e3693bb59c90b2c4b446c8e8694a5b Mon Sep 17 00:00:00 2001 From: kdx Date: Wed, 5 Apr 2023 23:19:58 +0200 Subject: fuck god --- map/game.tmj | 31 +++++++++++++++++++++---------- src/cfg.h | 2 +- src/entity.h | 7 ++----- src/grid.c | 15 +++++++++++++++ src/part.c | 29 ----------------------------- src/player.c | 17 ++++------------- 6 files changed, 43 insertions(+), 58 deletions(-) create mode 100644 src/grid.c delete mode 100644 src/part.c diff --git a/map/game.tmj b/map/game.tmj index 5401795..4832f9f 100644 --- a/map/game.tmj +++ b/map/game.tmj @@ -10,24 +10,35 @@ { "height":16, "id":1, - "name":"player", + "name":"2 player", "rotation":0, "type":"player", "visible":true, "width":16, - "x":144, - "y":96 + "x":320, + "y":112 }, { - "height":32, + "height":16, "id":2, - "name":"player", + "name":"1 player", "rotation":0, "type":"player", "visible":true, - "width":32, - "x":256, - "y":144 + "width":16, + "x":64, + "y":112 + }, + { + "height":8, + "id":3, + "name":"grid", + "rotation":0, + "type":"", + "visible":true, + "width":8, + "x":0, + "y":0 }], "opacity":1, "type":"objectgroup", @@ -36,10 +47,10 @@ "y":0 }], "nextlayerid":3, - "nextobjectid":3, + "nextobjectid":4, "orientation":"orthogonal", "renderorder":"right-down", - "tiledversion":"1.10.0", + "tiledversion":"1.10.1", "tileheight":16, "tilesets":[], "tilewidth":16, diff --git a/src/cfg.h b/src/cfg.h index 7778350..45c6e23 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -2,5 +2,5 @@ #define DWIDTH 400 #define DHEIGHT 224 -#define TARGET_FPS 60 +#define TARGET_FPS 30 #define TSIZE 16 diff --git a/src/entity.h b/src/entity.h index bf246d0..263cd5f 100644 --- a/src/entity.h +++ b/src/entity.h @@ -20,11 +20,8 @@ struct Entity { int width; int height; bool ignore_solids; - union { - struct { - int life; - } part; - }; + int life; + int id; }; unsigned int entity_type(const char *typename); diff --git a/src/grid.c b/src/grid.c new file mode 100644 index 0000000..f39ebcf --- /dev/null +++ b/src/grid.c @@ -0,0 +1,15 @@ +#include "TZR.h" +#include "entity.h" +#include "entityimpl.h" + +IMPL_INIT(grid, 0) {} + +IMPL(draw) { + if (TZR_GetTick() % 2) + return; + TZR_DrawSetColor(1, 1, 1, 1); + for (int i = 0; i < DHEIGHT; i += TSIZE) + TZR_DrawLine(-1, i - 1, DWIDTH, i - 1); + for (int i = 0; i < DWIDTH; i += TSIZE) + TZR_DrawLine(i - 1, -1, i - 1, DHEIGHT); +} diff --git a/src/part.c b/src/part.c deleted file mode 100644 index a722193..0000000 --- a/src/part.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "entityimpl.h" -#include - -IMPL_INIT(part, 0) { - this->width = this->height = 1 + rand() % 2; - this->ignore_solids = true; - this->part.life = 30 + rand() % 10; - this->vel[0] = (float)(rand() % 1024) / 1023.0; - this->vel[1] = (float)(rand() % 1024) / 1023.0; - this->vel[0] *= 1 - 2 * (rand() % 2); - this->vel[1] *= 1 - 2 * (rand() % 3); -} - -IMPL(update) { - this->part.life -= 1; - if (this->part.life <= 0) { - this->type = 0; - return; - } - this->vel[1] += 0.1; - - entity_move(this, g); -} - -IMPL(draw) { - TZR_DrawSetColor(1, 1, 1, 1); - TZR_DrawRectangle(this->pos[0], this->pos[1], - this->width, this->height, .fill=true); -} diff --git a/src/player.c b/src/player.c index 36a5131..eea0137 100644 --- a/src/player.c +++ b/src/player.c @@ -1,20 +1,11 @@ #include "entityimpl.h" -IMPL(draw) { - TZR_DrawSetColor(1, 1, 1, 0.5); - TZR_DrawRectangle(this->pos[0] - this->width / 2, - this->pos[1] - this->height / 2, - this->width, this->height, .fill=true); +IMPL_INIT(player, 0) { + this->id = atoi(this->name); } -IMPL(update) { - this->vel[0] = 2 * TZR_IsKeyDown(SDL_SCANCODE_RIGHT) - - 2 * TZR_IsKeyDown(SDL_SCANCODE_LEFT); - entity_move(this, g); - entity_init(game_create_entity(g), entity_type("part"), NULL, - this->pos[0], this->pos[1], 0, 0); +IMPL(draw) { } -IMPL_INIT(player, 0) { - this->height = this->width = 12; +IMPL(update) { } -- cgit v1.2.3