George Cochrane
/
ScoreCount2
Peter's version
Fork of ScoreCount by
Revision 2:289c6ccc4e86, committed 2013-05-01
- Comitter:
- gcme93
- Date:
- Wed May 01 19:46:48 2013 +0000
- Parent:
- 1:d41b5b18175b
- Child:
- 3:8e42915e7375
- Commit message:
- Home improvements (cleaner)
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed May 01 14:45:59 2013 +0000 +++ b/main.cpp Wed May 01 19:46:48 2013 +0000 @@ -3,33 +3,42 @@ #include "TextLCD.h" - +//INITIAL PARAMETERS int hit=0; -int lives=10; +int lives=10; //How many lives to start game with float a; TSISensor tsi; -DigitalOut Flash(PTC11); +//RGB LED SETUP +DigitalOut Red(PTC6); +DigitalOut Blue(PTC10); +DigitalOut Green(PTC11); - +//LCD SCREEN SETUP TextLCD lcd(PTD7, PTD6, PTA17, PTA16, PTC17, PTC16); // rs, e, d4-d7 - int main() - +{ +while(1) { -Flash=1; -lcd.cls(); - - - while(1) + + lcd.cls(); + + while (lives>=0) { + Blue=1; //Blue light always on when playing + Red=0; //Red light off when no hits registered - while (lives>0) + if (lives==0) + { + Red=1; //Magenta if no lives remain + } + - { + + //TRIGGER FOR HIT (CURRENTLY TOUCH PAD) a=tsi.readPercentage(); if (a>=0.01) @@ -37,6 +46,8 @@ else {hit=0;} + + //Print no. of lives lcd.locate(0,0); lcd.printf("Lives remaining: %d \n", lives); @@ -48,55 +59,51 @@ lives--; + if(lives<0) + { + goto end; //Skip to the end (avoids read out of -1 lives) + } + + //Update lives on LCD lcd.locate(0,0); lcd.printf("Lives remaining: %d \n", lives); - for(i=0;i<4;i++) + //Flash to register hit + for(i=0;i<4;i++) //INCREASE i TO EXTEND TIME THAT GUN IS DISABLED! Maybe later add that being hit disables your own trigger? { - Flash=0; + Blue=0; + Red=1; wait(0.2); - Flash=1; - wait(0.2); + Red=0; + Blue=1; + wait(0.2); } } + } - - while (lives==0) - { - a=tsi.readPercentage(); - if (a>=0.01) - {hit=1;} - else - {hit=0;} +end: - lcd.locate(0,0); - lcd.printf("Lives remaining: %d \n", lives); - - - if (hit==1) - { - lives--; - } - } - - - +Blue=0; lcd.cls(); lcd.locate(0,0); lcd.printf(" - GAME OVER - ...you suck"); unsigned char i; -for(i=0;i<200;i++) +for(i=0;i<50;i++) //Flashing to indicate game over - INCREASE i FOR LONGER BREAK BEFORE RESET (perhaps button to reset, not auto reset?) { - Flash=0; + Red=1; wait(0.05); - Flash=1; - wait(0.05); + Red=0; + wait(0.05); } - -lcd.cls(); -lives= 10; + +//Pretty green light and resetting +Green=1; +lives= 10; +wait(2); +Green=0; +lcd.cls(); } } \ No newline at end of file