Adds skill return countdown.
Also removes ability to wall-bonk exploit the countdowns.
This commit is contained in:
parent
b6c5edbd92
commit
f7ec1195f4
|
@ -152,8 +152,12 @@ void
|
||||||
particle_engine_speed_lines(Position pos, Dimension dim, bool horizontal)
|
particle_engine_speed_lines(Position pos, Dimension dim, bool horizontal)
|
||||||
{
|
{
|
||||||
static SDL_Color color = { 0, 0, 255, 200 };
|
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;
|
int x, y;
|
||||||
unsigned int lt;
|
unsigned int lt;
|
||||||
Particle *p;
|
Particle *p;
|
||||||
|
|
54
src/player.c
54
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
|
static bool
|
||||||
has_collided(Player *player, RoomMatrix *matrix)
|
has_collided(Player *player, RoomMatrix *matrix)
|
||||||
{
|
{
|
||||||
|
@ -115,6 +129,8 @@ has_collided(Player *player, RoomMatrix *matrix)
|
||||||
|
|
||||||
player_monster_kill_check(player, space->monster);
|
player_monster_kill_check(player, space->monster);
|
||||||
|
|
||||||
|
player_step(player);
|
||||||
|
|
||||||
} else if (collided) {
|
} else if (collided) {
|
||||||
mixer_play_effect(BONK);
|
mixer_play_effect(BONK);
|
||||||
gui_log("Ouch! There is something in the way");
|
gui_log("Ouch! There is something in the way");
|
||||||
|
@ -132,29 +148,15 @@ has_collided(Player *player, RoomMatrix *matrix)
|
||||||
return collided;
|
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
|
static void
|
||||||
move_left(Player *player, RoomMatrix *matrix)
|
move_left(Player *player, RoomMatrix *matrix)
|
||||||
{
|
{
|
||||||
player->sprite->clip.y = 16;
|
player->sprite->clip.y = 16;
|
||||||
player->sprite->pos.x -= TILE_DIMENSION;
|
player->sprite->pos.x -= TILE_DIMENSION;
|
||||||
if (has_collided(player, matrix)) {
|
if (has_collided(player, matrix))
|
||||||
player->sprite->pos.x += TILE_DIMENSION;
|
player->sprite->pos.x += TILE_DIMENSION;
|
||||||
}
|
else
|
||||||
player_step(player);
|
player_step(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -162,10 +164,10 @@ move_right(Player *player, RoomMatrix *matrix)
|
||||||
{
|
{
|
||||||
player->sprite->clip.y = 32;
|
player->sprite->clip.y = 32;
|
||||||
player->sprite->pos.x += TILE_DIMENSION;
|
player->sprite->pos.x += TILE_DIMENSION;
|
||||||
if (has_collided(player, matrix)) {
|
if (has_collided(player, matrix))
|
||||||
player->sprite->pos.x -= TILE_DIMENSION;
|
player->sprite->pos.x -= TILE_DIMENSION;
|
||||||
}
|
else
|
||||||
player_step(player);
|
player_step(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -173,10 +175,10 @@ move_up(Player *player, RoomMatrix *matrix)
|
||||||
{
|
{
|
||||||
player->sprite->clip.y = 48;
|
player->sprite->clip.y = 48;
|
||||||
player->sprite->pos.y -= TILE_DIMENSION;
|
player->sprite->pos.y -= TILE_DIMENSION;
|
||||||
if (has_collided(player, matrix)) {
|
if (has_collided(player, matrix))
|
||||||
player->sprite->pos.y += TILE_DIMENSION;
|
player->sprite->pos.y += TILE_DIMENSION;
|
||||||
}
|
else
|
||||||
player_step(player);
|
player_step(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -184,10 +186,10 @@ move_down(Player *player, RoomMatrix *matrix)
|
||||||
{
|
{
|
||||||
player->sprite->clip.y = 0;
|
player->sprite->clip.y = 0;
|
||||||
player->sprite->pos.y += TILE_DIMENSION;
|
player->sprite->pos.y += TILE_DIMENSION;
|
||||||
if (has_collided(player, matrix)) {
|
if (has_collided(player, matrix))
|
||||||
player->sprite->pos.y -= TILE_DIMENSION;
|
player->sprite->pos.y -= TILE_DIMENSION;
|
||||||
}
|
else
|
||||||
player_step(player);
|
player_step(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -147,6 +147,8 @@ create_sip_health(void)
|
||||||
static bool
|
static bool
|
||||||
skill_charge(Skill *skill, SkillData *data)
|
skill_charge(Skill *skill, SkillData *data)
|
||||||
{
|
{
|
||||||
|
UNUSED(skill);
|
||||||
|
|
||||||
Player *player = data->player;
|
Player *player = data->player;
|
||||||
RoomMatrix *matrix = data->matrix;
|
RoomMatrix *matrix = data->matrix;
|
||||||
|
|
||||||
|
|
|
@ -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 *
|
||||||
skillbar_create(SDL_Renderer *renderer)
|
skillbar_create(SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
|
@ -55,6 +68,7 @@ skillbar_create(SDL_Renderer *renderer)
|
||||||
bar->activationTimer = timer_create();
|
bar->activationTimer = timer_create();
|
||||||
bar->lastActivation = 0;
|
bar->lastActivation = 0;
|
||||||
load_texture(bar, "GUI/GUI0.png", renderer);
|
load_texture(bar, "GUI/GUI0.png", renderer);
|
||||||
|
load_countdown_sprites(bar);
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +127,18 @@ render_activation_indicator(SkillBar *bar, Camera *cam)
|
||||||
SDL_RenderDrawRect(cam->renderer, &square);
|
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
|
static void
|
||||||
render_skills(Player *player, Camera *cam)
|
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_SetRenderDrawColor(cam->renderer, 0, 0, 255, 100);
|
||||||
SDL_RenderFillRect(cam->renderer, &activeSkillBox);
|
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
|
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 };
|
static SDL_Rect unavailableSkillBox = { 0, 0, 32, 32 };
|
||||||
|
|
||||||
|
@ -152,6 +173,7 @@ render_skill_unavailable(Player *player, Camera *cam)
|
||||||
unavailableSkillBox.x = i * 32;
|
unavailableSkillBox.x = i * 32;
|
||||||
SDL_SetRenderDrawColor(cam->renderer, 255, 0, 0, 70);
|
SDL_SetRenderDrawColor(cam->renderer, 255, 0, 0, 70);
|
||||||
SDL_RenderFillRect(cam->renderer, &unavailableSkillBox);
|
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_frame(cam);
|
||||||
render_skills(player, cam);
|
render_skills(player, cam);
|
||||||
render_sprites(bar, cam);
|
render_sprites(bar, cam);
|
||||||
render_skill_unavailable(player, cam);
|
render_skill_unavailable(bar, player, cam);
|
||||||
render_activation_indicator(bar, cam);
|
render_activation_indicator(bar, cam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
typedef struct SkillBar_t {
|
typedef struct SkillBar_t {
|
||||||
LinkedList *sprites;
|
LinkedList *sprites;
|
||||||
|
Sprite *countdowns[PLAYER_SKILL_COUNT];
|
||||||
Timer *activationTimer;
|
Timer *activationTimer;
|
||||||
unsigned int lastActivation;
|
unsigned int lastActivation;
|
||||||
} SkillBar;
|
} SkillBar;
|
||||||
|
|
Loading…
Reference in New Issue