Adds skill return countdown.

Also removes ability to wall-bonk exploit the countdowns.
This commit is contained in:
Linus Probert 2018-03-02 17:05:13 +01:00
parent b6c5edbd92
commit f7ec1195f4
5 changed files with 65 additions and 34 deletions

View File

@ -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;

View File

@ -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,28 +148,14 @@ 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;
}
else
player_step(player);
}
@ -162,9 +164,9 @@ 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;
}
else
player_step(player);
}
@ -173,9 +175,9 @@ 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;
}
else
player_step(player);
}
@ -184,9 +186,9 @@ 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;
}
else
player_step(player);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -27,6 +27,7 @@
typedef struct SkillBar_t {
LinkedList *sprites;
Sprite *countdowns[PLAYER_SKILL_COUNT];
Timer *activationTimer;
unsigned int lastActivation;
} SkillBar;