Peter's version

Fork of ScoreCount by George Cochrane

main.cpp

Committer:
gcme93
Date:
2013-05-02
Revision:
3:8e42915e7375
Parent:
2:289c6ccc4e86
Child:
4:7cec137649a0

File content as of revision 3:8e42915e7375:

#include "mbed.h"
#include "TSISensor.h"
#include "TextLCD.h"
#include "process_signal.h"

TSISensor tsi;


//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

//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) 
{
    
    
    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)
    {
    Green=1;      //Magenta if no lives remain
    }
    
    //Print no. of lives
    lcd.cls();
    
    lcd.locate(0,0);
    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)
                {
                goto end;        //Skip to the end (avoids read out of -1 lives)
                }
                
                //Update lives on LCD
                lcd.locate(0,0);
                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?
                    {
                    Blue=0;
                    Red=1;
                    wait(0.2);
                    Red=0;
                    Blue=1;
                    wait(0.2);                  
                    }
                }
    
    }
    
end:

Blue=0;
lcd.cls();
lcd.locate(0,0);
lcd.printf(" - GAME  OVER - ...you suck");


unsigned char 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?)
                    {
                    Red=1;
                    wait(0.05);
                    Red=0;
                    wait(0.05); 
                    }
                    
//Pretty green light and resetting
Green=1;  
lives= 10;
wait(2);    
Green=0;        
lcd.cls(); 
}
}