C++ Project 2016-2017: Arkanoid
Public Member Functions | Protected Attributes | List of all members
arkanoid::Ball Class Reference

The Ball in the Arkanoid game. More...

#include <ball.h>

Inheritance diagram for arkanoid::Ball:
arkanoid::Entity arkanoidSFML::BallSFML

Public Member Functions

 Ball ()
 
 Ball (double x, double y, double newSpeed=8.0, pair< double, double > size=make_pair(1.0, 1.0))
 
 ~Ball ()
 
void update ()
 
void draw () const
 
void speedUp (double factor)
 
void setInvisible (int period)
 
template<typename T >
vector< int > bounceIfPossible (vector< unique_ptr< T >> const &entities)
 
void bounceIfPossible (unique_ptr< Player > const &player)
 
virtual void reset ()
 
- Public Member Functions inherited from arkanoid::Entity
 Entity ()
 
 Entity (double x, double y, pair< double, double > newSize=make_pair(1.0, 1.0))
 
virtual ~Entity ()
 
Vector2D getPosition () const
 
void setPosition (double x, double y)
 
void setPosition (const Vector2D &vector)
 
void setSize (pair< double, double > newSize)
 
pair< double, double > getSize () const
 
bool collidesWith (const Entity &other) const
 

Protected Attributes

Vector2D velocity
 
Vector2D origin
 
double speed
 
bool notMoving
 
int invisDuration
 
bool spedUp
 
Randomrandom
 
- Protected Attributes inherited from arkanoid::Entity
Vector2D position
 The current position of the Entity (in the 9x7 grid).
 
pair< double, double > size
 The size (width and height respectively) of the Entity.
 

Detailed Description

The Ball in the Arkanoid game.

Definition at line 21 of file ball.h.

Constructor & Destructor Documentation

◆ Ball() [1/2]

arkanoid::Ball::Ball ( )

Default Constructor.

Initialise the Ball at origin ([0, 0]) in the World.

Definition at line 17 of file ball.cpp.

◆ Ball() [2/2]

arkanoid::Ball::Ball ( double  x,
double  y,
double  newSpeed = 8.0,
pair< double, double >  size = make_pair(1.0, 1.0) 
)

Constructor.

Initialise the Ball at a specific position in the World.

Parameters
xThe x position (in the grid) of the Ball.
yThe y position (in the grid) of the Ball.
newSpeed(optional) The speed of the Ball.
size(optional) The size (width and height respectively) of the Ball.

Definition at line 19 of file ball.cpp.

◆ ~Ball()

arkanoid::Ball::~Ball ( )

Destructor.

Definition at line 21 of file ball.cpp.

Member Function Documentation

◆ bounceIfPossible() [1/2]

template<typename T >
vector< int > arkanoid::Ball::bounceIfPossible ( vector< unique_ptr< T >> const &  entities)

Checks for all Entity if there's a collision, if there is, then "bounce" off the Entity, i.e. rotate 90° in the right direction.

Parameters
entitiesList of all the Entity of the World (Ball not included).
Returns
The indeces in the list of the Entity that the Ball collided with.

Definition at line 39 of file ball.cpp.

◆ bounceIfPossible() [2/2]

void arkanoid::Ball::bounceIfPossible ( unique_ptr< Player > const &  player)

Checks if there's a collision with the Player, if there is, make the correct bounce (angle) depending on the point of collision.

Parameters
playerThe Player of the World.

Definition at line 99 of file ball.cpp.

◆ draw()

void arkanoid::Ball::draw ( ) const
virtual

Do nothing...

Implements arkanoid::Entity.

Definition at line 25 of file ball.cpp.

◆ reset()

void arkanoid::Ball::reset ( )
virtual

Reset the direction of the Ball and set it at a specific position. (-> call this method when the Player missed the Ball).

Reimplemented in arkanoidSFML::BallSFML.

Definition at line 140 of file ball.cpp.

◆ setInvisible()

void arkanoid::Ball::setInvisible ( int  period)

Make the Ball invisible for a period of time.

Parameters
periodThe period the Ball becomes invisible (in frames).

Definition at line 34 of file ball.cpp.

◆ speedUp()

void arkanoid::Ball::speedUp ( double  factor)

Change the velocity of the Ball by a factor.

Parameters
factorThe factor.

Definition at line 27 of file ball.cpp.

◆ update()

void arkanoid::Ball::update ( )
virtual

Do nothing...

Implements arkanoid::Entity.

Definition at line 23 of file ball.cpp.


The documentation for this class was generated from the following files: