el15mh 200929957

Dependencies:   mbed

Committer:
el15mh
Date:
Thu May 04 14:43:29 2017 +0000
Revision:
9:960dfc71c224
Child:
10:989e5dbd12ee
Documented using doxygen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el15mh 9:960dfc71c224 1 /**
el15mh 9:960dfc71c224 2 @brief Ball Class contains necessary parameters to draw the ball of the correct position, size and fill style.
el15mh 9:960dfc71c224 3 @author Max Houghton
el15mh 9:960dfc71c224 4 @date March 19 2017
el15mh 9:960dfc71c224 5 */
el15mh 9:960dfc71c224 6
el15mh 9:960dfc71c224 7 #ifndef BALL_H
el15mh 9:960dfc71c224 8 #define BALL_H
el15mh 9:960dfc71c224 9
el15mh 9:960dfc71c224 10 #include "mbed.h"
el15mh 9:960dfc71c224 11 #include "N5110.h"
el15mh 9:960dfc71c224 12 #include "Gamepad.h"
el15mh 9:960dfc71c224 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 9:960dfc71c224 65 *
el15mh 9:960dfc71c224 66 */
el15mh 9:960dfc71c224 67 Vector2D getVelocity();
el15mh 9:960dfc71c224 68
el15mh 9:960dfc71c224 69 /** Set Position
el15mh 9:960dfc71c224 70 *
el15mh 9:960dfc71c224 71 * @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 72 * @param - p - 2D Vector struct containing the location of the ball to be set to.
el15mh 9:960dfc71c224 73 *
el15mh 9:960dfc71c224 74 */
el15mh 9:960dfc71c224 75 void setPosition(Vector2D p);
el15mh 9:960dfc71c224 76
el15mh 9:960dfc71c224 77 /** Set Velocity
el15mh 9:960dfc71c224 78 *
el15mh 9:960dfc71c224 79 * @details - This decides where the ball is to travel next.
el15mh 9:960dfc71c224 80 * @param - v - 2D Vector struct which has the location of the ball for the next iteration.
el15mh 9:960dfc71c224 81 *
el15mh 9:960dfc71c224 82 */
el15mh 9:960dfc71c224 83 void setVelocity(Vector2D v);
el15mh 9:960dfc71c224 84
el15mh 9:960dfc71c224 85 private:
el15mh 9:960dfc71c224 86
el15mh 9:960dfc71c224 87 /**
el15mh 9:960dfc71c224 88 * @details - Struct containing x and y values for the following position of the ball
el15mh 9:960dfc71c224 89 */
el15mh 9:960dfc71c224 90 Vector2D velocity;
el15mh 9:960dfc71c224 91
el15mh 9:960dfc71c224 92 /** Check For Interference
el15mh 9:960dfc71c224 93 *
el15mh 9:960dfc71c224 94 * @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 9:960dfc71c224 95 *
el15mh 9:960dfc71c224 96 */
el15mh 9:960dfc71c224 97 Vector2D checkForInterference(Vector2D velocity);
el15mh 9:960dfc71c224 98
el15mh 9:960dfc71c224 99 /**
el15mh 9:960dfc71c224 100 * @param - _radius - Integer to decide size of the ball to be drawn.
el15mh 9:960dfc71c224 101 */
el15mh 9:960dfc71c224 102 int _radius;
el15mh 9:960dfc71c224 103
el15mh 9:960dfc71c224 104 /**
el15mh 9:960dfc71c224 105 * @param - _x - Float value specifying x coordinate of centre of ball.
el15mh 9:960dfc71c224 106 */
el15mh 9:960dfc71c224 107 float _x;
el15mh 9:960dfc71c224 108
el15mh 9:960dfc71c224 109 /**
el15mh 9:960dfc71c224 110 * @param - _y - Float value specifying y coordinate of centre of ball.
el15mh 9:960dfc71c224 111 */
el15mh 9:960dfc71c224 112 float _y;
el15mh 9:960dfc71c224 113
el15mh 9:960dfc71c224 114 /**
el15mh 9:960dfc71c224 115 * @param - _colour - Boolean value specifying fill style of the ball; true corresponds to transparent fill and false to solid fill.
el15mh 9:960dfc71c224 116 */
el15mh 9:960dfc71c224 117 bool _colour;
el15mh 9:960dfc71c224 118
el15mh 9:960dfc71c224 119 };
el15mh 9:960dfc71c224 120
el15mh 9:960dfc71c224 121 #endif /* BALL_H */