diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-27 07:54:09 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-27 07:54:09 +0200 |
commit | 7fa2669277220041e53637a405ebba644450e4b7 (patch) | |
tree | d36d5611599333a44dba194ab5a7708ff0099f49 | |
parent | eb7846d195d082578fefb48528c569fa5ef624e3 (diff) | |
download | 006-7fa2669277220041e53637a405ebba644450e4b7.tar.gz |
particule example
-rw-r--r-- | src/entity.h | 5 | ||||
-rw-r--r-- | src/game.h | 2 | ||||
-rw-r--r-- | src/part.c | 29 | ||||
-rw-r--r-- | src/player.c | 8 |
4 files changed, 40 insertions, 4 deletions
diff --git a/src/entity.h b/src/entity.h index c444be8..45a1a9c 100644 --- a/src/entity.h +++ b/src/entity.h @@ -15,6 +15,11 @@ struct Entity { int width; int height; bool ignore_solids; + union { + struct { + int life; + } part; + }; }; unsigned int entity_type(const char *typename); @@ -1,7 +1,7 @@ #pragma once #include "entity.h" -enum { MAX_ENTITIES = 128 }; +enum { MAX_ENTITIES = 256 }; typedef struct Game { unsigned long uuid; diff --git a/src/part.c b/src/part.c new file mode 100644 index 0000000..c2d684d --- /dev/null +++ b/src/part.c @@ -0,0 +1,29 @@ +#include "entityimpl.h" +#include <stdlib.h> + +IMPL_INIT(part) { + 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(true, this->pos[0], this->pos[1], + this->width, this->height); +} diff --git a/src/player.c b/src/player.c index 1871944..847202b 100644 --- a/src/player.c +++ b/src/player.c @@ -1,16 +1,18 @@ #include "entityimpl.h" IMPL(draw) { - TZR_DrawSetColor(1, 1, 1, 1); + TZR_DrawSetColor(1, 1, 1, 0.5); TZR_DrawRectangle(true, this->pos[0] - this->width / 2, this->pos[1] - this->height / 2, this->width, this->height); } IMPL(update) { - this->vel[0] = TZR_IsKeyDown(SDL_SCANCODE_RIGHT) - - TZR_IsKeyDown(SDL_SCANCODE_LEFT); + 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"), this->pos[0], + this->pos[1], 0, 0); } IMPL_INIT(player) { |