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.cpp
00001 #include "Paddle.h" 00002 00003 Paddle::Paddle() 00004 { 00005 reset(); // initial parameters of paddle 00006 } 00007 00008 Paddle::~Paddle() 00009 { 00010 } 00011 00012 void Paddle::controlPaddle(Gamepad &pad) 00013 { 00014 // Sets the joystick as the paddle controller 00015 _d = pad.get_direction(); 00016 00017 } 00018 00019 void Paddle::move() 00020 { 00021 // Moving right 00022 if (_d == E) { 00023 pos.x = pos.x + _speed; // Adds speed to current position on x-axis 00024 00025 if (pos.x >= WIDTH - w) { 00026 pos.x = WIDTH - w; // Sets the right-most limit to paddle 00027 } 00028 } 00029 // Moving left 00030 if (_d == W) { 00031 pos.x = pos.x - _speed; // Subtracts speed from current position on x-axis 00032 00033 if (pos.x <= 0) { 00034 pos.x = 0; // Sets the left-most limit to paddle 00035 } 00036 } 00037 } 00038 00039 void Paddle::reset() 00040 { 00041 pos.x = WIDTH/2; // position of paddle on x-axis 00042 pos.y = HEIGHT - GAP; // position of paddle on y-axis 00043 velocity.x = 0; // x-velocity of paddle is zero as it does not move by itself 00044 velocity.y = 0; // y-velocity of paddle is zero as it does not move by itself 00045 w = 12; // width of the paddle 00046 h = 2; // height of the paddle 00047 _speed = 2; // speed of movement of paddle 00048 }
Generated on Thu Jul 14 2022 02:02:53 by
1.7.2