Kostadin Chakarov / Mbed 2 deprecated el17kec

Dependencies:   mbed

Committer:
kocemax
Date:
Thu May 09 11:55:47 2019 +0000
Revision:
13:3585d2ea4ff4
Parent:
12:b3ec47d606a5
Hopefully final commit, since I probably fixed all the comments

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 Paddle::Paddle()
kocemax 8:9b77eea95088 4 {
kocemax 12:b3ec47d606a5 5 reset(); // initial parameters of paddle
kocemax 8:9b77eea95088 6 }
kocemax 8:9b77eea95088 7
kocemax 8:9b77eea95088 8 Paddle::~Paddle()
kocemax 8:9b77eea95088 9 {
kocemax 8:9b77eea95088 10 }
kocemax 8:9b77eea95088 11
kocemax 8:9b77eea95088 12 void Paddle::controlPaddle(Gamepad &pad)
kocemax 8:9b77eea95088 13 {
kocemax 12:b3ec47d606a5 14 // Sets the joystick as the paddle controller
kocemax 8:9b77eea95088 15 _d = pad.get_direction();
kocemax 8:9b77eea95088 16
kocemax 8:9b77eea95088 17 }
kocemax 8:9b77eea95088 18
kocemax 8:9b77eea95088 19 void Paddle::move()
kocemax 8:9b77eea95088 20 {
kocemax 12:b3ec47d606a5 21 // Moving right
kocemax 8:9b77eea95088 22 if (_d == E) {
kocemax 12:b3ec47d606a5 23 pos.x = pos.x + _speed; // Adds speed to current position on x-axis
kocemax 8:9b77eea95088 24
kocemax 8:9b77eea95088 25 if (pos.x >= WIDTH - w) {
kocemax 12:b3ec47d606a5 26 pos.x = WIDTH - w; // Sets the right-most limit to paddle
kocemax 8:9b77eea95088 27 }
kocemax 8:9b77eea95088 28 }
kocemax 12:b3ec47d606a5 29 // Moving left
kocemax 8:9b77eea95088 30 if (_d == W) {
kocemax 12:b3ec47d606a5 31 pos.x = pos.x - _speed; // Subtracts speed from current position on x-axis
kocemax 8:9b77eea95088 32
kocemax 8:9b77eea95088 33 if (pos.x <= 0) {
kocemax 12:b3ec47d606a5 34 pos.x = 0; // Sets the left-most limit to paddle
kocemax 8:9b77eea95088 35 }
kocemax 8:9b77eea95088 36 }
kocemax 8:9b77eea95088 37 }
kocemax 8:9b77eea95088 38
kocemax 8:9b77eea95088 39 void Paddle::reset()
kocemax 8:9b77eea95088 40 {
kocemax 12:b3ec47d606a5 41 pos.x = WIDTH/2; // position of paddle on x-axis
kocemax 12:b3ec47d606a5 42 pos.y = HEIGHT - GAP; // position of paddle on y-axis
kocemax 12:b3ec47d606a5 43 velocity.x = 0; // x-velocity of paddle is zero as it does not move by itself
kocemax 12:b3ec47d606a5 44 velocity.y = 0; // y-velocity of paddle is zero as it does not move by itself
kocemax 12:b3ec47d606a5 45 w = 12; // width of the paddle
kocemax 12:b3ec47d606a5 46 h = 2; // height of the paddle
kocemax 12:b3ec47d606a5 47 _speed = 2; // speed of movement of paddle
kocemax 8:9b77eea95088 48 }