first commit
This commit is contained in:
81
src/game/ecs/c_flash.c
Normal file
81
src/game/ecs/c_flash.c
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Flash component.
|
||||
*/
|
||||
|
||||
#include "c_flash.h"
|
||||
|
||||
static void update_f(struct CFlash* self);
|
||||
|
||||
/* Updates flash component. */
|
||||
static void
|
||||
update_f(struct CFlash* self)
|
||||
{
|
||||
vec4 color;
|
||||
f32 progress;
|
||||
|
||||
if (self->isFinished)
|
||||
return;
|
||||
|
||||
progress = (f32)self->timer / self->timerMax;
|
||||
|
||||
glm_vec4_copy(self->color, color);
|
||||
|
||||
switch (self->type)
|
||||
{
|
||||
case C_FLASH_VANISH:
|
||||
glm_vec4_scale(color, progress, color);
|
||||
break;
|
||||
case C_FLASH_APPEAR:
|
||||
glm_vec4_scale(color, (1.0f - progress), color);
|
||||
break;
|
||||
case C_FLASH_STROBE:
|
||||
glm_vec4_scale(color, sin((M_PI * 2) * (progress * 2.0f)), color);
|
||||
break;
|
||||
case C_FLASH_CONSTANT:
|
||||
glm_vec4_copy(self->color, color);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
renderer_clear_color_set(&game.renderer, color);
|
||||
|
||||
if (self->timer <= 0)
|
||||
{
|
||||
renderer_clear_color_set(&game.renderer, self->baseColor);
|
||||
self->timer = 0;
|
||||
self->isFinished = true;
|
||||
}
|
||||
else
|
||||
self->timer--;
|
||||
}
|
||||
|
||||
/* Sets flash component info. */
|
||||
void
|
||||
c_flash_set(struct CFlash* self, vec4 baseColor, vec4 color, s32 timerMax, enum CFlashType type)
|
||||
{
|
||||
self->timerMax = timerMax;
|
||||
self->type = type;
|
||||
glm_vec4_copy(baseColor, self->baseColor);
|
||||
glm_vec4_copy(color, self->color);
|
||||
self->timer = self->timerMax;
|
||||
self->isFinished = false;
|
||||
}
|
||||
|
||||
/* Registers flash component. */
|
||||
void
|
||||
c_flash_register(void)
|
||||
{
|
||||
ecs_register
|
||||
(
|
||||
ECS_C_FLASH,
|
||||
sizeof(struct CFlash),
|
||||
C_FLASH_LIMIT,
|
||||
NULL,
|
||||
NULL,
|
||||
(ECSFunction)update_f,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user