ELEC2645 (2018/19) / Mbed 2 deprecated el17ebs

Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Thu May 09 09:58:51 2019 +0000
Revision:
16:c8d68cbd1ae2
Parent:
14:08ac9aaa34c3
Child:
17:98127ac75195
Penultimate Commit - Tidied a little and checking documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ellisbhastroud 3:a8960004d261 1 #ifndef BALL_H
ellisbhastroud 3:a8960004d261 2 #define BALL_H
ellisbhastroud 3:a8960004d261 3
ellisbhastroud 3:a8960004d261 4 #include "mbed.h"
ellisbhastroud 3:a8960004d261 5 #include "N5110.h"
ellisbhastroud 3:a8960004d261 6 #include "Gamepad.h"
ellisbhastroud 3:a8960004d261 7
ellisbhastroud 8:d410856c6d04 8 /** Enum for wall types */
ellisbhastroud 12:7f7fadb5c106 9 enum WallType {
ellisbhastroud 12:7f7fadb5c106 10
ellisbhastroud 8:d410856c6d04 11 LEFT, /**< left wall */
ellisbhastroud 8:d410856c6d04 12 RIGHT, /**< right wall */
ellisbhastroud 8:d410856c6d04 13 TOP, /**< top wall */
ellisbhastroud 8:d410856c6d04 14 BOTTOM, /**< bottom wall */
ellisbhastroud 10:9f54a6366e94 15 BOTTOMLEFT, /**< bottom left 45 deg wall */
ellisbhastroud 10:9f54a6366e94 16 BOTTOMRIGHT, /**< bottom right 45 deg wall */
ellisbhastroud 10:9f54a6366e94 17 TOPLEFT, /**< top left 45 deg wall */
ellisbhastroud 10:9f54a6366e94 18 TOPRIGHT, /**< top right 45 deg wall */
ellisbhastroud 10:9f54a6366e94 19
ellisbhastroud 8:d410856c6d04 20 };
ellisbhastroud 8:d410856c6d04 21
ellisbhastroud 8:d410856c6d04 22 /** Pixel Coordinate Struct*/
ellisbhastroud 8:d410856c6d04 23 struct Coord {
ellisbhastroud 12:7f7fadb5c106 24
ellisbhastroud 8:d410856c6d04 25 int x; /**< coordinate of x pixel */
ellisbhastroud 8:d410856c6d04 26 int y; /**< coordinate of y pixel */
ellisbhastroud 12:7f7fadb5c106 27
ellisbhastroud 8:d410856c6d04 28 };
ellisbhastroud 8:d410856c6d04 29
ellisbhastroud 12:7f7fadb5c106 30 /** Wall Information struct */
ellisbhastroud 9:bc34f2243e43 31 struct WallMap {
ellisbhastroud 12:7f7fadb5c106 32
ellisbhastroud 9:bc34f2243e43 33 WallType wall; /**< wall type */
ellisbhastroud 8:d410856c6d04 34 Coord start; /**< coordinate of line start */
ellisbhastroud 8:d410856c6d04 35 Coord end; /**< coordinate of line end */
ellisbhastroud 12:7f7fadb5c106 36
ellisbhastroud 8:d410856c6d04 37 };
ellisbhastroud 8:d410856c6d04 38
ellisbhastroud 9:bc34f2243e43 39 /** Levels Information struct */
ellisbhastroud 9:bc34f2243e43 40 struct Levels {
ellisbhastroud 12:7f7fadb5c106 41
ellisbhastroud 9:bc34f2243e43 42 Coord ball; /**< start position of ball */
ellisbhastroud 9:bc34f2243e43 43 Coord hole; /**< position of hole */
ellisbhastroud 12:7f7fadb5c106 44 WallMap walls[16]; /**< array of walls */
ellisbhastroud 12:7f7fadb5c106 45 int wall_count; /**< number of walls in level */
ellisbhastroud 12:7f7fadb5c106 46
ellisbhastroud 9:bc34f2243e43 47
ellisbhastroud 9:bc34f2243e43 48 };
ellisbhastroud 9:bc34f2243e43 49
ellisbhastroud 3:a8960004d261 50 /** Ball Class
ellisbhastroud 16:c8d68cbd1ae2 51 * @brief Class for controlling a ball
ellisbhastroud 3:a8960004d261 52 * @author Ellis Blackford Stroud
ellisbhastroud 3:a8960004d261 53 * @date May, 2018
ellisbhastroud 3:a8960004d261 54 */
ellisbhastroud 5:0b31909caf7f 55 class Ball
ellisbhastroud 5:0b31909caf7f 56 {
ellisbhastroud 3:a8960004d261 57 public:
ellisbhastroud 3:a8960004d261 58 /** Constructor */
ellisbhastroud 3:a8960004d261 59 Ball();
ellisbhastroud 16:c8d68cbd1ae2 60
ellisbhastroud 3:a8960004d261 61 /** Destructor */
ellisbhastroud 3:a8960004d261 62 ~Ball();
ellisbhastroud 3:a8960004d261 63
ellisbhastroud 14:08ac9aaa34c3 64 /** Resets ball private variables for new level
ellisbhastroud 14:08ac9aaa34c3 65 * @param a structing storing the start coordinate of the ball
ellisbhastroud 14:08ac9aaa34c3 66 */
ellisbhastroud 9:bc34f2243e43 67 void init(Coord start_pos);
ellisbhastroud 3:a8960004d261 68
ellisbhastroud 14:08ac9aaa34c3 69 /** Draws ball in position
ellisbhastroud 14:08ac9aaa34c3 70 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 71 */
ellisbhastroud 5:0b31909caf7f 72 void drawBall(N5110 &lcd);
ellisbhastroud 16:c8d68cbd1ae2 73
ellisbhastroud 14:08ac9aaa34c3 74 /** Prints shot count
ellisbhastroud 14:08ac9aaa34c3 75 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 76 */
ellisbhastroud 5:0b31909caf7f 77 void printShotCount(N5110 &lcd);
ellisbhastroud 4:035448357749 78
ellisbhastroud 14:08ac9aaa34c3 79 /** Draws power bar
ellisbhastroud 14:08ac9aaa34c3 80 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 81 * @param a float in the range 0.0 - 1.0
ellisbhastroud 14:08ac9aaa34c3 82 */
ellisbhastroud 8:d410856c6d04 83 void drawPower(N5110 &lcd, float mag);
ellisbhastroud 8:d410856c6d04 84
ellisbhastroud 14:08ac9aaa34c3 85 /** Draws aim on ball
ellisbhastroud 14:08ac9aaa34c3 86 * @param the class used to interact with the lcd periphal
ellisbhastroud 14:08ac9aaa34c3 87 * @param x and y floats of joystick coordinate in the range -1.0 - 1.0
ellisbhastroud 14:08ac9aaa34c3 88 */
ellisbhastroud 8:d410856c6d04 89 void drawAim(N5110 &lcd, Vector2D joy_coord ,float angle);
ellisbhastroud 14:08ac9aaa34c3 90
ellisbhastroud 14:08ac9aaa34c3 91 /** Moves ball position */
ellisbhastroud 10:9f54a6366e94 92 void move_ball();
ellisbhastroud 14:08ac9aaa34c3 93
ellisbhastroud 14:08ac9aaa34c3 94 /** Checks if ball is shot and if so changes ball velocity to direction and magnitude of joystick
ellisbhastroud 14:08ac9aaa34c3 95 * @param the class used to interact with the gamepad
ellisbhastroud 14:08ac9aaa34c3 96 * @param a struct storing mapped coordinates of the joystick position
ellisbhastroud 14:08ac9aaa34c3 97 */
ellisbhastroud 14:08ac9aaa34c3 98 void check_shoot_ball(Gamepad &pad, Vector2D joy_coord);
ellisbhastroud 14:08ac9aaa34c3 99
ellisbhastroud 14:08ac9aaa34c3 100 /** Sets total shout count
ellisbhastroud 14:08ac9aaa34c3 101 * @param an integer storing the total shot count
ellisbhastroud 14:08ac9aaa34c3 102 */
ellisbhastroud 12:7f7fadb5c106 103 void set_total_shot_count(int total_shot_count);
ellisbhastroud 9:bc34f2243e43 104
ellisbhastroud 14:08ac9aaa34c3 105 /** Gets total shout count
ellisbhastroud 14:08ac9aaa34c3 106 * @return the total shot count
ellisbhastroud 14:08ac9aaa34c3 107 */
ellisbhastroud 9:bc34f2243e43 108 int get_total_shot_count();
ellisbhastroud 16:c8d68cbd1ae2 109
ellisbhastroud 16:c8d68cbd1ae2 110 /** Gets current level shout count
ellisbhastroud 16:c8d68cbd1ae2 111 * @return the shot countof current level
ellisbhastroud 16:c8d68cbd1ae2 112 */
ellisbhastroud 16:c8d68cbd1ae2 113 int get_shot_count();
ellisbhastroud 16:c8d68cbd1ae2 114
ellisbhastroud 5:0b31909caf7f 115
ellisbhastroud 14:08ac9aaa34c3 116 /** Checks if ball is in hole
ellisbhastroud 14:08ac9aaa34c3 117 * @return true if ball is in the hole and false if not
ellisbhastroud 14:08ac9aaa34c3 118 */
ellisbhastroud 9:bc34f2243e43 119 bool check_hole(Coord hole);
ellisbhastroud 8:d410856c6d04 120
ellisbhastroud 14:08ac9aaa34c3 121 /** Checks if ball has met any bounce conditions
ellisbhastroud 14:08ac9aaa34c3 122 * @param array of WallMap struct values storing wall types and coordinates
ellisbhastroud 14:08ac9aaa34c3 123 * @param integer used to control loop which runs bounce check
ellisbhastroud 14:08ac9aaa34c3 124 */
ellisbhastroud 16:c8d68cbd1ae2 125 void check_wall_bounce(const WallMap map[], int size);
ellisbhastroud 8:d410856c6d04 126
ellisbhastroud 14:08ac9aaa34c3 127 /** Sets frame rate
ellisbhastroud 14:08ac9aaa34c3 128 * @param frequency of frame rate in Hz
ellisbhastroud 14:08ac9aaa34c3 129 */
ellisbhastroud 12:7f7fadb5c106 130 void set_frame_rate(int frame_rate);
ellisbhastroud 14:08ac9aaa34c3 131
ellisbhastroud 14:08ac9aaa34c3 132 /** Gets bounce flag state
ellisbhastroud 14:08ac9aaa34c3 133 * @return true for bounce false for none
ellisbhastroud 14:08ac9aaa34c3 134 */
ellisbhastroud 14:08ac9aaa34c3 135 bool get_bounce_flag();
ellisbhastroud 14:08ac9aaa34c3 136
ellisbhastroud 14:08ac9aaa34c3 137 /** Reset bounce flag state */
ellisbhastroud 14:08ac9aaa34c3 138 void reset_bounce_flag();
ellisbhastroud 12:7f7fadb5c106 139
ellisbhastroud 12:7f7fadb5c106 140 private:
ellisbhastroud 12:7f7fadb5c106 141
ellisbhastroud 8:d410856c6d04 142 void left_bounce(Coord start, Coord end);
ellisbhastroud 8:d410856c6d04 143 void right_bounce(Coord start, Coord end);
ellisbhastroud 8:d410856c6d04 144 void top_bounce(Coord start, Coord end);
ellisbhastroud 8:d410856c6d04 145 void bottom_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 146 void bottom_left_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 147 void bottom_right_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 148 void top_left_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 149 void top_right_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 150
ellisbhastroud 12:7f7fadb5c106 151 float _x_pos;
ellisbhastroud 3:a8960004d261 152 float _y_pos;
ellisbhastroud 3:a8960004d261 153 float _x_vel;
ellisbhastroud 3:a8960004d261 154 float _y_vel;
ellisbhastroud 14:08ac9aaa34c3 155 bool _bounce_flag;
ellisbhastroud 4:035448357749 156 int _shot_count;
ellisbhastroud 9:bc34f2243e43 157 int _total_shot_count;
ellisbhastroud 10:9f54a6366e94 158 int _frame_rate;
ellisbhastroud 5:0b31909caf7f 159 Direction _direction;
ellisbhastroud 12:7f7fadb5c106 160
ellisbhastroud 3:a8960004d261 161 };
ellisbhastroud 3:a8960004d261 162
ellisbhastroud 3:a8960004d261 163 #endif