George Cochrane
/
ScoreCount2
Peter's version
Fork of ScoreCount by
Revision 3:8e42915e7375, committed 2013-05-02
- Comitter:
- gcme93
- Date:
- Thu May 02 13:35:41 2013 +0000
- Parent:
- 2:289c6ccc4e86
- Child:
- 4:7cec137649a0
- Commit message:
- latest badboy
Changed in this revision
--- 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); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/process_signal.cpp Thu May 02 13:35:41 2013 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" + +//Function needs "signal" input, will register hit and add to array + +void reset_array(void) + { + + extern char data[4]; + + //Reset hits from each player + data[0]=0; + data[1]=0; + data[2]=0; + data[3]=0; + } + +unsigned char process_signal(int signal) + { + unsigned char x; + extern unsigned char Ah; + extern unsigned char Bh; + extern unsigned char Ch; + extern unsigned char Dh; + extern char data[4]; + + if (signal==1) + { + Ah++; + data[0]=Ah; + } + + if (signal==2) + { + Bh++; + data[1]=Bh; + } + + if (signal==3) + { + Ch++; + data[2]=Ch; + } + + if (signal==4) + { + Dh++; + data[3]=Dh; + } + + if (signal!=(1 || 2 || 3 || 4)) + { x=0; } + + else + { x=1; } + + return x; + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/process_signal.h Thu May 02 13:35:41 2013 +0000 @@ -0,0 +1,2 @@ +unsigned char process_signal(int signal); +void reset_array(void); \ No newline at end of file