sprite.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #ifndef sprite_H_INCLUDED
  2. #define sprite_H_INCLUDED
  3. #include "eruta.h"
  4. #include "image.h"
  5. typedef struct SpriteCell_ SpriteCell;
  6. typedef struct SpriteFrame_ SpriteFrame;
  7. typedef struct SpriteAction_ SpriteAction;
  8. typedef struct Sprite_ Sprite;
  9. typedef struct SpriteLayout_ SpriteLayout;
  10. typedef struct SpriteState_ SpriteState;
  11. /* Flags of a Sprite, frame or layer. */
  12. enum SpriteFlags_ {
  13. /* Zero flag means sprite , frame, etc not in use. */
  14. SPRITE_EMPTY = 0,
  15. /* Sprite element is in use if this is set, not if not. */
  16. SPRITE_ACTIVE = 1,
  17. /* Sprite element does not need to be updated. */
  18. SPRITE_FREEZE = 2,
  19. /* Direction flags */
  20. SPRITE_NO_DIRECTION = 0,
  21. SPRITE_SOUTH = 1 << 8,
  22. SPRITE_EAST = 1 << 9,
  23. SPRITE_NORTH = 1 << 10,
  24. SPRITE_WEST = 1 << 11,
  25. SPRITE_ALL = SPRITE_SOUTH + SPRITE_EAST + SPRITE_NORTH + SPRITE_WEST
  26. };
  27. /* Type of the sprite action. The numbers correspond with the
  28. * row in the liberated pixel cup sprite sheet compilation divided by 4,
  29. * which is used placeholder art now. The real art will have the same structure
  30. * for it's sprite sheets.
  31. *
  32. * To limit art requirements, emotions will be showed with emoticons and through
  33. * the character portraits in the dialogues.
  34. *
  35. */
  36. enum SpriteActionType_ {
  37. SPRITE_CAST = 0,
  38. SPRITE_STAB = 1,
  39. SPRITE_WALK = 2,
  40. SPRITE_SLASH = 3,
  41. SPRITE_SHOOT = 4,
  42. SPRITE_DOWN = 5,
  43. /* The positions below are not in the LPC
  44. * sprite sheet but could be synthesized or used in the real art. */
  45. SPRITE_RUN = 6,
  46. SPRITE_HURT = 7,
  47. SPRITE_STAND = 8,
  48. SPRITE_DEFEND = 9,
  49. };
  50. /* Sprite layer suggested uses. For Eruta the game,
  51. * knives, blades, staves, claws, guns and cannons are used,
  52. * but not bows and polearms */
  53. enum SpriteLayerKind_ {
  54. SPRITELAYER_BEHINDBODY = 1,
  55. SPRITELAYER_BODY = 3,
  56. SPRITELAYER_HEAD = 5,
  57. SPRITELAYER_EYES = 7,
  58. SPRITELAYER_EARS = 9,
  59. SPRITELAYER_HAIR = 10,
  60. SPRITELAYER_HANDS = 13,
  61. SPRITELAYER_FEET = 15,
  62. SPRITELAYER_LEGS = 17,
  63. SPRITELAYER_TORSO = 19,
  64. SPRITELAYER_BELT = 21,
  65. SPRITELAYER_ACCESSORY = 23,
  66. SPRITELAYER_BLADE = 25,
  67. SPRITELAYER_KNIFE = 27,
  68. SPRITELAYER_CLAW = 29,
  69. SPRITELAYER_STAFF = 31,
  70. SPRITELAYER_GUN = 33,
  71. SPRITELAYER_CANNON = 35,
  72. SPRITELAYER_POLEARM = 37,
  73. SPRITELAYER_BOW = 39,
  74. };
  75. /* Load type of sprites. */
  76. enum SpriteLoadType_ {
  77. SPRITE_LOAD_ULPCSS_NORMAL = 0,
  78. SPRITE_LOAD_ULPCSS_OVERSIZED_SLASH = 1,
  79. SPRITE_LOAD_ULPCSS_OVERSIZED_STAB = 2,
  80. };
  81. /* Amount of potential actions that a sprite has by default at creation. */
  82. #define SPRITE_NACTIONS_DEFAULT 32
  83. /* Amount of potential frame that a spriteaction has by default at creation. */
  84. #define SPRITEACTION_NFRAMES_DEFAULT 32
  85. /* Amount of potential layers that a spriteframe has by default at creation. */
  86. #define SPRITEFRAME_NLAYERS_DEFAULT 64
  87. int spriteframe_maxlayers(SpriteFrame * self);
  88. SpriteCell * spriteframe_cell(SpriteFrame * self, int index);
  89. int sprite_maxactions(Sprite *self);
  90. SpriteAction * sprite_action(Sprite *self, int index);
  91. SpriteAction * sprite_action_(Sprite *self, int index, SpriteAction * action);
  92. int sprite_frames(Sprite *self, int action);
  93. SpriteFrame * sprite_frame(Sprite *self, int action, int index);
  94. Sprite * sprite_initall(Sprite * self, int index, int nactions);
  95. Sprite * sprite_init(Sprite * self, int index);
  96. Sprite * sprite_done(Sprite * self);
  97. Sprite * sprite_free(Sprite * self);
  98. Sprite * sprite_alloc();
  99. Sprite * sprite_new(int index);
  100. /** Sprite cleanup walker decaration, needed for spritelist.c */
  101. void * sprite_cleanup_walker(void * data, void * extra);
  102. void sprite_draw(Sprite * self, Point * at);
  103. Sprite * sprite_now_(Sprite * self, int actionnow, int framenow);
  104. void sprite_update(Sprite * self, double dt);
  105. SpriteAction * sprite_action_for(Sprite * me, int pose, int direction);
  106. int sprite_action_index_for(Sprite * me, int pose, int direction);
  107. SpriteFrame * spriteaction_newframe
  108. (SpriteAction * self, int index, double duration);
  109. SpriteAction * sprite_newaction
  110. (Sprite * self, int actionindex, int type, int flags);
  111. SpriteCell * sprite_load_cell_from
  112. (Sprite * self, int pose, int direction, int layeri,
  113. Image * source, Point size, Point where, Point offset, double duration);
  114. SpriteFrame * sprite_newframe
  115. (Sprite * self, int actionindex, int frameindex, double duration);
  116. Sprite * sprite_loadlayer_vpath
  117. (Sprite * self, SpriteLayout * layout, int layerindex, char * vpath);
  118. Sprite * sprite_loadlayer_ulpcss_vpath
  119. (Sprite * self, int layerindex, char * vpath, int oversized);
  120. int sprite_framesused(Sprite * self, int actionindex);
  121. double spriteframe_duration(SpriteFrame * me);
  122. int spriteaction_is_pose(SpriteAction * self, int pose, int direction);
  123. int spriteaction_matches_pose(SpriteAction * self, int pose, int direction);
  124. void spritecell_draw_tinted(SpriteCell * self, Point * at, Color tint);
  125. void spritecell_draw(SpriteCell * self, Point * at);
  126. int sprite_id(Sprite * sprite);
  127. Point spritecell_real_position(SpriteCell * self, Point * at);
  128. #endif