diff --git a/data/blackboard.art b/data/blackboard.art index 63526b6..c5dd8c5 100644 Binary files a/data/blackboard.art and b/data/blackboard.art differ diff --git a/src/Asteroid.c b/src/Asteroid.c index 14c936d..3158b88 100644 --- a/src/Asteroid.c +++ b/src/Asteroid.c @@ -813,6 +813,22 @@ void asteroid_gameUpdateAndRender(GameState *state, Memory *memory, v2 localDp = V2(math_cosf(rotation), math_sinf(rotation)); entity->dP = v2_scale(localDp, world->pixelsPerMeter * 5); } + else if (entity->type == entitytype_particle) + { + f32 diff = entity->color.a - 0.1f; + if (diff < 0.01f) + { + deleteEntity(world, i--); + continue; + } + + f32 divisor = + MAX(entity->particleInitDp.x, entity->particleInitDp.y); + f32 maxDp = MAX(entity->dP.x, entity->dP.y); + + entity->color.a = maxDp / divisor; + + } /* Loop entity around world */ if (entity->pos.y >= world->worldSize.h) @@ -852,12 +868,16 @@ void asteroid_gameUpdateAndRender(GameState *state, Memory *memory, if (colliderA->type >= entitytype_asteroid_small && colliderA->type <= entitytype_asteroid_large) { + + f32 numParticles = 4; if (colliderA->type == entitytype_asteroid_medium) { AsteroidSpec spec = {0}; spec.pos = colliderA->pos; spec.dP = v2_scale(colliderA->dP, -2.0f); addAsteroidWithSpec(world, asteroidsize_small, &spec); + + numParticles = 8; } else if (colliderA->type == entitytype_asteroid_large) { @@ -871,6 +891,59 @@ void asteroid_gameUpdateAndRender(GameState *state, Memory *memory, spec.dP = v2_perpendicular(colliderA->dP); addAsteroidWithSpec(world, asteroidsize_small, &spec); + + numParticles = 16; + } + + for (i32 i = 0; i < numParticles; i++) + { + { // Add particles + Entity *particle = + &world->entityList[world->entityIndex++]; + particle->id = world->entityIdCounter++; + + particle->pos = colliderA->pos; + particle->size = V2(4.0f, 4.0f); + + i32 randValue = rand(); + Radians rotation = + DEGREES_TO_RADIANS((randValue % 360)); + v2 randDirectionVec = + V2(math_cosf(rotation), math_sinf(rotation)); + + i32 particleDpLimit = 8; + f32 randDpMultiplier = + (f32)(randValue % particleDpLimit) + 1; + + v2 newDp = v2_scale(colliderA->dP, randDpMultiplier); + newDp = v2_hadamard(newDp, randDirectionVec); + + particle->dP = newDp; + particle->particleInitDp = newDp; + + particle->offset = v2_scale(particle->size, -0.5f); + particle->hitbox = particle->size; + particle->rotation = 0; + particle->renderMode = rendermode_polygon; + + if (!world->particleVertexCache) + { + world->particleVertexCache = + MEMORY_PUSH_ARRAY(&world->entityArena, 4, v2); + world->particleVertexCache[0] = + V2(0, particle->size.h); + world->particleVertexCache[1] = V2(0, 0); + world->particleVertexCache[2] = + V2(particle->size.w, 0); + world->particleVertexCache[3] = particle->size; + } + + particle->vertexPoints = world->particleVertexCache; + particle->numVertexPoints = 4; + + particle->type = entitytype_particle; + particle->color = V4(1.0f, 0.0f, 0, 1.0f); + } } ASSERT(colliderB->type == entitytype_bullet); diff --git a/src/include/Dengine/Asteroid.h b/src/include/Dengine/Asteroid.h index 2ec46b4..227d02e 100644 --- a/src/include/Dengine/Asteroid.h +++ b/src/include/Dengine/Asteroid.h @@ -25,6 +25,7 @@ typedef struct World v2 *asteroidLargeVertexCache[3]; v2 *bulletVertexCache; + v2 *particleVertexCache; // TODO(doyle): Audio mixing instead of multiple renderers AudioRenderer *audioRenderer; diff --git a/src/include/Dengine/Entity.h b/src/include/Dengine/Entity.h index 265fa7c..9836048 100644 --- a/src/include/Dengine/Entity.h +++ b/src/include/Dengine/Entity.h @@ -58,6 +58,8 @@ enum EntityType entitytype_asteroid_medium, entitytype_asteroid_large, + entitytype_particle, + entitytype_bullet, entitytype_count, }; @@ -77,6 +79,7 @@ typedef struct Entity v2 pos; v2 dP; + v2 particleInitDp; v2 hitbox; v2 size;