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 8:f46db1ff5ec9, committed 2013-08-21
- Comitter:
- vsluiter
- Date:
- Wed Aug 21 21:55:40 2013 +0000
- Parent:
- 7:e605dbca7330
- Child:
- 9:c5086fe3c0cc
- Commit message:
- Working game!
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Aug 21 21:10:38 2013 +0000
+++ b/main.cpp Wed Aug 21 21:55:40 2013 +0000
@@ -131,13 +131,13 @@
bool leftpushed = false, rightpushed = false;
void left_pushed(void)
{
- if(paddle.direction == 1)
+ if(paddle.direction != 1)
leftpushed = true;
}
void right_pushed(void)
{
- if(paddle.direction != 1)
+ if(paddle.direction == 1)
rightpushed = true;
}
@@ -145,14 +145,16 @@
{
Ticker updater;
Ticker demopaddlepos;
+ Timer gametimer;
InterruptIn buttonleft(PTD5);
InterruptIn buttonright(PTD0);
uint8_t ledcounter;
+ uint8_t left_score = 0, right_score = 0;
buttonleft.mode(PullUp);
buttonright.mode(PullUp);
+ buttonright.fall(right_pushed);
buttonleft.fall(left_pushed);
- buttonright.fall(right_pushed);
- updater.attach(UpdateLEDstrip, .02);
+ updater.attach(UpdateLEDstrip, .01);
demopaddlepos.attach(UpdateDemoPaddle, .03);
ledstrip.format(8,0); //15 bits, mode '0'
ledstrip.frequency(1000000);
@@ -160,6 +162,7 @@
write_led(&totalstrip[ledcounter], 0,0,0);
}
paddle.setSize(6);
+ paddle.setSpeed(30);
paddle.setColor(255,0,255);
while(1) {
//PaddleDemo(2,255,10,100);
@@ -169,27 +172,49 @@
//WinLoose(2.5, LEFT);
if(paddle.direction == 1)
{
- if(leftpushed)
+ if(rightpushed)
{
- leftpushed = false;
- paddle.direction = 0;
+ rightpushed = false;
+ if(paddle.position > (NUMBER_OF_PIXELS - paddle.getSize()) && paddle.position < NUMBER_OF_PIXELS)
+ paddle.direction = 0;
}
}
else
{
- if(rightpushed)
+ if(leftpushed)
{
- rightpushed = false;
- paddle.direction = 1;
+ leftpushed = false;
+ if(paddle.position > -paddle.getSize() && (paddle.position < 0 ) )
+ paddle.direction = 1;
}
}
- if(paddle.position == NUMBER_OF_PIXELS)
- paddle.direction = 0;
- if(paddle.position == -7)
- paddle.direction = 1;
- // paddle.position = -paddle.getSize();
- //Randomblinks(5, true);
- //WinLoose(3, false);
+ if(paddle.position >= NUMBER_OF_PIXELS && (paddle.direction == 1))
+ {
+ //left player scores!
+ left_score++;
+ WinLoose(2, false);
+ Score(left_score, right_score);
+ if(left_score+right_score == 11)
+ {
+ left_score = right_score = 0;
+ Randomblinks(2,5);
+ }
+ paddle.position = -paddle.getSize();
+
+ }
+ if(paddle.position < -paddle.getSize() && (paddle.direction == 0))
+ {
+ //right player scores!
+ right_score++;
+ WinLoose(2, true);
+ if(left_score+right_score == 11)
+ {
+ left_score = right_score = 0;
+ Randomblinks(2,5);
+ }
+ Score(left_score, right_score);
+ paddle.position = NUMBER_OF_PIXELS;
+ }
}
}