Class containing methods to draw a ball within the maze game with the specified position, size and fill style parameters.

Committer:
el15mh
Date:
Thu May 04 14:01:56 2017 +0000
Revision:
3:569a3f2786ec
Parent:
2:bcb96ab2848b
Doxygen commenting added

Who changed what in which revision?

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