Adds levelcaps to skills

Still need to add the sparkles when they activate
This commit is contained in:
Linus Probert 2018-03-23 22:03:34 +01:00
parent 2204c7bade
commit 7386b3d582
10 changed files with 115 additions and 6 deletions

View File

@ -60,6 +60,10 @@
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
#define UNPACK_COLOR(color) color.r, color.g, color.b, color.a
#define C_WHITE (SDL_Color) { 255, 255, 255, 255 }
#define C_BLACK (SDL_Color) { 0, 0, 0, 255 }
typedef enum Direction_t { typedef enum Direction_t {
UP, DOWN, LEFT, RIGHT UP, DOWN, LEFT, RIGHT
} Direction; } Direction;

View File

@ -459,6 +459,7 @@ static void
run_game(void) run_game(void)
{ {
static UpdateData updateData; static UpdateData updateData;
static unsigned int playerLevel = 1;
map_clear_dead_monsters(gMap, gPlayer); map_clear_dead_monsters(gMap, gPlayer);
map_clear_collected_items(gMap); map_clear_collected_items(gMap);
@ -469,6 +470,10 @@ run_game(void)
roommatrix_build_lightmap(gRoomMatrix); roommatrix_build_lightmap(gRoomMatrix);
populateUpdateData(&updateData, deltaTime); populateUpdateData(&updateData, deltaTime);
if (playerLevel != gPlayer->stats.lvl) {
playerLevel = gPlayer->stats.lvl;
skillbar_check_skill_activation(gSkillBar, gPlayer);
}
gui_update_player_stats(gGui, gPlayer, gMap, gRenderer); gui_update_player_stats(gGui, gPlayer, gMap, gRenderer);
particle_engine_update(deltaTime); particle_engine_update(deltaTime);
player_update(&updateData); player_update(&updateData);

View File

@ -32,6 +32,7 @@ typedef struct Particle_t {
unsigned int movetime; unsigned int movetime;
unsigned int lifetime; unsigned int lifetime;
bool fixed; bool fixed;
Uint8 blend_mode;
SDL_Color color; SDL_Color color;
} Particle; } Particle;
@ -51,6 +52,7 @@ create_particle(void)
p->movetime = 100; p->movetime = 100;
p->lifetime = 100; p->lifetime = 100;
p->fixed = false; p->fixed = false;
p->blend_mode = SDL_BLENDMODE_MOD;
p->color = (SDL_Color) { 255, 255, 255, 255 }; p->color = (SDL_Color) { 255, 255, 255, 255 };
return p; return p;
} }
@ -197,6 +199,34 @@ particle_engine_speed_lines(Position pos, Dimension dim, bool horizontal)
} }
} }
void
particle_engine_sparkle(Position pos, Dimension dim)
{
debug("Sparkling");
for (unsigned int i = 0; i < 50; ++i) {
int x, y, yv;
unsigned int lt;
Particle *p;
x = get_random(dim.width) + pos.x;
y = get_random(dim.height) + pos.y;
yv = (get_random(100) + 100) * -1;
lt = get_random(20);
p = create_particle();
p->pos = (Position) { x, y };
p->velocity = (Vector2d) { (float) 0, (float) yv };
p->movetime = lt;
p->lifetime = lt;
p->blend_mode = SDL_BLENDMODE_BLEND;
p->dim = (Dimension) { 2, 2 };
p->color = C_WHITE;
linkedlist_append(&engine->particles, p);
}
}
void void
particle_engine_wind(Vector2d direction) particle_engine_wind(Vector2d direction)
{ {
@ -293,7 +323,7 @@ render_particle(Particle *p, Camera *cam)
pos = camera_to_camera_position(cam, &p->pos); pos = camera_to_camera_position(cam, &p->pos);
// Make the particles look visible on all surfaces // Make the particles look visible on all surfaces
SDL_SetRenderDrawBlendMode(cam->renderer, SDL_BLENDMODE_MOD); SDL_SetRenderDrawBlendMode(cam->renderer, p->blend_mode);
SDL_Rect box = { pos.x, pos.y, p->dim.width, p->dim.height }; SDL_Rect box = { pos.x, pos.y, p->dim.width, p->dim.height };
SDL_SetRenderDrawColor(cam->renderer, SDL_SetRenderDrawColor(cam->renderer,

View File

@ -40,6 +40,9 @@ particle_engine_eldritch_explosion(Position, Dimension);
void void
particle_engine_speed_lines(Position, Dimension, bool horizontal); particle_engine_speed_lines(Position, Dimension, bool horizontal);
void
particle_engine_sparkle(Position, Dimension);
void void
particle_engine_wind(Vector2d direction); particle_engine_wind(Vector2d direction);

View File

@ -271,8 +271,10 @@ check_skill_activation(Player *player, RoomMatrix *matrix, SDL_Event *event)
continue; continue;
Skill *skill = player->skills[i]; Skill *skill = player->skills[i];
if (skill->levelcap > player->stats.lvl)
continue;
if (skill->available && !skill->available(player)) if (skill->available && !skill->available(player))
continue; continue;
skill->active = (selected - 1) == i && !skill->active && skill->resetCountdown == 0; skill->active = (selected - 1) == i && !skill->active && skill->resetCountdown == 0;
if (skill->active && skill->instantUse) { if (skill->active && skill->instantUse) {
SkillData skillData = { player, matrix, VECTOR2D_NODIR }; SkillData skillData = { player, matrix, VECTOR2D_NODIR };

View File

@ -49,7 +49,7 @@ pointer_handle_event(Pointer *p, SDL_Event *event)
#ifdef DEBUG #ifdef DEBUG
if (event->type == SDL_MOUSEBUTTONDOWN) { if (event->type == SDL_MOUSEBUTTONDOWN) {
Dimension dim = { 10, 10 }; Dimension dim = { 10, 10 };
particle_engine_eldritch_explosion(p->sprite->pos, dim); particle_engine_sparkle(p->sprite->pos, dim);
} }
#endif // DEBUG #endif // DEBUG
} }

View File

@ -59,6 +59,7 @@ create_default(const char *s_label, Sprite *s)
skill->active = false; skill->active = false;
skill->available = NULL; skill->available = NULL;
skill->use = NULL; skill->use = NULL;
skill->levelcap = 1;
return skill; return skill;
} }
@ -120,6 +121,7 @@ create_flurry(void)
s->clip = CLIP32(0, 0); s->clip = CLIP32(0, 0);
s->fixed = true; s->fixed = true;
Skill *skill = create_default("Flurry", s); Skill *skill = create_default("Flurry", s);
skill->levelcap = 2;
skill->use = skill_use_flurry; skill->use = skill_use_flurry;
return skill; return skill;
} }
@ -169,6 +171,7 @@ create_throw_dagger(void)
s->clip = CLIP32(64, 0); s->clip = CLIP32(64, 0);
s->fixed = true; s->fixed = true;
Skill *skill = create_default("Throw dagger", s); Skill *skill = create_default("Throw dagger", s);
skill->levelcap = 1;
skill->instantUse = false; skill->instantUse = false;
skill->resetTime = 1; skill->resetTime = 1;
skill->available = skill_throw_dagger_available; skill->available = skill_throw_dagger_available;
@ -201,6 +204,7 @@ create_sip_health(void)
s->clip = CLIP16(0, 0); s->clip = CLIP16(0, 0);
s->fixed = true; s->fixed = true;
Skill *skill = create_default("Sip health", s); Skill *skill = create_default("Sip health", s);
skill->levelcap = 1;
skill->instantUse = true; skill->instantUse = true;
skill->available = skill_sip_health_available; skill->available = skill_sip_health_available;
skill->use = skill_sip_health; skill->use = skill_sip_health;
@ -297,6 +301,7 @@ create_charge(void)
s->clip = CLIP32(32, 0); s->clip = CLIP32(32, 0);
s->fixed = true; s->fixed = true;
Skill *skill = create_default("Charge", s); Skill *skill = create_default("Charge", s);
skill->levelcap = 4;
skill->use = skill_charge; skill->use = skill_charge;
return skill; return skill;
} }

View File

@ -45,6 +45,7 @@ typedef struct Skill_t {
Sprite *icon; Sprite *icon;
unsigned int resetTime; unsigned int resetTime;
unsigned int resetCountdown; unsigned int resetCountdown;
unsigned int levelcap;
bool actionRequired; bool actionRequired;
bool instantUse; bool instantUse;
bool active; bool active;

View File

@ -24,6 +24,7 @@
#include "sprite.h" #include "sprite.h"
#include "keyboard.h" #include "keyboard.h"
#include "texturecache.h" #include "texturecache.h"
#include "particle_engine.h"
static void static void
load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer) load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer)
@ -66,12 +67,27 @@ skillbar_create(SDL_Renderer *renderer)
SkillBar *bar = ec_malloc(sizeof(SkillBar)); SkillBar *bar = ec_malloc(sizeof(SkillBar));
bar->sprites = linkedlist_create(); bar->sprites = linkedlist_create();
bar->activationTimer = timer_create(); bar->activationTimer = timer_create();
bar->skillSparkleTimer = 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); load_countdown_sprites(bar);
return bar; return bar;
} }
void
skillbar_check_skill_activation(SkillBar *bar, Player *player)
{
for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) {
if (!player->skills[i])
continue;
if (player->skills[i]->levelcap != player->stats.lvl)
continue;
timer_start(bar->skillSparkleTimer);
}
}
static void static void
render_frame(Camera *cam) render_frame(Camera *cam)
{ {
@ -169,21 +185,58 @@ 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 };
for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) { for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) {
bool unavailable = false;
SDL_Color color;
if (!player->skills[i]) if (!player->skills[i])
continue; continue;
Skill *skill = player->skills[i]; Skill *skill = player->skills[i];
if (skill->resetCountdown || (skill->available && !skill->available(player))) { if (skill->levelcap > player->stats.lvl) {
unavailable = true;
color = (SDL_Color) { 0, 0, 0, 220 };
} else if (skill->resetCountdown
|| (skill->available && !skill->available(player)))
{
unavailable = true;
color = (SDL_Color) { 255, 0, 0, 70 };
}
if (unavailable) {
unavailableSkillBox.x = i * 32; unavailableSkillBox.x = i * 32;
SDL_SetRenderDrawColor(cam->renderer, 255, 0, 0, 70); SDL_SetRenderDrawColor(cam->renderer, UNPACK_COLOR(color));
SDL_RenderFillRect(cam->renderer, &unavailableSkillBox); SDL_RenderFillRect(cam->renderer, &unavailableSkillBox);
if (skill->resetCountdown) { if (skill->resetCountdown) {
render_skill_countdown(bar, i, skill->resetCountdown, cam); render_skill_countdown(bar,
i,
skill->resetCountdown,
cam);
} }
} }
} }
} }
static void
render_skill_sparkles(SkillBar *bar, Player *player)
{
if (timer_get_ticks(bar->skillSparkleTimer) > 3000) {
timer_stop(bar->skillSparkleTimer);
return;
}
Position pos = { 0, 0 };
Dimension dim = { 32, 32 };
for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) {
if (!player->skills[i])
continue;
else if (player->skills[i]->levelcap != player->stats.lvl)
continue;
pos.x += 32 * i;
particle_engine_sparkle(pos, dim);
}
}
void void
skillbar_render(SkillBar *bar, Player *player, Camera *cam) skillbar_render(SkillBar *bar, Player *player, Camera *cam)
{ {
@ -192,6 +245,8 @@ skillbar_render(SkillBar *bar, Player *player, Camera *cam)
render_sprites(bar, cam); render_sprites(bar, cam);
render_skill_unavailable(bar, player, cam); render_skill_unavailable(bar, player, cam);
render_activation_indicator(bar, cam); render_activation_indicator(bar, cam);
if (timer_started(bar->skillSparkleTimer))
render_skill_sparkles(bar, player);
} }
void void

View File

@ -29,12 +29,16 @@ typedef struct SkillBar_t {
LinkedList *sprites; LinkedList *sprites;
Sprite *countdowns[PLAYER_SKILL_COUNT]; Sprite *countdowns[PLAYER_SKILL_COUNT];
Timer *activationTimer; Timer *activationTimer;
Timer *skillSparkleTimer;
unsigned int lastActivation; unsigned int lastActivation;
} SkillBar; } SkillBar;
SkillBar * SkillBar *
skillbar_create(SDL_Renderer*); skillbar_create(SDL_Renderer*);
void
skillbar_check_skill_activation(SkillBar*, Player*);
void void
skillbar_render(SkillBar*, Player*, Camera*); skillbar_render(SkillBar*, Player*, Camera*);