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.
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed-rtos mbed wave_player
Fork of ECE2036Lab2StarterCode by
paddle.cpp
00001 #include "paddle.h" 00002 #include "uLCD_4DGL.h" 00003 00004 // Constructors 00005 Paddle::Paddle() { 00006 setLength(40); 00007 setWidth(3); 00008 setPaddleMove(8); 00009 setX(118);//118 00010 setY(1); 00011 setOldY(1); 00012 } 00013 00014 /**** Set Functions ****/ 00015 00016 void Paddle::setLength(int set_length) {length = set_length; } 00017 void Paddle::setWidth(int set_width) {width = set_width; } 00018 void Paddle::setPaddleMove(int set_pMove){paddleMove = set_pMove; } 00019 void Paddle::setScore(int set_score) {score += set_score; } 00020 void Paddle::setX(int set_x) {x = set_x; } 00021 void Paddle::setY(int set_y) {y = set_y; } 00022 void Paddle::setOldY(int set_oy) {oldy = set_oy; } 00023 00024 /**** Get Functions ****/ 00025 00026 int Paddle::getLength() {return length; } 00027 int Paddle::getWidth() {return width; } 00028 int Paddle::getPaddleMove() {return paddleMove; } 00029 int Paddle::getScore() {return score; } 00030 int Paddle::getX() {return x; } 00031 int Paddle::getY() {return y; } 00032 int Paddle::getOldY() {return oldy; } 00033 00034 /**** Member Functions ****/ 00035 00036 void Paddle::movePaddleUp() { 00037 // moves the paddle up (does not draw!) 00038 if(y > paddleMove) 00039 y -= paddleMove; 00040 } 00041 void Paddle::movePaddleDown() { 00042 // moves the paddle up (does not draw!) 00043 if(y < 127 - paddleMove - length) 00044 y += paddleMove; 00045 } 00046 void Paddle::resetScore() {score = 0; } // resets score 00047 void Paddle::initDraw(uLCD_4DGL *uLCD) { 00048 // draw the paddle initially (draws the whole thing) 00049 uLCD->filled_rectangle(x, y, x + width, y + length, BLUE); 00050 } 00051 void Paddle::redraw(uLCD_4DGL *uLCD) { 00052 // draws the paddle for a move (does NOT draw the whole thing) 00053 if(oldy > y) { 00054 uLCD->filled_rectangle(x, oldy - paddleMove + 1, x + width, oldy, BLUE); 00055 uLCD->filled_rectangle(x, oldy + length - paddleMove + 1, x + width, oldy + length, BLACK); 00056 oldy = y; 00057 } 00058 else if(oldy < y) { 00059 uLCD->filled_rectangle(x, oldy, x + width, oldy + paddleMove, BLACK); 00060 uLCD->filled_rectangle(x, oldy + length, x + width, oldy + length + paddleMove, BLUE); 00061 oldy = y; 00062 } 00063 }// end redraw
Generated on Tue Jul 19 2022 14:32:53 by
1.7.2
