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

Files at this revision

API Documentation at this revision

Comitter:
el15mh
Date:
Thu May 04 14:01:56 2017 +0000
Parent:
2:bcb96ab2848b
Commit message:
Doxygen commenting added

Changed in this revision

Ball.cpp Show annotated file Show diff for this revision Revisions of this file
Ball.h Show annotated file Show diff for this revision Revisions of this file
diff -r bcb96ab2848b -r 569a3f2786ec Ball.cpp
--- a/Ball.cpp	Wed May 03 21:13:45 2017 +0000
+++ b/Ball.cpp	Thu May 04 14:01:56 2017 +0000
@@ -1,24 +1,24 @@
-/*
-
-@file Ball.cpp
-
-(c) Max Houghton 02.14.17
-Roller Maze Project, ELEC2645, Univeristy of Leeds
-
-*/
-
 #include "Ball.h"
 
+/**
+ *  @details - constructor
+ */
 Ball::Ball()
 {
     
 }
 
+/**
+ *  @details - destructor
+ */
 Ball::~Ball()
 {
     
 }
 
+/**
+ * @details - Initiases the ball.
+ */
 void Ball::init(float x,     // x coordinate for centre
                 float y,     // y coordinate for centre
                 int radius,  // radius size
@@ -34,10 +34,15 @@
     // printf("DRAW FUNCTION: x = %f, y = %f, radius = %f \n", _x, _y, _radius);
 }
 
+/**
+ *  @details - Updates position of the ball
+ */
 void Ball::update(Vector2D position)
 {
     velocity = position;
     
+    // smooths out small signal fluctuations from accelerometer
+    // used by joystick output also but with neglible effect
     checkForInterference(velocity);
     
     // new coordinates for the centre of the ball
@@ -45,10 +50,13 @@
     _y -= velocity.y;   // +ve y joystick motion => -ve ball motion
 }
 
-// goes into main 'draw' function in engine
-// main draw function in engine then called by menu during 'playGame' function
+/**
+ *  @details - Function draws the ball
+ */
 void Ball::draw(N5110 &lcd)
 {
+    // goes into main 'draw' function in engine
+    // main draw function in engine then called by menu during 'playGame' function
     if (_colour){// true colour => outline
         lcd.drawCircle(_x, _y, _radius, FILL_TRANSPARENT);
     }
@@ -58,18 +66,27 @@
     
 }
 
+/**
+ *  @details - Sets the velocity of the ball
+ */
 void Ball::setVelocity(Vector2D v)
 {
     velocity.x = v.x;
     velocity.y = v.y;
 }
 
+/**
+ *  @details - Sets the position of the ball
+ */
 void Ball::setPosition(Vector2D p)
 {
     _x = p.x;
     _y = p.y;
 }
 
+/**
+ *  @details - Returns a struct containing current ball velocity information
+ */
 Vector2D Ball::getVelocity()
 {
     Vector2D _velocity = {velocity.x, velocity.y};
@@ -77,6 +94,9 @@
     return _velocity;
 }
 
+/**
+ *  @details - Returns a struct containing current ball position information
+ */
 Vector2D Ball::getPosition()
 {
     Vector2D p = {_x,_y};
@@ -84,6 +104,9 @@
     return p;
 }
 
+/**
+ *  @details - Smooths out data from accelerometer and returns values in struct
+ */
 Vector2D Ball::checkForInterference(Vector2D velocity)
 {
     // +ve x
@@ -103,6 +126,6 @@
     if ((velocity.y > -0.1f) && (velocity.y < 0.0f)){
         velocity.y = 0.0f;
     }
-
+    
     return velocity;
 }
diff -r bcb96ab2848b -r 569a3f2786ec Ball.h
--- a/Ball.h	Wed May 03 21:13:45 2017 +0000
+++ b/Ball.h	Thu May 04 14:01:56 2017 +0000
@@ -1,20 +1,9 @@
-/*
- 
- @file Ball.h
- 
- (c) Max Houghton 02.14.17
- Roller Maze Project, ELEC2645, Univeristy of Leeds
- 
+/** Ball Class
+ @brief Class contains necessary parameters to draw the ball of the correct position, size and fill style.
+ @author Max Houghton
+ @date March 19 2017
  */
 
-//
-//  ball.h
-//
-//
-//  Created by Max Houghton on 19/03/2017.
-//
-//
-
 #ifndef BALL_H
 #define BALL_H
 
@@ -27,29 +16,104 @@
     
 public:
     
+    /**
+     *  @details - constructor
+     */
     Ball();
+    
+    /**
+     *  @details - destructor
+     */
     ~Ball();
     
+    /** Initialise Ball
+     *
+     *  @details - Initiases the ball with the appropriate different parameters chosen by user.
+     *  @param - x - specifies the x coordinate for the starting position of the ball.
+     *  @param - y - specifies the y coordinate for the starting position of the ball.
+     *  @param - radius - specifies size of the ball to be drawn.
+     *  @param - colour - specifies if the ball is either transparent or filled.
+     */
     void init(float x, float y, int radius, bool colour);
+    
+    /** Update
+     *
+     *  @details - Function takes the 2D Vector 'position' and updates the current position of the ball by adding on the values of 'position'.
+     *  @param - position - 2D Vector struct passed down by engine containing values for the centre of the ball for the next iteration.
+     *
+     */
     void update(Vector2D position);
+    
+    /** Draw
+     *
+     *  @details - Function draws the ball using the current set values for the centre of the ball and its radius.
+     *  @param - lcd - N5110 Library used to draw the circle representing the ball.
+     *
+     */
     void draw(N5110 &lcd);
     
+    /** Get Position
+     *
+     *  @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.
+     *
+     */
     Vector2D getPosition();
+    
+    /** Get Velocity
+     *
+     *  @details - Function returns a 2D Vector struct containing information about the ball's next position.
+     *
+     */
     Vector2D getVelocity();
     
+    /** Set Position
+     *
+     *  @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.
+     *  @param - p - 2D Vector struct containing the location of the ball to be set to.
+     *
+     */
     void setPosition(Vector2D p);
+    
+    /** Set Velocity
+     *
+     *  @details - This decides where the ball is to travel next.
+     *  @param - v - 2D Vector struct which has the location of the ball for the next iteration.
+     *
+     */
     void setVelocity(Vector2D v);
     
 private:
     
+    /**
+     *  @details - Struct containing x and y values for the following position of the ball
+     */
     Vector2D velocity;
     
+    /** Check For Interference
+     *
+     *  @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.
+     *
+     */
     Vector2D checkForInterference(Vector2D velocity);
     
+    /**
+     *  @param - _radius - Integer to decide size of the ball to be drawn.
+     */
     int _radius;
     
+    /**
+     *  @param - _x - Float value specifying x coordinate of centre of ball.
+     */
     float _x;
+    
+    /**
+     *  @param - _y - Float value specifying y coordinate of centre of ball.
+     */
     float _y;
+    
+    /**
+     *  @param - _colour - Boolean value specifying fill style of the ball; true corresponds to transparent fill and false to solid fill.
+     */
     bool _colour;
     
 };