player 1
Dependencies: 4DGL-uLCD-SE PinDetect SparkfunAnalogJoystick mbed-rtos mbed SDFileSystem
Fork of 4180FinalLab by
Wireless 2 Player Pong game
paddle.cpp
- Committer:
- rishibhargava1
- Date:
- 2016-04-24
- Revision:
- 3:591086e44bf9
- Child:
- 4:7da18e3c590b
File content as of revision 3:591086e44bf9:
#include "paddle.h" Paddle::Paddle(uint8_t initx, uint8_t inity, uint8_t olength, uint8_t owidth){ x = initx; y = inity; length = length; width = width; if (y < 100){ bottom = false; } else { bottom = true; } } void Paddle::setLimits(uint8_t left, uint8_t right){ leftLim = left; rightLim = right; } void Paddle::setMaxMove(uint8_t amt){ maxMove = amt; } uint8_t Paddle::getX(){ return x; } void Paddle::setX(uint8_t newx){ x = newx; } void Paddle::move(float amt){ if (x + amt*maxMove + length > rightLim) x = rightLim - length; else if (x + amt*maxMove < leftLim) x = leftLim; else x = x + amt*maxMove; } bool Paddle::checkHit(uint8_t ballX, uint8_t ballY, uint8_t size){ if (ballX+size/2 >= x && ballX+size/2 <= x+length){ if (bottom && (ballY+size >= y && ballY <= y+width)){ return true; } else if (!bottom && (ballY <= y+width && ballY+size >= y)){ return true; } } return false; } uint8_t Paddle::returnAngle(uint8_t ballX, uint8_t size){ return abs((ballX+size/2 - (x + length/2))); } bool Paddle::returnDir(uint8_t ballX, uint8_t size){ if (ballX+size/2 > (x+length/2)){ return true; } else return false; } void Paddle::reset(uint8_t initx, uint8_t inity){ x = initx; y = inity; }