explosions.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "explosions.h"
  2. #include "images_diffuse.h"
  3. #include "tag.h"
  4. declare_body(frame_killer, {
  5. size_t frames;
  6. })
  7. declare_tick(frame_killer, {
  8. if(--self->frames == 0) return 1;
  9. })
  10. declare_draw(frame_killer, { })
  11. declare_head(frame_killer)
  12. void kill_on_frame(entity *ent, size_t frame) {
  13. frame_killer *fk = c_new(frame_killer);
  14. fk->frames = frame;
  15. add_component(ent, fk);
  16. }
  17. entity *laser_explosion(vec pos) {
  18. entity *ent = ent_new();
  19. ent->position = vadd(pos, vxy(-4, -5));
  20. ent->tag = TAG_EXPLOSION;
  21. add_component(ent, get_animator(&sprite_laser_explode, 1));
  22. kill_on_frame(ent, 5);
  23. return ent;
  24. }
  25. entity *satellite_explosion(vec pos) {
  26. entity *ent = ent_new();
  27. ent->position = vadd(pos, vxy(-6, 0));
  28. ent->tag = TAG_EXPLOSION;
  29. add_component(ent, get_animator(&sprite_satellite_bullet_explode, 1));
  30. kill_on_frame(ent, 6);
  31. return ent;
  32. }
  33. entity *basic_spray_explosion(vec pos) {
  34. entity *ent = ent_new();
  35. ent->position = vadd(pos, vxy(-10, 0));
  36. ent->tag = TAG_EXPLOSION;
  37. add_component(ent, get_animator(&sprite_basic_spray_explode, 1));
  38. kill_on_frame(ent, 6);
  39. return ent;
  40. }
  41. entity *player_warp_animation() {
  42. entity *ent = ent_new();
  43. ent->tag = TAG_WARP;
  44. add_component(ent, get_animator(&sprite_player_ship_warp, 2));
  45. kill_on_frame(ent, 20 * 2);
  46. return ent;
  47. }