Particle sparcle when skill unlocks

Minor modification to dagger damage
This commit is contained in:
Linus Probert 2018-03-24 12:46:23 +01:00
parent 7386b3d582
commit 9a3dd410ab
5 changed files with 69 additions and 52 deletions

View File

@ -495,7 +495,7 @@ run_game(void)
SDL_RenderSetViewport(gRenderer, &gameViewport);
map_render(gMap, &gCamera);
particle_engine_render(&gCamera);
particle_engine_render_game(&gCamera);
if (!is_player_dead())
player_render(gPlayer, &gCamera);
@ -518,6 +518,7 @@ run_game(void)
BOTTOM_GUI_HEIGHT, &gCamera);
SDL_RenderSetViewport(gRenderer, NULL);
particle_engine_render_global(&gCamera);
if (gGameState == IN_GAME_MENU) {
SDL_Rect dimmer = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 150);

View File

@ -37,7 +37,8 @@ typedef struct Particle_t {
} Particle;
typedef struct Engine_t {
LinkedList *particles;
LinkedList *global_particles;
LinkedList *game_particles;
} Engine;
static Engine *engine = NULL;
@ -71,7 +72,8 @@ particle_engine_init(void)
fatal("Engine already initiated");
engine = ec_malloc(sizeof(Engine));
engine->particles = linkedlist_create();
engine->game_particles = linkedlist_create();
engine->global_particles = linkedlist_create();
}
void
@ -106,7 +108,7 @@ particle_engine_bloodspray(Position pos, Dimension dim, unsigned int count)
p->lifetime = lt;
p->dim = (Dimension) { w, h };
p->color = (SDL_Color) { 255, 0, 0, 255 };
linkedlist_append(&engine->particles, p);
linkedlist_append(&engine->game_particles, p);
}
}
@ -142,7 +144,7 @@ create_explosion(Position pos, Dimension dim, unsigned int c_count, ...)
p->lifetime = lt;
p->dim = (Dimension) { 2, 2 };
p->color = colors[get_random((unsigned int) c_count-1)];
linkedlist_append(&engine->particles, p);
linkedlist_append(&engine->game_particles, p);
}
free(colors);
}
@ -195,22 +197,23 @@ particle_engine_speed_lines(Position pos, Dimension dim, bool horizontal)
else
p->dim = (Dimension) { 2, 20 };
p->color = color;
linkedlist_append(&engine->particles, p);
linkedlist_append(&engine->game_particles, p);
}
}
void
particle_engine_sparkle(Position pos, Dimension dim)
{
debug("Sparkling");
for (unsigned int i = 0; i < 50; ++i) {
int x, y, yv;
for (unsigned int i = 0; i < 10; ++i) {
int x, y, yv, alpha;
unsigned int lt;
Particle *p;
x = get_random(dim.width) + pos.x;
y = get_random(dim.height) + pos.y;
alpha = get_random(155) + 100;
yv = (get_random(100) + 100) * -1;
lt = get_random(20);
@ -223,7 +226,9 @@ particle_engine_sparkle(Position pos, Dimension dim)
p->blend_mode = SDL_BLENDMODE_BLEND;
p->dim = (Dimension) { 2, 2 };
p->color = C_WHITE;
linkedlist_append(&engine->particles, p);
p->color.a = alpha;
p->fixed = true;
linkedlist_append(&engine->global_particles, p);
}
}
@ -263,7 +268,7 @@ particle_engine_wind(Vector2d direction)
p->dim = (Dimension) { w, h };
p->color = color;
p->fixed = true;
linkedlist_append(&engine->particles, p);
linkedlist_append(&engine->game_particles, p);
}
}
@ -277,40 +282,34 @@ move_particle(Particle *particle, float deltaTime)
particle->pos.y += (int) (particle->velocity.y * deltaTime);
}
void
particle_engine_update(float deltaTime)
static void
update_particles(LinkedList **particles, float deltaTime)
{
check_engine();
LinkedList *current, *last;
current = engine->particles;
last = NULL;
while (current) {
Particle *particle = current->data;
LinkedList *cleared = linkedlist_create();
while (*particles) {
Particle *particle = linkedlist_pop(particles);
if (particle->movetime)
particle->movetime--;
if (particle->lifetime > 0) {
particle->lifetime--;
move_particle(current->data, deltaTime);
last = current;
current = current->next;
move_particle(particle, deltaTime);
linkedlist_push(&cleared, particle);
} else {
if (!last) {
engine->particles = current->next;
free(current->data);
free(current);
current = engine->particles;
} else {
last->next = current->next;
free(current->data);
free(current);
current = last->next;
}
free(particle);
}
}
*particles = cleared;
}
void
particle_engine_update(float deltaTime)
{
check_engine();
update_particles(&engine->global_particles, deltaTime);
update_particles(&engine->game_particles, deltaTime);
}
static void
@ -322,7 +321,6 @@ render_particle(Particle *p, Camera *cam)
else
pos = camera_to_camera_position(cam, &p->pos);
// Make the particles look visible on all surfaces
SDL_SetRenderDrawBlendMode(cam->renderer, p->blend_mode);
SDL_Rect box = { pos.x, pos.y, p->dim.width, p->dim.height };
@ -337,24 +335,37 @@ render_particle(Particle *p, Camera *cam)
SDL_SetRenderDrawBlendMode(cam->renderer, SDL_BLENDMODE_BLEND);
}
void
particle_engine_render(Camera *cam)
static void
render_particles(LinkedList *particles, Camera *cam)
{
check_engine();
LinkedList *particles = engine->particles;
while (particles) {
render_particle(particles->data, cam);
particles = particles->next;
LinkedList *render_list = particles;
while (render_list) {
render_particle(render_list->data, cam);
render_list = render_list->next;
}
}
void
particle_engine_render_game(Camera *cam)
{
render_particles(engine->game_particles, cam);
}
void
particle_engine_render_global(Camera *cam)
{
render_particles(engine->global_particles, cam);
}
void
particle_engine_clear(void)
{
check_engine();
while (engine->particles)
free(linkedlist_pop(&engine->particles));
while (engine->game_particles)
free(linkedlist_pop(&engine->game_particles));
}
void
@ -362,8 +373,8 @@ particle_engine_close(void)
{
check_engine();
while (engine->particles)
free(linkedlist_pop(&engine->particles));
while (engine->game_particles)
free(linkedlist_pop(&engine->game_particles));
free(engine);
engine = NULL;

View File

@ -50,7 +50,10 @@ void
particle_engine_update(float deltatime);
void
particle_engine_render(Camera*);
particle_engine_render_game(Camera*);
void
particle_engine_render_global(Camera*);
void
particle_engine_clear(void);

View File

@ -90,13 +90,15 @@ projectile_update(Projectile *p, UpdateData *data)
return;
if (space->monster) {
Uint32 dmg = stats_fight(&data->player->stats, &space->monster->stats);
Stats tmpStats = data->player->stats;
tmpStats.dmg *= 2;
Uint32 dmg = stats_fight(&tmpStats, &space->monster->stats);
if (dmg > 0) {
gui_log("Your dagger pierced %s for %u damage", space->monster->lclabel, dmg);
mixer_play_effect(SWORD_HIT);
data->player->hits += 1;
}
if (get_random(2) == 0) {
if (get_random(2) >= 1) {
Item *item = item_builder_build_item(DAGGER, 1);
item->sprite->pos = space->monster->sprite->pos;
linkedlist_append(&data->map->items, item);

View File

@ -219,12 +219,12 @@ render_skill_unavailable(SkillBar *bar, Player *player, Camera *cam)
static void
render_skill_sparkles(SkillBar *bar, Player *player)
{
if (timer_get_ticks(bar->skillSparkleTimer) > 3000) {
if (timer_get_ticks(bar->skillSparkleTimer) > 1500) {
timer_stop(bar->skillSparkleTimer);
return;
}
Position pos = { 0, 0 };
Position pos = { 0, GAME_VIEW_HEIGHT };
Dimension dim = { 32, 32 };
for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) {
if (!player->skills[i])