demo_character.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /* License Notice:
  2. **
  3. ** This program is free software: you can redistribute it and/or modify
  4. ** it under the terms of the GNU General Public License as published by
  5. ** the Free Software Foundation, either version 3 of the License, or
  6. ** (at your option) any later version.
  7. ** This program is distributed in the hope that it will be useful,
  8. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ** GNU General Public License for more details.
  11. ** You should have received a copy of the GNU General Public License
  12. ** along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. */
  14. /**
  15. * @file demo_character.hpp
  16. * @author TooOld2Rock'nRoll
  17. * @date 2024/03/06
  18. * @brief A example character for the ArcadeFighter Library.
  19. *
  20. * @todo Use the loading thread for resources....
  21. * @todo Falling is now implemented in two places (jump and long jump states update), need a physics class!
  22. * @todo Import character statistics from a file.
  23. * @todo Import character animations from a file.
  24. */
  25. #ifndef _DEMO_CHARACTER_HPP_
  26. #define _DEMO_CHARACTER_HPP_
  27. /*---- Includes ----*/
  28. #include "character.hpp"
  29. /*---- Enums ----*/
  30. extern "C" {
  31. typedef enum _extended_commands_
  32. {
  33. LIGHT_PUNCH = character_commands_t::_command_max, //<-- enumeration will start where character_commands ended
  34. HARD_PUNCH,
  35. SHORT_JUMP,
  36. LONG_JUMP,
  37. CROUCH_WALK,
  38. RUN,
  39. _extend_command_max
  40. } extended_character_commands_e;
  41. typedef enum _extended_char_state_
  42. {
  43. ROLLING = character_state_t::_state_max, //<-- enumeration will start where character_state ended
  44. DASHING, ///< Character is in the middle of a dash.
  45. CROUCH_WALKING,
  46. RUNNING, ///<Double left/right click-hold
  47. LONG_JUMPIMP, ///<Jump from running.
  48. _extend_state_max
  49. } extended_character_state_e;
  50. }//end extern "C"
  51. /*---- Class Declaration ----*/
  52. /**
  53. * @brief A example of how a character could be implemented extending the Character class.
  54. * @extends Character
  55. */
  56. class DemoCharacter : public Character
  57. {
  58. public:
  59. enum animation_list_e
  60. {
  61. LOADING = 0,
  62. OPENING_ANIME, //no animation yet!
  63. WIN, //no animation yet!
  64. LOSE,
  65. IDLE,
  66. WALKING,
  67. RUNNING,
  68. DASHING, //no animation yet!
  69. ROLLING,
  70. CROUCH_IDLE,
  71. CROUCH_WALKING,
  72. JUMP,
  73. AIR_SPIN,
  74. LAND,
  75. BLOCK,
  76. JAB,
  77. CROSS,
  78. _anime_max ///< Just to keep count of enum size.
  79. };//end animation_list
  80. enum audio_effect_list_e
  81. {
  82. SOUND_LIGHT_PUNCH = 0,
  83. SOUND_HARD_PUNCH,
  84. SOUND_JUMP,
  85. SOUND_LAND,
  86. _audio_effect_max ///< Just to keep count of enum size.
  87. };//end audio_effect_list_e
  88. private:
  89. Audio::Effect *punch = nullptr;
  90. void _populateDefaultCommandList ();
  91. void _populateDefaultStatesList ();
  92. void _populateDefaultChainActions ();
  93. protected:
  94. public:
  95. DemoCharacter (DomainID_t domain_id, Shader *sh);
  96. virtual void load () override final;
  97. };//END DemoCharacter
  98. /*---- Custom Commands ----*/
  99. /** @brief Command that makes the Character move in walking speed. */
  100. class WalkCommand : public Command<DemoCharacter>
  101. { virtual void execute (DemoCharacter &puppet, double delta_t) override; };
  102. /** @brief Command that makes the Character move in running speed. */
  103. class RunCommand : public Command<DemoCharacter>
  104. { virtual void execute (DemoCharacter &puppet, double delta_t) override; };
  105. /** @brief Command that makes the Character jump. */
  106. class JumpCommand : public Command<DemoCharacter>
  107. { virtual void execute (DemoCharacter &puppet, double delta_t) override; };
  108. /** @brief Command that makes the Character do a shot forward/backward jump. */
  109. class ShortJumpCommand : public Command<DemoCharacter>
  110. { virtual void execute (DemoCharacter &puppet, double delta_t) override; };
  111. /** @brief Command that makes the Character do a long forward/backward jump. */
  112. class LongJumpCommand : public Command<DemoCharacter>
  113. { virtual void execute (DemoCharacter &puppet, double delta_t) override; };
  114. /** @brief Command that makes the Character attack with a light punch. */
  115. class LightPunchCommand : public Command<DemoCharacter>
  116. { void execute (DemoCharacter &puppet, double delta_t) override final; };
  117. /** @brief Command that makes the Character attack with a hard punch. */
  118. class HardPunchCommand : public Command<DemoCharacter>
  119. { void execute (DemoCharacter &puppet, double delta_t) override final; };
  120. /** @brief Command that makes the Character move in crouched speed. */
  121. class CrouchWalkCommand : public Command<DemoCharacter>
  122. { void execute (DemoCharacter &puppet, double delta_t) override final; };
  123. /*---- Custom States ----*/
  124. /** @brief A state to uso on loading screens. */
  125. class LoadingState : public State<DemoCharacter>
  126. {
  127. public:
  128. void enter (DemoCharacter &puppet) override final
  129. { puppet.setActiveSprite (DemoCharacter::animation_list_e::LOADING); }
  130. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final
  131. { return true; }
  132. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final
  133. { /* ignore all */ }
  134. void update (DemoCharacter &puppet, double delta_t) override final
  135. { puppet.getActiveSprite().update (delta_t); }
  136. };//END IdleState
  137. /** @brief A basic Idle state. */
  138. class IdleState : public AutomatedState<DemoCharacter>
  139. {
  140. public:
  141. IdleState ();
  142. void enter (DemoCharacter &puppet) override final
  143. { puppet.setActiveSprite (DemoCharacter::animation_list_e::IDLE); }
  144. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  145. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  146. void update (DemoCharacter &puppet, double delta_t) override final;
  147. };//END IdleState
  148. /** @brief A basic walking state. */
  149. class WalkingState : public State<DemoCharacter>
  150. {
  151. public:
  152. void enter (DemoCharacter &puppet) override final;
  153. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  154. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  155. void update (DemoCharacter &puppet, double delta_t) override final;
  156. };//END WalkingState
  157. /** @brief A extended running state. */
  158. class RunningState : public State<DemoCharacter>
  159. {
  160. public:
  161. void enter (DemoCharacter &puppet) override final;
  162. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  163. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  164. void update (DemoCharacter &puppet, double delta_t) override final;
  165. };//END RunningState
  166. /** @brief A basic crouch state. */
  167. class CrouchState : public State<DemoCharacter>
  168. {
  169. public:
  170. void enter (DemoCharacter &puppet) override final
  171. { puppet.setActiveSprite (DemoCharacter::animation_list_e::CROUCH_IDLE); }
  172. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  173. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  174. void update (DemoCharacter &puppet, double delta_t) override final;
  175. };//END CrouchState
  176. /** @brief A extended crouch walking state. */
  177. class CrouchWalkingState : public State<DemoCharacter>
  178. {
  179. public:
  180. void enter (DemoCharacter &puppet) override final
  181. { puppet.setActiveSprite (DemoCharacter::animation_list_e::CROUCH_WALKING); }
  182. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  183. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  184. void update (DemoCharacter &puppet, double delta_t) override final;
  185. };//END CrouchWalkingState
  186. /** @brief A basic jumping state. */
  187. class JumpingState : public State<DemoCharacter>
  188. {
  189. public:
  190. void enter (DemoCharacter &puppet) override final
  191. { puppet.setActiveSprite (DemoCharacter::animation_list_e::JUMP); }
  192. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  193. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  194. void update (DemoCharacter &puppet, double delta_t) override final;
  195. };//END JumpingState
  196. /** @brief A extended jumping state. */
  197. class LongJumpState : public State<DemoCharacter>
  198. {
  199. public:
  200. void enter (DemoCharacter &puppet) override final
  201. { puppet.setActiveSprite (DemoCharacter::animation_list_e::AIR_SPIN); }
  202. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  203. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  204. void update (DemoCharacter &puppet, double delta_t) override final;
  205. };//END LongJumpState
  206. /** @brief A basic attack state. */
  207. class AttackState : public State<DemoCharacter>
  208. {
  209. public:
  210. void enter (DemoCharacter &puppet) override final { /*changes depending on the attack command!*/ }
  211. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  212. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  213. void update (DemoCharacter &puppet, double delta_t) override final;
  214. };//END AttackState
  215. /** @brief A basic blocking state. */
  216. class BlockState : public State<DemoCharacter>
  217. {
  218. public:
  219. void enter (DemoCharacter &puppet) override final
  220. { puppet.setActiveSprite (DemoCharacter::animation_list_e::BLOCK); }
  221. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  222. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  223. void update (DemoCharacter &puppet, double delta_t) override final;
  224. };//END BlockState
  225. /** @brief A extended rolling state. */
  226. class RollingState : public State<DemoCharacter>
  227. {
  228. public:
  229. void enter (DemoCharacter &puppet) override final;
  230. bool checkStateChange (DemoCharacter &puppet, unsigned new_state) const override final;
  231. void handleInput (DemoCharacter &puppet, controller_button_map_t input, key_state input_st, double delta_t) override final;
  232. void update (DemoCharacter &puppet, double delta_t) override final;
  233. };//END LongJumpState
  234. #endif //_DEMO_CHARACTER_HPP_