Kostadin Chakarov / Mbed 2 deprecated el17kec

Dependencies:   mbed

Committer:
kocemax
Date:
Wed May 08 13:49:01 2019 +0000
Revision:
8:9b77eea95088
Child:
12:b3ec47d606a5
Finally, implemented power ups and fixed the angles after pad collision. Also started commenting, not much time left, so will finish the commenting and if I have more time will add a couple more 'negative' power ups.

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 8:9b77eea95088 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 8:9b77eea95088 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 8:9b77eea95088 25 /** Moving right */
kocemax 8:9b77eea95088 26 if (_d == E) {
kocemax 8:9b77eea95088 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 8:9b77eea95088 30 pos.x = WIDTH - w; /** Sets the right-most limit to paddle*/
kocemax 8:9b77eea95088 31 }
kocemax 8:9b77eea95088 32 }
kocemax 8:9b77eea95088 33 /** Moving left */
kocemax 8:9b77eea95088 34 if (_d == W) {
kocemax 8:9b77eea95088 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 8:9b77eea95088 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 8:9b77eea95088 46 pos.x = WIDTH/2; /** position of paddle on x-axis */
kocemax 8:9b77eea95088 47 pos.y = HEIGHT - GAP; /** position of paddle on y-axis */
kocemax 8:9b77eea95088 48 velocity.x = 0; /** x-velocity of paddle is zero as it does not move by itself */
kocemax 8:9b77eea95088 49 velocity.y = 0; /** y-velocity of paddle is zero as it does not move by itself */
kocemax 8:9b77eea95088 50 w = 12; /** width of the paddle */
kocemax 8:9b77eea95088 51 h = 2; /** height of the paddle */
kocemax 8:9b77eea95088 52 _speed = 2; /** speed of movement of paddle */
kocemax 8:9b77eea95088 53 }