From f7ec1195f4e4c64244aea77f2e286547fc72b4a9 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Fri, 2 Mar 2018 17:05:13 +0100 Subject: [PATCH] Adds skill return countdown. Also removes ability to wall-bonk exploit the countdowns. --- src/particle_engine.c | 6 ++++- src/player.c | 54 ++++++++++++++++++++++--------------------- src/skill.c | 2 ++ src/skillbar.c | 36 +++++++++++++++++++++++------ src/skillbar.h | 1 + 5 files changed, 65 insertions(+), 34 deletions(-) diff --git a/src/particle_engine.c b/src/particle_engine.c index 0ab05f4..84cffef 100644 --- a/src/particle_engine.c +++ b/src/particle_engine.c @@ -152,8 +152,12 @@ void particle_engine_speed_lines(Position pos, Dimension dim, bool horizontal) { static SDL_Color color = { 0, 0, 255, 200 }; + unsigned int count = (unsigned int) (dim.width + dim.height) / 2; - for (unsigned int i = 0; i < 150; ++i) { + if (dim.width == 0 || dim.height == 0) + return; + + for (unsigned int i = 0; i < count; ++i) { int x, y; unsigned int lt; Particle *p; diff --git a/src/player.c b/src/player.c index dad4bbf..c795ac7 100644 --- a/src/player.c +++ b/src/player.c @@ -77,6 +77,20 @@ player_gain_xp(Player *player, unsigned int xp_gain) } } +static void +player_step(Player *p) +{ + p->total_steps++; + p->steps++; + p->missText->pos = p->sprite->pos; + p->hitText->pos = p->sprite->pos; + + for (size_t i = 0; i < PLAYER_SKILL_COUNT; ++i) { + if (p->skills[i] != NULL && p->skills[i]->resetCountdown > 0) + p->skills[i]->resetCountdown--; + } +} + static bool has_collided(Player *player, RoomMatrix *matrix) { @@ -115,6 +129,8 @@ has_collided(Player *player, RoomMatrix *matrix) player_monster_kill_check(player, space->monster); + player_step(player); + } else if (collided) { mixer_play_effect(BONK); gui_log("Ouch! There is something in the way"); @@ -132,29 +148,15 @@ has_collided(Player *player, RoomMatrix *matrix) return collided; } -static void -player_step(Player *p) -{ - p->total_steps++; - p->steps++; - p->missText->pos = p->sprite->pos; - p->hitText->pos = p->sprite->pos; - - for (size_t i = 0; i < PLAYER_SKILL_COUNT; ++i) { - if (p->skills[i] != NULL && p->skills[i]->resetCountdown > 0) - p->skills[i]->resetCountdown--; - } -} - static void move_left(Player *player, RoomMatrix *matrix) { player->sprite->clip.y = 16; player->sprite->pos.x -= TILE_DIMENSION; - if (has_collided(player, matrix)) { + if (has_collided(player, matrix)) player->sprite->pos.x += TILE_DIMENSION; - } - player_step(player); + else + player_step(player); } static void @@ -162,10 +164,10 @@ move_right(Player *player, RoomMatrix *matrix) { player->sprite->clip.y = 32; player->sprite->pos.x += TILE_DIMENSION; - if (has_collided(player, matrix)) { + if (has_collided(player, matrix)) player->sprite->pos.x -= TILE_DIMENSION; - } - player_step(player); + else + player_step(player); } static void @@ -173,10 +175,10 @@ move_up(Player *player, RoomMatrix *matrix) { player->sprite->clip.y = 48; player->sprite->pos.y -= TILE_DIMENSION; - if (has_collided(player, matrix)) { + if (has_collided(player, matrix)) player->sprite->pos.y += TILE_DIMENSION; - } - player_step(player); + else + player_step(player); } static void @@ -184,10 +186,10 @@ move_down(Player *player, RoomMatrix *matrix) { player->sprite->clip.y = 0; player->sprite->pos.y += TILE_DIMENSION; - if (has_collided(player, matrix)) { + if (has_collided(player, matrix)) player->sprite->pos.y -= TILE_DIMENSION; - } - player_step(player); + else + player_step(player); } void diff --git a/src/skill.c b/src/skill.c index 853cfa0..663c6f2 100644 --- a/src/skill.c +++ b/src/skill.c @@ -147,6 +147,8 @@ create_sip_health(void) static bool skill_charge(Skill *skill, SkillData *data) { + UNUSED(skill); + Player *player = data->player; RoomMatrix *matrix = data->matrix; diff --git a/src/skillbar.c b/src/skillbar.c index 37ac153..7eb7675 100644 --- a/src/skillbar.c +++ b/src/skillbar.c @@ -47,6 +47,19 @@ load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer) } } +static void +load_countdown_sprites(SkillBar *bar) +{ + for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) { + Sprite *s = sprite_create(); + sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, 16); + s->fixed = true; + s->pos = (Position) { 8 + (32 * i), 8 }; + s->dim = (Dimension) { 16, 16 }; + bar->countdowns[i] = s; + } +} + SkillBar * skillbar_create(SDL_Renderer *renderer) { @@ -55,6 +68,7 @@ skillbar_create(SDL_Renderer *renderer) bar->activationTimer = timer_create(); bar->lastActivation = 0; load_texture(bar, "GUI/GUI0.png", renderer); + load_countdown_sprites(bar); return bar; } @@ -113,6 +127,18 @@ render_activation_indicator(SkillBar *bar, Camera *cam) SDL_RenderDrawRect(cam->renderer, &square); } +static void +render_skill_countdown(SkillBar *bar, int index, unsigned int count, Camera *cam) +{ + static SDL_Color color = { 255, 255, 255, 255 }; + char buffer[5]; + Sprite *s = bar->countdowns[index]; + + m_sprintf(buffer, 5, "%u", count); + texture_load_from_text(s->textures[0], buffer, color, cam->renderer); + sprite_render(s, cam); +} + static void render_skills(Player *player, Camera *cam) { @@ -131,16 +157,11 @@ render_skills(Player *player, Camera *cam) SDL_SetRenderDrawColor(cam->renderer, 0, 0, 255, 100); SDL_RenderFillRect(cam->renderer, &activeSkillBox); } - if (player->skills[i]->resetCountdown > 0) { - activeSkillBox.x = i * 32; - SDL_SetRenderDrawColor(cam->renderer, 255, 0, 0, 100); - SDL_RenderFillRect(cam->renderer, &activeSkillBox); - } } } static void -render_skill_unavailable(Player *player, Camera *cam) +render_skill_unavailable(SkillBar *bar, Player *player, Camera *cam) { static SDL_Rect unavailableSkillBox = { 0, 0, 32, 32 }; @@ -152,6 +173,7 @@ render_skill_unavailable(Player *player, Camera *cam) unavailableSkillBox.x = i * 32; SDL_SetRenderDrawColor(cam->renderer, 255, 0, 0, 70); SDL_RenderFillRect(cam->renderer, &unavailableSkillBox); + render_skill_countdown(bar, i, player->skills[i]->resetCountdown, cam); } } } @@ -162,7 +184,7 @@ skillbar_render(SkillBar *bar, Player *player, Camera *cam) render_frame(cam); render_skills(player, cam); render_sprites(bar, cam); - render_skill_unavailable(player, cam); + render_skill_unavailable(bar, player, cam); render_activation_indicator(bar, cam); } diff --git a/src/skillbar.h b/src/skillbar.h index 3feade5..3f8a046 100644 --- a/src/skillbar.h +++ b/src/skillbar.h @@ -27,6 +27,7 @@ typedef struct SkillBar_t { LinkedList *sprites; + Sprite *countdowns[PLAYER_SKILL_COUNT]; Timer *activationTimer; unsigned int lastActivation; } SkillBar;