el15mh 200929957

Dependencies:   mbed

Committer:
el15mh
Date:
Thu May 04 17:39:23 2017 +0000
Revision:
10:989e5dbd12ee
Parent:
9:960dfc71c224
Documented and final revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el15mh 9:960dfc71c224 1 #ifndef BALL_H
el15mh 9:960dfc71c224 2 #define BALL_H
el15mh 9:960dfc71c224 3
el15mh 9:960dfc71c224 4 #include "mbed.h"
el15mh 9:960dfc71c224 5 #include "N5110.h"
el15mh 9:960dfc71c224 6 #include "Gamepad.h"
el15mh 9:960dfc71c224 7
el15mh 10:989e5dbd12ee 8 /**
el15mh 10:989e5dbd12ee 9 @brief Ball Class contains necessary parameters to draw the ball of the correct position, size and colour.
el15mh 10:989e5dbd12ee 10 @author Max Houghton
el15mh 10:989e5dbd12ee 11 @date March 19 2017
el15mh 10:989e5dbd12ee 12 */
el15mh 10:989e5dbd12ee 13
el15mh 9:960dfc71c224 14 class Ball
el15mh 9:960dfc71c224 15 {
el15mh 9:960dfc71c224 16
el15mh 9:960dfc71c224 17 public:
el15mh 9:960dfc71c224 18
el15mh 9:960dfc71c224 19 /**
el15mh 9:960dfc71c224 20 * @details - constructor
el15mh 9:960dfc71c224 21 */
el15mh 9:960dfc71c224 22 Ball();
el15mh 9:960dfc71c224 23
el15mh 9:960dfc71c224 24 /**
el15mh 9:960dfc71c224 25 * @details - destructor
el15mh 9:960dfc71c224 26 */
el15mh 9:960dfc71c224 27 ~Ball();
el15mh 9:960dfc71c224 28
el15mh 9:960dfc71c224 29 /** Initialise Ball
el15mh 9:960dfc71c224 30 *
el15mh 9:960dfc71c224 31 * @details - Initiases the ball with the appropriate different parameters chosen by user.
el15mh 9:960dfc71c224 32 * @param - x - specifies the x coordinate for the starting position of the ball.
el15mh 9:960dfc71c224 33 * @param - y - specifies the y coordinate for the starting position of the ball.
el15mh 9:960dfc71c224 34 * @param - radius - specifies size of the ball to be drawn.
el15mh 9:960dfc71c224 35 * @param - colour - specifies if the ball is either transparent or filled.
el15mh 9:960dfc71c224 36 */
el15mh 9:960dfc71c224 37 void init(float x, float y, int radius, bool colour);
el15mh 9:960dfc71c224 38
el15mh 9:960dfc71c224 39 /** Update
el15mh 9:960dfc71c224 40 *
el15mh 9:960dfc71c224 41 * @details - Function takes the 2D Vector 'position' and updates the current position of the ball by adding on the values of 'position'.
el15mh 9:960dfc71c224 42 * @param - position - 2D Vector struct passed down by engine containing values for the centre of the ball for the next iteration.
el15mh 9:960dfc71c224 43 *
el15mh 9:960dfc71c224 44 */
el15mh 9:960dfc71c224 45 void update(Vector2D position);
el15mh 9:960dfc71c224 46
el15mh 9:960dfc71c224 47 /** Draw
el15mh 9:960dfc71c224 48 *
el15mh 9:960dfc71c224 49 * @details - Function draws the ball using the current set values for the centre of the ball and its radius.
el15mh 9:960dfc71c224 50 * @param - lcd - N5110 Library used to draw the circle representing the ball.
el15mh 9:960dfc71c224 51 *
el15mh 9:960dfc71c224 52 */
el15mh 9:960dfc71c224 53 void draw(N5110 &lcd);
el15mh 9:960dfc71c224 54
el15mh 9:960dfc71c224 55 /** Get Position
el15mh 9:960dfc71c224 56 *
el15mh 9:960dfc71c224 57 * @details - Function returns a 2D Vector struct containing information about the ball's current position. This is used when checking for wall collisions in the Maze Engine class.
el15mh 9:960dfc71c224 58 *
el15mh 9:960dfc71c224 59 */
el15mh 9:960dfc71c224 60 Vector2D getPosition();
el15mh 9:960dfc71c224 61
el15mh 9:960dfc71c224 62 /** Get Velocity
el15mh 9:960dfc71c224 63 *
el15mh 9:960dfc71c224 64 * @details - Function returns a 2D Vector struct containing information about the ball's next position.
el15mh 10:989e5dbd12ee 65 * @return position
el15mh 9:960dfc71c224 66 *
el15mh 9:960dfc71c224 67 */
el15mh 9:960dfc71c224 68 Vector2D getVelocity();
el15mh 9:960dfc71c224 69
el15mh 9:960dfc71c224 70 /** Set Position
el15mh 9:960dfc71c224 71 *
el15mh 9:960dfc71c224 72 * @details - This function dictates the position of the ball for the next update of the game. It is used in the wall collision check and goal check functions.
el15mh 9:960dfc71c224 73 * @param - p - 2D Vector struct containing the location of the ball to be set to.
el15mh 10:989e5dbd12ee 74 * @return velocity
el15mh 9:960dfc71c224 75 *
el15mh 9:960dfc71c224 76 */
el15mh 9:960dfc71c224 77 void setPosition(Vector2D p);
el15mh 9:960dfc71c224 78
el15mh 9:960dfc71c224 79 /** Set Velocity
el15mh 9:960dfc71c224 80 *
el15mh 9:960dfc71c224 81 * @details - This decides where the ball is to travel next.
el15mh 9:960dfc71c224 82 * @param - v - 2D Vector struct which has the location of the ball for the next iteration.
el15mh 9:960dfc71c224 83 *
el15mh 9:960dfc71c224 84 */
el15mh 9:960dfc71c224 85 void setVelocity(Vector2D v);
el15mh 9:960dfc71c224 86
el15mh 9:960dfc71c224 87 private:
el15mh 9:960dfc71c224 88
el15mh 9:960dfc71c224 89 /**
el15mh 9:960dfc71c224 90 * @details - Struct containing x and y values for the following position of the ball
el15mh 9:960dfc71c224 91 */
el15mh 9:960dfc71c224 92 Vector2D velocity;
el15mh 9:960dfc71c224 93
el15mh 9:960dfc71c224 94 /** Check For Interference
el15mh 9:960dfc71c224 95 *
el15mh 9:960dfc71c224 96 * @details - When using the accelerometer data for position values, small but non-zero values can cause the ball undesirably. This function removes all small values of the data ensuring the ball only moves according to deliberate movements of the accelerometer.
el15mh 10:989e5dbd12ee 97 * @return velocity
el15mh 9:960dfc71c224 98 *
el15mh 9:960dfc71c224 99 */
el15mh 9:960dfc71c224 100 Vector2D checkForInterference(Vector2D velocity);
el15mh 9:960dfc71c224 101
el15mh 9:960dfc71c224 102 /**
el15mh 10:989e5dbd12ee 103 * @param _radius - Integer to decide size of the ball to be drawn.
el15mh 9:960dfc71c224 104 */
el15mh 9:960dfc71c224 105 int _radius;
el15mh 9:960dfc71c224 106
el15mh 9:960dfc71c224 107 /**
el15mh 10:989e5dbd12ee 108 * @param _x - Float value specifying x coordinate of centre of ball.
el15mh 9:960dfc71c224 109 */
el15mh 9:960dfc71c224 110 float _x;
el15mh 9:960dfc71c224 111
el15mh 9:960dfc71c224 112 /**
el15mh 10:989e5dbd12ee 113 * @param _y - Float value specifying y coordinate of centre of ball.
el15mh 9:960dfc71c224 114 */
el15mh 9:960dfc71c224 115 float _y;
el15mh 9:960dfc71c224 116
el15mh 9:960dfc71c224 117 /**
el15mh 10:989e5dbd12ee 118 * @param _colour - Boolean value specifying fill style of the ball; true corresponds to transparent fill and false to solid fill.
el15mh 10:989e5dbd12ee 119 * @return _colour
el15mh 9:960dfc71c224 120 */
el15mh 9:960dfc71c224 121 bool _colour;
el15mh 9:960dfc71c224 122
el15mh 9:960dfc71c224 123 };
el15mh 9:960dfc71c224 124
el15mh 9:960dfc71c224 125 #endif /* BALL_H */