67 lines
1.1 KiB
C
67 lines
1.1 KiB
C
/*
|
|
* DESCRIPTION:
|
|
* Stun component.
|
|
*/
|
|
|
|
#include "c_stun.h"
|
|
|
|
static void update_f(struct CStun* self);
|
|
|
|
/* Draws a stun component. */
|
|
static void
|
|
update_f(struct CStun* self)
|
|
{
|
|
struct CPhysics* physics;
|
|
struct CControl* control;
|
|
struct CRotation* rotation;
|
|
struct CHealth* health;
|
|
|
|
physics = ecs_get(self->id, ECS_C_PHYSICS);
|
|
control = ecs_get(self->id, ECS_C_CONTROL);
|
|
rotation = ecs_get(self->id, ECS_C_ROTATION);
|
|
health = ecs_get(self->id, ECS_C_HEALTH);
|
|
|
|
if (health->isDead || !control || !rotation || !physics || !self->isStun)
|
|
return;
|
|
|
|
control->isDisabled = true;
|
|
rotation->isDisabled = true;
|
|
|
|
glm_vec3_zero(physics->velocity);
|
|
|
|
self->timer--;
|
|
|
|
if (self->timer <= 0)
|
|
{
|
|
control->isDisabled = false;
|
|
rotation->isDisabled = false;
|
|
self->isStun = false;
|
|
}
|
|
}
|
|
|
|
/* Sets stun component. */
|
|
void
|
|
c_stun_set(struct CStun* self, s32 timerMax)
|
|
{
|
|
self->timerMax = timerMax;
|
|
self->timer = self->timerMax;
|
|
self->isStun = true;
|
|
}
|
|
|
|
/* Registers stun component. */
|
|
void
|
|
c_stun_register(void)
|
|
{
|
|
ecs_register
|
|
(
|
|
ECS_C_STUN,
|
|
sizeof(struct CStun),
|
|
C_STUN_LIMIT,
|
|
NULL,
|
|
NULL,
|
|
(ECSFunction)update_f,
|
|
NULL,
|
|
NULL
|
|
);
|
|
}
|