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.
Diff: Paddle/Paddle.cpp
- Revision:
- 8:9b77eea95088
- Child:
- 12:b3ec47d606a5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Paddle/Paddle.cpp Wed May 08 13:49:01 2019 +0000
@@ -0,0 +1,53 @@
+#include "Paddle.h"
+
+/** Constructor */
+Paddle::Paddle()
+{
+ reset(); /** initial parameters of paddle */
+}
+
+/** Destructor - nothing happening here */
+Paddle::~Paddle()
+{
+}
+
+/** Adds the joystick control for the paddle */
+void Paddle::controlPaddle(Gamepad &pad)
+{
+ /** Sets the joystick as the paddle controller */
+ _d = pad.get_direction();
+
+}
+
+/** Determines the movement physics of the paddle */
+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*/
+ }
+ }
+}
+
+/** Resets paddle's initial parameters when game is over / lost */
+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 */
+}
\ No newline at end of file