![](/media/cache/profiles/004acbc8eefec9fe0629b15f52b94bcf.50x50_q85.jpg)
Peter's version
Fork of ScoreCount by
Diff: main.cpp
- Revision:
- 3:8e42915e7375
- Parent:
- 2:289c6ccc4e86
- Child:
- 4:7cec137649a0
--- a/main.cpp Wed May 01 19:46:48 2013 +0000 +++ b/main.cpp Thu May 02 13:35:41 2013 +0000 @@ -1,14 +1,11 @@ #include "mbed.h" #include "TSISensor.h" #include "TextLCD.h" - +#include "process_signal.h" -//INITIAL PARAMETERS -int hit=0; -int lives=10; //How many lives to start game with -float a; TSISensor tsi; + //RGB LED SETUP DigitalOut Red(PTC6); DigitalOut Blue(PTC10); @@ -17,46 +14,63 @@ //LCD SCREEN SETUP TextLCD lcd(PTD7, PTD6, PTA17, PTA16, PTC17, PTC16); // rs, e, d4-d7 +//INITIAL PARAMETERS AND GLOBAL VARIABLES +int hit=0; +int lives=10; //How many lives to start game with +unsigned char data[4]; +unsigned char Ah=0; +unsigned char Bh=0; +unsigned char Ch=0; +unsigned char Dh=0; +char Player='A'; +//BEGIN! int main() { + + + + while(1) { - lcd.cls(); + + reset_array(); //At start of new game reset hits from players to 0 while (lives>=0) { Blue=1; //Blue light always on when playing Red=0; //Red light off when no hits registered + Green=0; if (lives==0) { - Red=1; //Magenta if no lives remain + Green=1; //Magenta if no lives remain } - - - - //TRIGGER FOR HIT (CURRENTLY TOUCH PAD) - a=tsi.readPercentage(); - - if (a>=0.01) - {hit=1;} - else - {hit=0;} - //Print no. of lives + lcd.cls(); + lcd.locate(0,0); - lcd.printf("Lives remaining: %d \n", lives); + lcd.printf("Player %c \n", Player); + + lcd.locate(0,1); + lcd.printf("Lives left: %d \n", lives); + + //Have you been hit? + + int signal; //Signal input here! + + signal=1; + + hit= process_signal(signal); if (hit==1) { unsigned char i; - - + lives--; if(lives<0) @@ -66,7 +80,10 @@ //Update lives on LCD lcd.locate(0,0); - lcd.printf("Lives remaining: %d \n", lives); + lcd.printf("Player %c", Player); + + lcd.locate(0,1); + lcd.printf("You've been hit!"); //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? @@ -76,7 +93,7 @@ wait(0.2); Red=0; Blue=1; - wait(0.2); + wait(0.2); } }