Advertisement
Cinestra

Project 3 Actor.h Progress 2

Jun 2nd, 2023
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. #ifndef ACTOR_H_
  2. #define ACTOR_H_
  3.  
  4. #include "GraphObject.h"
  5.  
  6. // Students: Add code to this file, Actor.cpp, StudentWorld.h, and StudentWorld.cpp
  7.  
  8. const int PEACH = 1;
  9. const int YOSHI = 2;
  10. const int WAITING_TO_ROLL = false;
  11. const int PAUSED = false;
  12. const int WALKING = true;
  13. const int invalid_direction = -100;
  14.  
  15. class StudentWorld;
  16.  
  17. /*
  18. From Graph Object:
  19.  
  20. static const int left = 180;
  21. static const int right = 0;
  22. static const int up = 90;
  23. static const int down = 270;
  24.  
  25. GraphObject(int imageID, int startX, int startY, int dir = right, int depth = 0, double size = 1.0)
  26. */
  27.  
  28. class Actor : public GraphObject
  29. {
  30. public:
  31. Actor(int imageID, int startX, int startY, StudentWorld* world, int depth = 0, int dir = right, double size = 1.0)
  32. :GraphObject(imageID, startX, startY, dir, depth, size)
  33. {
  34. m_world = world;
  35. }
  36.  
  37. virtual ~Actor() {}
  38. virtual void do_something() = 0; // Does something during the tick
  39. virtual bool is_impactable() = 0;
  40. virtual void do_impacted_behavior() = 0;
  41. virtual bool is_square() = 0;
  42. virtual bool is_dynamically_added() = 0;
  43.  
  44. StudentWorld* get_world() const {
  45. return m_world;
  46. }
  47.  
  48. private:
  49. StudentWorld* m_world;
  50. };
  51.  
  52. class Character : public Actor
  53. {
  54. public:
  55. Character(int imageID, int startX, int startY, StudentWorld* world)
  56. :Actor(imageID, startX, startY, world)
  57. {
  58. m_state = 0; // 0 stands for either waiting to roll or paused
  59. m_ticks_to_move = 0;
  60. m_walk_direction = 0;
  61. }
  62.  
  63. virtual ~Character() {}
  64.  
  65. int get_walk_direction() const {
  66. return m_walk_direction;
  67. }
  68.  
  69. void set_walk_direction(int walk_direction) {
  70. m_walk_direction = walk_direction;
  71. }
  72.  
  73. int get_ticks() const {
  74. return m_ticks_to_move;
  75. }
  76.  
  77. int get_state() const {
  78. return m_state;
  79. }
  80.  
  81. void set_state(bool state) {
  82. m_state = state;
  83. }
  84.  
  85. void set_ticks(int ticks) {
  86. m_ticks_to_move = ticks;
  87. }
  88.  
  89. bool can_move_in_direction(int dir) const;
  90. int get_random_direction() const;
  91. void update_sprite_direction();
  92. void do_corner_turn();
  93.  
  94. bool is_at_fork();
  95.  
  96. // Have not implemented ANY of the virtual void functions, must do in inhereted classes
  97.  
  98. private:
  99. int m_ticks_to_move;
  100. int m_state;
  101. int m_walk_direction;
  102. };
  103.  
  104. // Must implement the following:
  105. /* virtual void do_something() = 0; // Does something during the tick
  106. virtual void do_impaceted_behavior() = 0; // If it's impactable by a vortex, it does it's impacted behavior
  107. virtual bool is_square() = 0; // Determines if it's a static object or not
  108. virtual bool is_impactable() = 0; // Can this be hit by a vortex
  109. virtual bool is_dynamically_added() = 0; // Was this just added to the board
  110. *
  111. */
  112.  
  113. class Player : public Character
  114. {
  115. public:
  116. Player(int player_number, int startX, int startY, StudentWorld* world)
  117. :Character(player_number == 1 ? IID_PEACH : IID_YOSHI, startX, startY, world)
  118. {
  119. m_player_number = player_number;
  120. m_coins = 0;
  121. m_stars = 0;
  122. }
  123. virtual ~Player() {}
  124. virtual void do_something();
  125. virtual bool is_impactable() {
  126. return false;
  127. }
  128. virtual void do_impacted_behavior() {
  129.  
  130. }
  131. virtual bool is_square() {
  132. return false;
  133. }
  134.  
  135. virtual bool is_dynamically_added() {
  136. return false;
  137. }
  138.  
  139. void set_coins(int coins) { m_coins = coins; }
  140. int get_coins() const { return m_coins; }
  141. void set_stars(int stars) { m_stars = stars; }
  142. int get_stars() const { return m_stars; }
  143.  
  144. private:
  145. int m_player_number;
  146. int m_coins;
  147. int m_stars;
  148. };
  149.  
  150. class Baddie : public Character
  151. {
  152. public:
  153. Baddie(int max_possible_squares_to_move, int imageID, int startX, int startY, StudentWorld* world)
  154. :Character(imageID, startX, startY, world)
  155. {
  156. m_max_possible_squares_to_move = max_possible_squares_to_move;
  157. m_pause_counter = 180;
  158. m_players_on_square = new std::set<Player*>;
  159. }
  160.  
  161. virtual ~Baddie();
  162. virtual void do_something();
  163. virtual void do_impacted_behavior();
  164. virtual bool is_impactable() { return true; }
  165. virtual bool is_dynamically_added(){ return false; }
  166. virtual bool is_square() { return false; }
  167.  
  168. private:
  169. virtual void do_baddie_behavior(Player* player) = 0;
  170. int m_max_possible_squares_to_move;
  171. int m_pause_counter;
  172.  
  173. // Player* is a pointer to a player class
  174. // Set<Player*> is a set of pointers to the player class
  175. // Set<Player*>* is a pointer to a set of pointers to the player class
  176. std::set<Player*>* m_players_on_square;
  177. void update_players_on_square(std::set<Player*>& updated);
  178.  
  179. virtual void do_special_pause_behavior() = 0; // Only for Bowser
  180. };
  181.  
  182. class Boo : public Baddie
  183. {
  184. public:
  185. Boo(int startX, int startY, StudentWorld* world)
  186. :Baddie(3, IID_BOO, startX, startY, world)
  187. {
  188.  
  189. }
  190.  
  191. virtual ~Boo() {};
  192.  
  193. private:
  194. virtual void do_baddie_behavior(Player* player);
  195. virtual void do_special_pause_behavior() { } // Does nothing
  196. };
  197.  
  198. class Bowser : public Baddie
  199. {
  200. public:
  201. Bowser(int startX, int startY, StudentWorld* world)
  202. :Baddie(10, IID_BOWSER, startX, startY, world)
  203. {
  204.  
  205. }
  206.  
  207. virtual ~Bowser() {}
  208.  
  209. private:
  210. virtual void do_baddie_behavior(Player* player);
  211. virtual void do_special_pause_behavior();
  212. };
  213.  
  214. class Square : public Actor
  215. {
  216. public:
  217. Square(int imageID, int startX, int startY, StudentWorld* world, int depth = 1, int dir = right, bool active = true)
  218. :Actor(imageID, startX, startY, world, 1)
  219. {
  220. m_active = active;
  221. }
  222.  
  223. virtual ~Square() {}
  224. virtual void do_something();
  225. virtual bool is_impactable() {
  226. return false;
  227. }
  228. virtual void do_impacted_behavior() {
  229.  
  230. }
  231. virtual bool is_square() {
  232. return true;
  233. }
  234.  
  235. virtual bool is_dynamically_added() {
  236. return true;
  237. }
  238.  
  239. bool is_active() {
  240. return m_active;
  241. }
  242.  
  243. void set_active(bool active) {
  244. m_active = active;
  245. }
  246.  
  247. private:
  248. bool m_active;
  249. };
  250.  
  251. class Coin_Square : public Square
  252. {
  253. public:
  254. Coin_Square(int coins, int startX, int startY, StudentWorld* world)
  255. :Square(IID_BLUE_COIN_SQUARE, startX, startY, world)
  256. {
  257. m_coins = coins;
  258. }
  259.  
  260. virtual ~Coin_Square() {}
  261.  
  262. virtual bool is_dynamically_added() {
  263. return false;
  264. }
  265.  
  266. private:
  267. int m_coins;
  268. };
  269.  
  270. #endif // ACTOR_H_
  271.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement