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.
Revision 13:e96098b6660d, committed 2013-08-22
- Comitter:
- vsluiter
- Date:
- Thu Aug 22 22:57:00 2013 +0000
- Parent:
- 12:97c71b84c984
- Child:
- 14:5b588ea6bd8f
- Commit message:
- Improved paddle handling
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 22 22:35:36 2013 +0000
+++ b/main.cpp Thu Aug 22 22:57:00 2013 +0000
@@ -176,51 +176,57 @@
static uint8_t naglevel1 = 0, naglevel2 = 0;
//paddle.position = 48;
//while(1);
- if(paddle.direction == 1)
+ if(leftpushed || rightpushed)
{
- if(rightpushed)
+ if(paddle.direction == 1)
{
- //printf("\n\rright pushed");
- rightpushed = false;
- if(rightpushpos >= NUMBER_OF_PIXELS && rightpushpos < (NUMBER_OF_PIXELS + paddle.getSize()) )
+ if(rightpushed)
{
- paddle.direction = 0;
- paddle.position = NUMBER_OF_PIXELS;
+ //printf("\n\rright pushed");
+ rightpushed = false;
+ if(rightpushpos >= NUMBER_OF_PIXELS )
+ {
+ paddle.direction = 0;
+ paddle.position = NUMBER_OF_PIXELS;
+ }
+ pc.printf("\n\rright pushed. Paddle position: %d, registered: %d", paddle.position, rightpushpos);
}
- pc.printf("\n\rright pushed. Paddle position: %d, registered: %d", paddle.position, rightpushpos);
+ }
+ else
+ {
+ if(leftpushed)
+ {
+ //printf("\n\rleft pushed");
+ leftpushed = false;
+ if(leftpushpos <= 0 )
+ {
+ paddle.direction = 1;
+ paddle.position = 0;
+ }
+ pc.printf("\n\rleft pushed. Paddle position: %d, registered: %d", paddle.position, leftpushpos);
+ }
}
}
else
- {
- if(leftpushed)
+ {
+ if(paddle.position > ( NUMBER_OF_PIXELS + paddle.getSize() ) && (paddle.direction == 1))
{
- //printf("\n\rleft pushed");
- leftpushed = false;
- if(leftpushpos > -paddle.getSize() && (paddle.position <= 0 ) )
- {
- paddle.direction = 1;
- paddle.position = 0;
- }
- pc.printf("\n\rleft pushed. Paddle position: %d, registered: %d", paddle.position, leftpushpos);
+ pc.printf("\n\rleft player score. Paddle position: %d", paddle.position);
+ //left player scores!
+ left_score++;
+ HandleScore(&left_score,&right_score,false, &gametimer);
+ paddle.position = -paddle.getSize();
+ naglevel1=naglevel2 = 0;
}
- }
- if(paddle.position > ( NUMBER_OF_PIXELS + paddle.getSize() ) && (paddle.direction == 1))
- {
- pc.printf("\n\rleft player score. Paddle position: %d", paddle.position);
- //left player scores!
- left_score++;
- HandleScore(&left_score,&right_score,false, &gametimer);
- paddle.position = -paddle.getSize();
- naglevel1=naglevel2 = 0;
- }
- if(paddle.position < -paddle.getSize() && (paddle.direction == 0))
- {
- pc.printf("\n\rleft player score. Paddle position: %d", paddle.position);
- //right player scores!
- right_score++;
- HandleScore(&left_score,&right_score,true, &gametimer);
- naglevel1=naglevel2 = 0;
- paddle.position = NUMBER_OF_PIXELS;
+ if(paddle.position < -paddle.getSize() && (paddle.direction == 0))
+ {
+ pc.printf("\n\rlright player score. Paddle position: %d", paddle.position);
+ //right player scores!
+ right_score++;
+ HandleScore(&left_score,&right_score,true, &gametimer);
+ naglevel1=naglevel2 = 0;
+ paddle.position = NUMBER_OF_PIXELS;
+ }
}
if(gametimer.read()>6 && !naglevel1)
{