parent
7c86e0b3c5
commit
edf78412dc
|
@ -52,6 +52,8 @@ void add_particle_emitter(ParticleSystem_t* system, const ParticleEmitter_t* in_
|
||||||
emitter->particles[i].velocity.x = speed * cos(angle);
|
emitter->particles[i].velocity.x = speed * cos(angle);
|
||||||
emitter->particles[i].velocity.y = speed * sin(angle);
|
emitter->particles[i].velocity.y = speed * sin(angle);
|
||||||
emitter->particles[i].position = emitter->position;
|
emitter->particles[i].position = emitter->position;
|
||||||
|
emitter->particles[i].rotation = angle;
|
||||||
|
emitter->particles[i].angular_vel = -10 + 20 * (float)rand() / (float)RAND_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void update_particle_system(ParticleSystem_t* system)
|
void update_particle_system(ParticleSystem_t* system)
|
||||||
|
@ -110,11 +112,33 @@ void draw_particle_system(ParticleSystem_t* system)
|
||||||
{
|
{
|
||||||
ParticleEmitter_t* emitter = system->emitters + emitter_idx;
|
ParticleEmitter_t* emitter = system->emitters + emitter_idx;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < emitter->n_particles; ++i)
|
Particle_t* part = emitter->particles;
|
||||||
|
for (uint32_t i = 0; i < emitter->n_particles; ++i, ++part)
|
||||||
{
|
{
|
||||||
if (emitter->particles[i].alive)
|
if (part->alive)
|
||||||
{
|
{
|
||||||
DrawCircleV(emitter->particles[i].position, 5, BLACK);
|
if (emitter->tex == NULL)
|
||||||
|
{
|
||||||
|
DrawCircleV(part->position, 5, BLACK);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Rectangle source = {
|
||||||
|
0.0f, 0.0f,
|
||||||
|
(float)emitter->tex->width, (float)emitter->tex->height
|
||||||
|
};
|
||||||
|
|
||||||
|
Rectangle dest = {
|
||||||
|
part->position.x, part->position.y,
|
||||||
|
(float)emitter->tex->width, (float)emitter->tex->height
|
||||||
|
};
|
||||||
|
Vector2 origin = { (float)emitter->tex->width / 2, (float)emitter->tex->height / 2 };
|
||||||
|
DrawTexturePro(
|
||||||
|
*emitter->tex,
|
||||||
|
source, dest, origin,
|
||||||
|
part->rotation, WHITE
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emitter_idx = system->emitter_list[emitter_idx].next;
|
emitter_idx = system->emitter_list[emitter_idx].next;
|
||||||
|
|
|
@ -13,11 +13,11 @@ typedef enum PartEmitterType
|
||||||
|
|
||||||
typedef struct Particle
|
typedef struct Particle
|
||||||
{
|
{
|
||||||
Texture2D* tex;
|
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
Vector2 velocity;
|
Vector2 velocity;
|
||||||
Vector2 accleration;
|
Vector2 accleration;
|
||||||
float rotation;
|
float rotation;
|
||||||
|
float angular_vel;
|
||||||
float size;
|
float size;
|
||||||
uint32_t timer;
|
uint32_t timer;
|
||||||
bool alive;
|
bool alive;
|
||||||
|
@ -41,6 +41,7 @@ typedef struct ParticleEmitter
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
Particle_t particles[MAX_PARTICLES];
|
Particle_t particles[MAX_PARTICLES];
|
||||||
uint32_t n_particles;
|
uint32_t n_particles;
|
||||||
|
Texture2D* tex;
|
||||||
uint32_t timer;
|
uint32_t timer;
|
||||||
bool one_shot;
|
bool one_shot;
|
||||||
bool finished;
|
bool finished;
|
||||||
|
|
|
@ -10,6 +10,8 @@ void simple_particle_system_update(Particle_t* part, void* user_data)
|
||||||
{
|
{
|
||||||
|
|
||||||
float delta_time = DELTA_T; // TODO: Will need to think about delta time handling
|
float delta_time = DELTA_T; // TODO: Will need to think about delta time handling
|
||||||
|
part->rotation += part->angular_vel;
|
||||||
|
|
||||||
part->velocity =
|
part->velocity =
|
||||||
Vector2Add(
|
Vector2Add(
|
||||||
part->velocity,
|
part->velocity,
|
||||||
|
@ -49,6 +51,7 @@ int main(void)
|
||||||
static ParticleSystem_t part_sys = {0};
|
static ParticleSystem_t part_sys = {0};
|
||||||
|
|
||||||
init_particle_system(&part_sys);
|
init_particle_system(&part_sys);
|
||||||
|
Texture2D tex = LoadTexture("res/bomb.png");
|
||||||
|
|
||||||
EmitterConfig_t conf ={
|
EmitterConfig_t conf ={
|
||||||
.launch_range = {0, 360},
|
.launch_range = {0, 360},
|
||||||
|
@ -61,6 +64,7 @@ int main(void)
|
||||||
.config = conf,
|
.config = conf,
|
||||||
.n_particles = MAX_PARTICLES,
|
.n_particles = MAX_PARTICLES,
|
||||||
.one_shot = true,
|
.one_shot = true,
|
||||||
|
.tex = &tex,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool key_press = false;
|
bool key_press = false;
|
||||||
|
@ -83,5 +87,7 @@ int main(void)
|
||||||
draw_particle_system(&part_sys);
|
draw_particle_system(&part_sys);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
UnloadTexture(tex);
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
deinit_particle_system(&part_sys);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue