@@ -64,6 +64,15 @@ levelup(Player *player)
6464 player -> stats .hp = player -> stats .maxhp ;
6565}
6666
67+ static void
68+ player_particle_bleed (Position pos , Dimension dim , void * userdata )
69+ {
70+ Player * p = userdata ;
71+ float perc = (float ) p -> stats .hp / p -> stats .maxhp ;
72+ Uint32 particle_count = (Uint32 ) (20.0f * perc );
73+ particle_engine_bloodspray (pos , dim , particle_count );
74+ }
75+
6776void
6877player_levelup (Player * player )
6978{
@@ -320,15 +329,26 @@ player_turn(Player *player, Vector2d *direction)
320329 }
321330}
322331
332+ void
333+ player_update_pos (Player * player , Uint32 dx , Uint32 dy )
334+ {
335+ player -> sprite -> pos .x += dx ;
336+ player -> sprite -> pos .y += dy ;
337+
338+ Position pos = player -> sprite -> pos ;
339+ pos .x += 5 ;
340+ pos .y += 5 ;
341+ particle_emitter_update (player -> bleed_emitter , pos , DIM (10 , 10 ));
342+ }
343+
323344static void
324345move (Player * player , RoomMatrix * matrix , Vector2d direction )
325346{
326347 player_turn (player , & direction );
327348
328349 Position lastPos = position_to_matrix_coords (& player -> sprite -> pos );
329350
330- player -> sprite -> pos .x += TILE_DIMENSION * (int ) direction .x ;
331- player -> sprite -> pos .y += TILE_DIMENSION * (int ) direction .y ;
351+ player_update_pos (player , TILE_DIMENSION * (int ) direction .x , TILE_DIMENSION * (int ) direction .y );
332352
333353 if (!has_collided (player , matrix , direction )) {
334354 action_spent (player );
@@ -547,6 +567,13 @@ player_create(class_t class, Camera *cam)
547567 player -> equipment .keys = 0 ;
548568 player -> stateData .shopOwnerKiller = false;
549569
570+ ParticleEmitter * emitter = particle_emitter_create ();
571+ emitter -> timestep = 2000 ;
572+ emitter -> enabled = false;
573+ emitter -> particle_func = particle_engine_bleed ;
574+ emitter -> userdata = player ;
575+ player -> bleed_emitter = emitter ;
576+
550577 build_sword_animation (player , cam -> renderer );
551578
552579 memset (& player -> skills ,
@@ -701,6 +728,8 @@ player_render(Player *player, Camera *cam)
701728 projectile_render (projectile -> data , cam );
702729 projectile = projectile -> next ;
703730 }
731+
732+ particle_emitter_render (player -> bleed_emitter );
704733}
705734
706735void
@@ -759,6 +788,9 @@ player_update(UpdateData *data)
759788 player -> projectiles = remaining ;
760789
761790 animation_update (player -> swordAnimation );
791+
792+ uint32_t damage_taken = player -> stats .maxhp - player -> stats .hp ;
793+ player -> bleed_emitter -> enabled = damage_taken >= player -> stats .maxhp / 2 ;
762794}
763795
764796static void
@@ -789,6 +821,8 @@ player_destroy(Player *player)
789821 player -> skills [i ] = NULL ;
790822 }
791823
824+ particle_emitter_destroy (player -> bleed_emitter );
825+
792826 free (player );
793827}
794828
0 commit comments