Kostadin Chakarov / Mbed 2 deprecated el17kec

Dependencies:   mbed

Committer:
kocemax
Date:
Thu May 09 11:41:58 2019 +0000
Revision:
12:b3ec47d606a5
Parent:
8:9b77eea95088
Child:
13:3585d2ea4ff4
Had to fix more of the comments, to improve the documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kocemax 8:9b77eea95088 1 #include "Paddle.h"
kocemax 8:9b77eea95088 2
kocemax 8:9b77eea95088 3 /** Constructor */
kocemax 8:9b77eea95088 4 Paddle::Paddle()
kocemax 8:9b77eea95088 5 {
kocemax 12:b3ec47d606a5 6 reset(); // initial parameters of paddle
kocemax 8:9b77eea95088 7 }
kocemax 8:9b77eea95088 8
kocemax 8:9b77eea95088 9 /** Destructor - nothing happening here */
kocemax 8:9b77eea95088 10 Paddle::~Paddle()
kocemax 8:9b77eea95088 11 {
kocemax 8:9b77eea95088 12 }
kocemax 8:9b77eea95088 13
kocemax 8:9b77eea95088 14 /** Adds the joystick control for the paddle */
kocemax 8:9b77eea95088 15 void Paddle::controlPaddle(Gamepad &pad)
kocemax 8:9b77eea95088 16 {
kocemax 12:b3ec47d606a5 17 // Sets the joystick as the paddle controller
kocemax 8:9b77eea95088 18 _d = pad.get_direction();
kocemax 8:9b77eea95088 19
kocemax 8:9b77eea95088 20 }
kocemax 8:9b77eea95088 21
kocemax 8:9b77eea95088 22 /** Determines the movement physics of the paddle */
kocemax 8:9b77eea95088 23 void Paddle::move()
kocemax 8:9b77eea95088 24 {
kocemax 12:b3ec47d606a5 25 // Moving right
kocemax 8:9b77eea95088 26 if (_d == E) {
kocemax 12:b3ec47d606a5 27 pos.x = pos.x + _speed; // Adds speed to current position on x-axis
kocemax 8:9b77eea95088 28
kocemax 8:9b77eea95088 29 if (pos.x >= WIDTH - w) {
kocemax 12:b3ec47d606a5 30 pos.x = WIDTH - w; // Sets the right-most limit to paddle
kocemax 8:9b77eea95088 31 }
kocemax 8:9b77eea95088 32 }
kocemax 12:b3ec47d606a5 33 // Moving left
kocemax 8:9b77eea95088 34 if (_d == W) {
kocemax 12:b3ec47d606a5 35 pos.x = pos.x - _speed; // Subtracts speed from current position on x-axis
kocemax 8:9b77eea95088 36
kocemax 8:9b77eea95088 37 if (pos.x <= 0) {
kocemax 12:b3ec47d606a5 38 pos.x = 0; // Sets the left-most limit to paddle
kocemax 8:9b77eea95088 39 }
kocemax 8:9b77eea95088 40 }
kocemax 8:9b77eea95088 41 }
kocemax 8:9b77eea95088 42
kocemax 8:9b77eea95088 43 /** Resets paddle's initial parameters when game is over / lost */
kocemax 8:9b77eea95088 44 void Paddle::reset()
kocemax 8:9b77eea95088 45 {
kocemax 12:b3ec47d606a5 46 pos.x = WIDTH/2; // position of paddle on x-axis
kocemax 12:b3ec47d606a5 47 pos.y = HEIGHT - GAP; // position of paddle on y-axis
kocemax 12:b3ec47d606a5 48 velocity.x = 0; // x-velocity of paddle is zero as it does not move by itself
kocemax 12:b3ec47d606a5 49 velocity.y = 0; // y-velocity of paddle is zero as it does not move by itself
kocemax 12:b3ec47d606a5 50 w = 12; // width of the paddle
kocemax 12:b3ec47d606a5 51 h = 2; // height of the paddle
kocemax 12:b3ec47d606a5 52 _speed = 2; // speed of movement of paddle
kocemax 8:9b77eea95088 53 }