Two player imu pong
Dependencies: 4DGL-uLCD-SE IMUfilter LSM9DS0 PinDetect mbed
Paddle.cpp
- Committer:
- rrr93
- Date:
- 2015-10-22
- Revision:
- 0:941225f01ccc
File content as of revision 0:941225f01ccc:
#include "paddle.h" Paddle::Paddle(int len, int width) { setLength(len); setWidth(width); setPaddleMove(8); y = 1; x = 118; oldy = y; resetScore(); } Paddle::Paddle(int len, int wid, int xi, int yi) { setLength(len); setWidth(wid); setPaddleMove(8); y = yi; x = xi; oldy = y; resetScore(); } //set functions void Paddle::setLength(int len) { length = len; } void Paddle::setWidth(int wid) { width = wid; } void Paddle::setPaddleMove(int move) { paddleMove = move; } /* void Paddle::setLimits(int top, int bot) { topLimit = top; bottomLimit = bot; } */ // get Function int Paddle::getScore() { return score; } //Member Functions void Paddle::movePaddle(bool mv) { if (mv) {if(y > paddleMove) {y -=paddleMove;} // end of inner if } // end of outer if else { if(y < 127 - paddleMove - length) { y+= paddleMove;} }//end of else }//ends function bool Paddle::checkHitX(int xpos, int ypos, int radius, bool left) { if (left) { if ((xpos <= x+radius+width) && (ypos <= y +length) && (ypos>=y)) { score = score +1; return true; } else { return false;} } else { if ((xpos>= x-radius) && (ypos <= y +length) && (ypos>=y)) { score = score +1; return true; } else { return false;} } } bool Paddle::checkHitY(int xpos, int ypos, int radius) { if (((xpos >= x) && (xpos <= x+3)) && ((ypos>=y) && (ypos<=y +length))) { return true;} else {return false;} } void Paddle::resetScore() { score = 0; } void Paddle::initDraw(uLCD_4DGL *screen) { screen->filled_rectangle(x, y, x+width, y+length, BLUE); } void Paddle::redraw(uLCD_4DGL *uLCD) { if(oldy > y) { uLCD->filled_rectangle(x, oldy-paddleMove+1, x+width, oldy, BLUE); uLCD->filled_rectangle(x, oldy+length-paddleMove+1, x+width, oldy+length, BLACK); oldy = y; } else if(oldy < y) { uLCD->filled_rectangle(x, oldy, x+width, oldy+paddleMove, BLACK); uLCD->filled_rectangle(x, oldy+length,x+width, oldy+length+paddleMove, BLUE); oldy = y; } }