Add particles!
This commit is contained in:
78
game/main.c
78
game/main.c
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "pathfinding.h"
|
||||
#include "sounds.h"
|
||||
#include "entity_factory.h"
|
||||
|
||||
// Constants
|
||||
const char *GAME_DATA_SAVE_PATH = "game_data.ini";
|
||||
@@ -192,6 +193,12 @@ bool init(void *userData) {
|
||||
{ ecs_id(TextureRegion) }
|
||||
},
|
||||
});
|
||||
game->particles0Query = ecs_query(ECS, {
|
||||
.filter.terms = { { ecs_id(ParticleLayer0) } }
|
||||
});
|
||||
game->particles1Query = ecs_query(ECS, {
|
||||
.filter.terms = { { ecs_id(ParticleLayer1) } }
|
||||
});
|
||||
|
||||
{
|
||||
ECS_COMPONENT_DEFINE(ECS, InputState);
|
||||
@@ -354,6 +361,8 @@ void deinit(void *userData) {
|
||||
// Destroy queries
|
||||
ecs_query_fini(input->queries.selected);
|
||||
ecs_query_fini(game->drawQuery);
|
||||
ecs_query_fini(game->particles0Query);
|
||||
ecs_query_fini(game->particles1Query);
|
||||
|
||||
Game gameCopy = *game;
|
||||
InputState inputCopy = *input;
|
||||
@@ -530,6 +539,22 @@ static void renderGame(Game *game, float dt) {
|
||||
DrawTexturePro(tex, draw.src, draw.dst, draw.origin, draw.rotation, c);
|
||||
}
|
||||
bzTileMapClearCollisionLayer(&game->map, COLL_LAYER_TRANSPARENCY);
|
||||
|
||||
// Draw particle layer 1
|
||||
it = ecs_query_iter(ECS, game->particles1Query);
|
||||
ecs_defer_begin(ECS);
|
||||
while (ecs_iter_next(&it)) {
|
||||
Particle *particle = ecs_field(&it, Particle, 1);
|
||||
for (i32 i = 0; i < it.count; i++) {
|
||||
DrawCircleV(particle[i].pos, 2.0f, RED);
|
||||
if (updateParticle(tex, &particle[i], dt))
|
||||
ecs_delete(ECS, it.entities[i]);
|
||||
}
|
||||
}
|
||||
ecs_defer_end(ECS);
|
||||
|
||||
|
||||
#if 0
|
||||
Vector2 target = GetMousePosition();
|
||||
target = GetScreenToWorld2D(target, game->camera);
|
||||
static f32 elapsed = 0;
|
||||
@@ -543,7 +568,6 @@ static void renderGame(Game *game, float dt) {
|
||||
elapsed += dt * 2;
|
||||
elapsed = Clamp(elapsed, 0, 1.0f);
|
||||
attack = false;
|
||||
#if 0
|
||||
if (worker && false) {
|
||||
Position *pos = ecs_get_mut(ECS, worker, Position);
|
||||
DrawCircle(pos->x, pos->y, 2.0f, BLUE);
|
||||
@@ -709,6 +733,58 @@ void imguiRender(float dt, void *userData) {
|
||||
break;
|
||||
}
|
||||
igText("Input state: %s", inputState);
|
||||
if (igCollapsingHeader_TreeNodeFlags("ParticleEditor", 0)) {
|
||||
static ParticleEmitter emitter = {0.0f};
|
||||
emitter.data.tileID = getParticleTypeTile(PARTICLE_CIRCLE);
|
||||
emitter.data.blend = BLEND_ADDITIVE;
|
||||
struct ParticleEmitterData *data = &emitter.data;
|
||||
igSliderFloat2("Pos", &emitter.pos.x, 0.0f, 1000.0f, "%.2f", 0);
|
||||
igSliderFloat2("minOffset", &data->minOffset.x, -50.0f, 50.0f, "%.2f", 0);
|
||||
igSliderFloat2("maxOffset", &data->maxOffset.x, -50.0f, 50.0f, "%.2f", 0);
|
||||
|
||||
igSliderFloat2("minStartVel", &data->minStartVel.x, -50.0f, 50.0f, "%.2f", 0);
|
||||
igSliderFloat2("maxStartVel", &data->maxStartVel.x, -50.0f, 50.0f, "%.2f", 0);
|
||||
|
||||
igSliderFloat2("minEndVel", &data->minEndVel.x, -50.0f, 50.0f, "%.2f", 0);
|
||||
igSliderFloat2("maxEndVel", &data->maxEndVel.x, -50.0f, 50.0f, "%.2f", 0);
|
||||
|
||||
igSliderFloat("minStartSize", &data->minStartSize, -50.0f, 50.0f, "%.2f", 0);
|
||||
igSliderFloat("maxStartSize", &data->maxStartSize, -50.0f, 50.0f, "%.2f", 0);
|
||||
|
||||
igSliderFloat("minEndSize", &data->minEndSize, -50.0f, 50.0f, "%.2f", 0);
|
||||
igSliderFloat("maxEndSize", &data->maxEndSize, -50.0f, 50.0f, "%.2f", 0);
|
||||
|
||||
igSliderFloat("minStartRotSpeed", &data->minStartRotSpeed, -50.0f, 50.0f, "%.2f", 0);
|
||||
igSliderFloat("maxStartRotSpeed", &data->maxStartRotSpeed, -50.0f, 50.0f, "%.2f", 0);
|
||||
|
||||
igSliderFloat("minEndRotSpeed", &data->minEndRotSpeed, -50.0f, 50.0f, "%.2f", 0);
|
||||
igSliderFloat("maxEndRotSpeed", &data->maxEndRotSpeed, -50.0f, 50.0f, "%.2f", 0);
|
||||
|
||||
#define igColor(label, color) \
|
||||
do { \
|
||||
\
|
||||
float cols[4] = { color.r / 255.0f, color.g / 255.0f, \
|
||||
color.b / 255.0f, color.a / 255.0f }; \
|
||||
igColorEdit4(label, cols, 0); \
|
||||
color.r = cols[0] * 255.0f; \
|
||||
color.g = cols[1] * 255.0f; \
|
||||
color.b = cols[2] * 255.0f; \
|
||||
color.a = cols[3] * 255.0f; \
|
||||
} while (0)
|
||||
|
||||
|
||||
igColor("minStartColor", data->minStartColor);
|
||||
igColor("maxStartColor", data->maxStartColor);
|
||||
igColor("minEndColor", data->minEndColor);
|
||||
igColor("maxEndColor", data->maxEndColor);
|
||||
#undef igColor
|
||||
|
||||
igSliderFloat("minLifetime", &data->minLifetime, 0.0f, 6.0f, "%.2f", 0);
|
||||
igSliderFloat("maxLifetime", &data->maxLifetime, 0.0f, 6.0f, "%.2f", 0);
|
||||
Particle particle = spawnParticle(&emitter);
|
||||
ecs_entity_t e = entityCreateEmpty();
|
||||
ecs_set_ptr(ECS, e, ParticleLayer1, &particle);
|
||||
}
|
||||
if (igCollapsingHeader_TreeNodeFlags("Selection", 0)) {
|
||||
switch (input->state) {
|
||||
case INPUT_SELECTED_UNITS:
|
||||
|
||||
Reference in New Issue
Block a user