Class containing methods to draw a ball within the maze game with the specified position, size and fill style parameters.
Diff: Ball.cpp
- Revision:
- 3:569a3f2786ec
- Parent:
- 2:bcb96ab2848b
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; }