ELEC2645 (2018/19) / Mbed 2 deprecated el17ebs

Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Wed May 08 14:54:19 2019 +0000
Revision:
14:08ac9aaa34c3
Parent:
12:7f7fadb5c106
Child:
16:c8d68cbd1ae2
Doxygen comments added;

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 14:08ac9aaa34c3 51 * @brief Class for controlling a golf ball
ellisbhastroud 3:a8960004d261 52 * @author Ellis Blackford Stroud
ellisbhastroud 3:a8960004d261 53 * @date May, 2018
ellisbhastroud 3:a8960004d261 54 */
ellisbhastroud 3:a8960004d261 55
ellisbhastroud 5:0b31909caf7f 56 class Ball
ellisbhastroud 5:0b31909caf7f 57 {
ellisbhastroud 3:a8960004d261 58
ellisbhastroud 3:a8960004d261 59 public:
ellisbhastroud 3:a8960004d261 60
ellisbhastroud 3:a8960004d261 61 /** Constructor */
ellisbhastroud 3:a8960004d261 62 Ball();
ellisbhastroud 3:a8960004d261 63
ellisbhastroud 3:a8960004d261 64 /** Destructor */
ellisbhastroud 3:a8960004d261 65 ~Ball();
ellisbhastroud 3:a8960004d261 66
ellisbhastroud 14:08ac9aaa34c3 67 /** Resets ball private variables for new level
ellisbhastroud 14:08ac9aaa34c3 68 * @param a structing storing the start coordinate of the ball
ellisbhastroud 14:08ac9aaa34c3 69 */
ellisbhastroud 9:bc34f2243e43 70 void init(Coord start_pos);
ellisbhastroud 3:a8960004d261 71
ellisbhastroud 14:08ac9aaa34c3 72 /** Draws ball in position
ellisbhastroud 14:08ac9aaa34c3 73 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 74 */
ellisbhastroud 5:0b31909caf7f 75 void drawBall(N5110 &lcd);
ellisbhastroud 14:08ac9aaa34c3 76
ellisbhastroud 14:08ac9aaa34c3 77 /** Prints shot count
ellisbhastroud 14:08ac9aaa34c3 78 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 79 */
ellisbhastroud 5:0b31909caf7f 80 void printShotCount(N5110 &lcd);
ellisbhastroud 4:035448357749 81
ellisbhastroud 14:08ac9aaa34c3 82 /** Draws power bar
ellisbhastroud 14:08ac9aaa34c3 83 * @param the class used to interact with the lcd display
ellisbhastroud 14:08ac9aaa34c3 84 * @param a float in the range 0.0 - 1.0
ellisbhastroud 14:08ac9aaa34c3 85 */
ellisbhastroud 8:d410856c6d04 86 void drawPower(N5110 &lcd, float mag);
ellisbhastroud 8:d410856c6d04 87
ellisbhastroud 14:08ac9aaa34c3 88 /** Draws aim on ball
ellisbhastroud 14:08ac9aaa34c3 89 * @param the class used to interact with the lcd periphal
ellisbhastroud 14:08ac9aaa34c3 90 * @param x and y floats of joystick coordinate in the range -1.0 - 1.0
ellisbhastroud 14:08ac9aaa34c3 91 */
ellisbhastroud 8:d410856c6d04 92 void drawAim(N5110 &lcd, Vector2D joy_coord ,float angle);
ellisbhastroud 14:08ac9aaa34c3 93
ellisbhastroud 14:08ac9aaa34c3 94 /** Moves ball position */
ellisbhastroud 10:9f54a6366e94 95 void move_ball();
ellisbhastroud 14:08ac9aaa34c3 96
ellisbhastroud 14:08ac9aaa34c3 97 /** Checks if ball is shot and if so changes ball velocity to direction and magnitude of joystick
ellisbhastroud 14:08ac9aaa34c3 98 * @param the class used to interact with the gamepad
ellisbhastroud 14:08ac9aaa34c3 99 * @param a struct storing mapped coordinates of the joystick position
ellisbhastroud 14:08ac9aaa34c3 100 */
ellisbhastroud 14:08ac9aaa34c3 101 void check_shoot_ball(Gamepad &pad, Vector2D joy_coord);
ellisbhastroud 14:08ac9aaa34c3 102
ellisbhastroud 14:08ac9aaa34c3 103 /** Sets total shout count
ellisbhastroud 14:08ac9aaa34c3 104 * @param an integer storing the total shot count
ellisbhastroud 14:08ac9aaa34c3 105 */
ellisbhastroud 12:7f7fadb5c106 106 void set_total_shot_count(int total_shot_count);
ellisbhastroud 9:bc34f2243e43 107
ellisbhastroud 14:08ac9aaa34c3 108 /** Gets total shout count
ellisbhastroud 14:08ac9aaa34c3 109 * @return the total shot count
ellisbhastroud 14:08ac9aaa34c3 110 */
ellisbhastroud 9:bc34f2243e43 111 int get_total_shot_count();
ellisbhastroud 5:0b31909caf7f 112
ellisbhastroud 14:08ac9aaa34c3 113 /** Checks if ball is in hole
ellisbhastroud 14:08ac9aaa34c3 114 * @return true if ball is in the hole and false if not
ellisbhastroud 14:08ac9aaa34c3 115 */
ellisbhastroud 9:bc34f2243e43 116 bool check_hole(Coord hole);
ellisbhastroud 8:d410856c6d04 117
ellisbhastroud 14:08ac9aaa34c3 118 /** Checks if ball has met any bounce conditions
ellisbhastroud 14:08ac9aaa34c3 119 * @param array of WallMap struct values storing wall types and coordinates
ellisbhastroud 14:08ac9aaa34c3 120 * @param integer used to control loop which runs bounce check
ellisbhastroud 14:08ac9aaa34c3 121 */
ellisbhastroud 9:bc34f2243e43 122 void check_wall_bounce(WallMap map[], int size);
ellisbhastroud 8:d410856c6d04 123
ellisbhastroud 14:08ac9aaa34c3 124 /** Sets frame rate
ellisbhastroud 14:08ac9aaa34c3 125 * @param frequency of frame rate in Hz
ellisbhastroud 14:08ac9aaa34c3 126 */
ellisbhastroud 12:7f7fadb5c106 127 void set_frame_rate(int frame_rate);
ellisbhastroud 14:08ac9aaa34c3 128
ellisbhastroud 14:08ac9aaa34c3 129 /** Gets bounce flag state
ellisbhastroud 14:08ac9aaa34c3 130 * @return true for bounce false for none
ellisbhastroud 14:08ac9aaa34c3 131 */
ellisbhastroud 14:08ac9aaa34c3 132 bool get_bounce_flag();
ellisbhastroud 14:08ac9aaa34c3 133
ellisbhastroud 14:08ac9aaa34c3 134 /** Reset bounce flag state */
ellisbhastroud 14:08ac9aaa34c3 135 void reset_bounce_flag();
ellisbhastroud 12:7f7fadb5c106 136
ellisbhastroud 12:7f7fadb5c106 137 private:
ellisbhastroud 12:7f7fadb5c106 138
ellisbhastroud 8:d410856c6d04 139 void left_bounce(Coord start, Coord end);
ellisbhastroud 8:d410856c6d04 140 void right_bounce(Coord start, Coord end);
ellisbhastroud 8:d410856c6d04 141 void top_bounce(Coord start, Coord end);
ellisbhastroud 8:d410856c6d04 142 void bottom_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 143 void bottom_left_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 144 void bottom_right_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 145 void top_left_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 146 void top_right_bounce(Coord start, Coord end);
ellisbhastroud 10:9f54a6366e94 147
ellisbhastroud 12:7f7fadb5c106 148 float _x_pos;
ellisbhastroud 3:a8960004d261 149 float _y_pos;
ellisbhastroud 3:a8960004d261 150 float _x_vel;
ellisbhastroud 3:a8960004d261 151 float _y_vel;
ellisbhastroud 14:08ac9aaa34c3 152 bool _bounce_flag;
ellisbhastroud 4:035448357749 153 int _shot_count;
ellisbhastroud 9:bc34f2243e43 154 int _total_shot_count;
ellisbhastroud 10:9f54a6366e94 155 int _frame_rate;
ellisbhastroud 5:0b31909caf7f 156 Direction _direction;
ellisbhastroud 12:7f7fadb5c106 157
ellisbhastroud 3:a8960004d261 158 };
ellisbhastroud 3:a8960004d261 159
ellisbhastroud 3:a8960004d261 160 #endif