Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Paddle/Paddle.cpp
- Committer:
- kocemax
- Date:
- 2019-05-09
- Revision:
- 13:3585d2ea4ff4
- Parent:
- 12:b3ec47d606a5
File content as of revision 13:3585d2ea4ff4:
#include "Paddle.h"
Paddle::Paddle()
{
reset(); // initial parameters of paddle
}
Paddle::~Paddle()
{
}
void Paddle::controlPaddle(Gamepad &pad)
{
// Sets the joystick as the paddle controller
_d = pad.get_direction();
}
void Paddle::move()
{
// Moving right
if (_d == E) {
pos.x = pos.x + _speed; // Adds speed to current position on x-axis
if (pos.x >= WIDTH - w) {
pos.x = WIDTH - w; // Sets the right-most limit to paddle
}
}
// Moving left
if (_d == W) {
pos.x = pos.x - _speed; // Subtracts speed from current position on x-axis
if (pos.x <= 0) {
pos.x = 0; // Sets the left-most limit to paddle
}
}
}
void Paddle::reset()
{
pos.x = WIDTH/2; // position of paddle on x-axis
pos.y = HEIGHT - GAP; // position of paddle on y-axis
velocity.x = 0; // x-velocity of paddle is zero as it does not move by itself
velocity.y = 0; // y-velocity of paddle is zero as it does not move by itself
w = 12; // width of the paddle
h = 2; // height of the paddle
_speed = 2; // speed of movement of paddle
}