Code for The game of Pong using Photocell Resistors
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
Revision 1:4352a2c0a4af, committed 2015-10-21
- Comitter:
- doubster
- Date:
- Wed Oct 21 01:58:52 2015 +0000
- Parent:
- 0:2a96017a6c8e
- Commit message:
- Removed and Added Comments;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2a96017a6c8e -r 4352a2c0a4af main.cpp --- a/main.cpp Mon Oct 19 22:59:32 2015 +0000 +++ b/main.cpp Wed Oct 21 01:58:52 2015 +0000 @@ -116,7 +116,7 @@ DrawBall(ballx,bally,ballcolor); while(true){ - + // Update Positions oldballx = ballx; oldbally = bally; ballx += ballxincr; @@ -126,6 +126,7 @@ paddlely += paddlelincr; paddlery += paddlerincr; + // Ball Collision with right wall if(ballx+ballradius>=border){ // Lose //ballxincr = -2; @@ -137,6 +138,7 @@ //hitvariable = 1; //Sound("hit"); } + // Ball Collision with left wall else if(ballx<=0){ // Lose Sound("end"); @@ -147,6 +149,7 @@ //hitvariable = 1; //Sound("hit"); } + // Ball Collision with top and Bottom if(bally+ballradius>=border){ ballyincr = -1; hitvariable = 1; @@ -166,7 +169,7 @@ else if(ballx+ballradius>=paddlerx && bally+ballradius>paddlery && bally-ballradius<paddlery+paddlesizey){ ballxincr = -1; } - + // Paddle not fall off the screen if(paddlely<0){ paddlely = 0; //paddlelincr = 1; @@ -183,12 +186,7 @@ paddlery = border - paddlesizey; //paddlerincr = -1; } - - //paddlelincr = 1;//(oldphotocell - photocell)/oldphotocell - photocell; - // Find a way to multiply by a certain fraction to obtain the difference in value high enough to write the line above. From old to new - // A matter of change. Or just leave it the way it is. But it should fluctuate with how fast the light changes, if the change is drastic, then we slide down the line fast. - // Or maybe it doesn't need to be so drastic. Just a simple, cover and unveil. Cover and unveil would work for this part of the game. - // Hardware Wise add teh other paddle. and software wise, simply add a new photocell at pin 16. and copy the code below. + // Get light from Photocells if(photocellleft*100 >initialphotocell) { paddlelincr = -2; @@ -213,16 +211,6 @@ DrawPaddle(paddlelx,paddlely,paddlecolor); DrawPaddle(paddlerx,paddlery,paddlecolor); } - - - - // Collisions - // For the hits might have to use threading, so that gameplay doesn't slow down when sound - // plays - //Sound("hit"); - - // Game over - //Sound("end"); }