2023-08-26 09:28:06 -04:00

145 lines
2.9 KiB
C

#include "play.h"
static void _play_entity_init(Play* self);
/* Initializes entities for the play state. */
static void
_play_entity_init(Play* self)
{
self->player = ecs_entity_add(&self->state->game->ecs);
self->elemental = ecs_entity_add(&self->state->game->ecs);
self->spawner = ecs_entity_add(&self->state->game->ecs);
self->cursor = ecs_entity_add(&self->state->game->ecs);
self->goodieDisplay = ecs_entity_add(&self->state->game->ecs);
self->timerDisplay = ecs_entity_add(&self->state->game->ecs);
self->waveDisplay = ecs_entity_add(&self->state->game->ecs);
self->waveTimerDisplay = ecs_entity_add(&self->state->game->ecs);
self->heartDisplay = ecs_entity_add(&self->state->game->ecs);
self->tutorialText = ecs_entity_add(&self->state->game->ecs);
self->overlay = ecs_entity_add(&self->state->game->ecs);
entity_spawner_init
(
&self->state->game->ecs,
self->spawner,
self->player
);
entity_player_init
(
&self->state->game->ecs,
self->player,
(f32*)PLAY_PLAYER_POSITION,
self->spawner
);
entity_cursor_init
(
&self->state->game->ecs,
self->cursor
);
entity_goodie_display_init
(
&self->state->game->ecs,
self->goodieDisplay,
self->player
);
entity_heart_display_init
(
&self->state->game->ecs,
self->heartDisplay,
self->player
);
entity_timer_display_init
(
&self->state->game->ecs,
self->timerDisplay
);
entity_wave_display_init
(
&self->state->game->ecs,
self->waveDisplay,
self->spawner
);
entity_combat_timer_display_init
(
&self->state->game->ecs,
self->combatTimerDisplay,
self->spawner
);
entity_wave_timer_display_init
(
&self->state->game->ecs,
self->waveTimerDisplay,
self->spawner
);
entity_elemental_init
(
&self->state->game->ecs,
self->elemental,
(f32*)PLAY_ELEMENTAL_POSITION,
self->spawner,
self->player
);
entity_tutorial_text_init
(
&self->state->game->ecs,
self->tutorialText,
(f32*)PLAY_TUTORIAL_TEXT_POSITION,
self->player
);
entity_sprite_init
(
&self->state->game->ecs,
self->overlay,
self->state->game->resources.textures[TEXTURE_OVERLAY],
(f32*)PLAY_OVERLAY_SIZE,
(f32*)PLAY_OVERLAY_POSITION
);
}
/* Initializes play state. */
void
play_init(Play* self, State* state)
{
memset(self, '\0', sizeof(Play));
self->state = state;
_play_entity_init(self);
music_play(&self->state->game->resources.music[MUSIC_CALM], true);
}
/* Ticks play state. */
void
play_tick(Play* self)
{
ComponentGoodies* goodies;
ComponentHealth* health;
ComponentTimer* timer;
goodies = ecs_component_get(&self->state->game->ecs, ECS_COMPONENT_GOODIES, self->elemental);
health = ecs_component_get(&self->state->game->ecs, ECS_COMPONENT_HEALTH, self->player);
timer = ecs_component_get(&self->state->game->ecs, ECS_COMPONENT_TIMER, self->timerDisplay);
if (goodies->value >= goodies->max)
self->isResults = true;
else if
(
health->isDead ||
timer->isDone
)
self->isGameOver = true;
}