A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.

Dependencies:   ConfigFile N5110 PowerControl beep mbed

tower.h

Committer:
el13drt
Date:
2015-05-05
Revision:
62:827cda7a2663
Parent:
60:681bc941b94d
Child:
63:ff9b64b23d26

File content as of revision 62:827cda7a2663:

/**
@file tower.h
@brief Revision 1.0.
@author Daniel R. Tomlinson
@date   May 2015

@brief Header file - Contains Global Variables, Inputs/Outputs and Function prototypes. 
*/

///Alters tolerance of Joystick directions
#define DIRECTION_TOLERANCE 0.05
#include "ConfigFile.h"

/**
@namespace lcd
*/
N5110 lcd(p7,p8,p9,p10,p11,p13,p22);//VCC, SCE, RST, D/C, MOSI, SCLK, LED - assign pins for LCD.

/**
@namespace local
*/
LocalFileSystem local("local");
ConfigFile cfg;

/**
@namespace serial.
*/
Serial serial(USBTX, USBRX);

/**  
@namespace timerA.
@brief timerA - the function timerExpiredA every 0.1 sec.
*/
Ticker timerA;//for buttonA

/**
@namespace timerB.
@parameter Calls the function timerExpiredB every 0.1 sec.
*/
Ticker timerB;//for buttonB

/**
@namespace pollJoystick.
*/
Ticker pollJoystick;

/**
@namespace buzzer.
*/
Beep buzzer(p21);

/**  
@namespace buttonA
*/
DigitalIn buttonA(p20);

/**  
@namespace buttonB
*/
DigitalIn buttonB(p19);

/**
@namespace ledA.
*/
AnalogOut ledA(p18);//action LED

/**
@namespace ledP.
*/
DigitalOut ledP(p24);//Power LED

/**
@namespace joyButton.
*/
InterruptIn joyButton(p17);//Interrupt for ISR

/**
@namespace xpot.
*/
AnalogIn xPot(p15);//left/right

/**
@namespace ypot.
*/
AnalogIn yPot(p16);//up/down

//Globabl Variables

//sound FX toggle
int FX = 0;/*!< Toggle for Sound FX. */

//previous Direction
//stops continuous scrolling on some features
int preDirection;/*!< Used to stop continuous scrolling. */

//timer flags to check state of the buttons
int buttonFlagA = 0;/*!< Button flag set for ISR when state of buttonA changes. */
int buttonFlagB = 0;/*!< Button flag set for ISR when state of buttonB changes. */

//button values for debounce problem
int oldButtonA = 0;
int newButtonA;

int oldButtonB = 0;
int newButtonB;

//flag for joystick reading
int printFlag = 0;/*!< Print flag set for ISR when Joystick is moved. */

//boundary conditions
int cells [84][48];/*!< Boundary conditions for cells.*/

//real time score
int score = 0;/*!< Integer to show and print Scores. */

//stored high score variables
int highScore1;
int highScore2;
int highScore3;

//global char arrays to store initials/score
char player1initials[14] = {"1.AAA.....0"};/*!< Buffer for printing Initials and Top Score 1.*/
char player2initials[14] = {"2.BBB.....0"};/*!< Buffer for printing Initials and Top Score 2.*/
char player3initials[14] = {"3.CCC.....0"};/*!< Buffer for printing Initials and Top Score 3.*/

//difficulty variable - hazards fall at 2 pixels per refresh
int fall = 2;/*!< Increments hazards each Iteration by the Integer stored. */

//global variables for movement (pixelNinja)
int a1 = 22;
int a2 = 24;
int a3 = 23;
int a4 = 22;
int a5 = 22;
int a6 = 24;
int a7 = 25;
int a8 = 20;
int a9 = 20;
int a10 = 26;
int a11 = 26;
int a12 = 26;
int a13 = 24;
int a14 = 19;
int a15 = 20;
int a16 = 21;

//global variable for hazard X co-ordinates
int randX1;/*!< X co-ordinate for Hazard 1. */
int randX2;/*!< X co-ordinate for Hazard 2. */
int randX3;/*!< X co-ordinate for Hazard 3. */
int randX4;/*!< X co-ordinate for Hazard 4. */
int randX5;/*!< X co-ordinate for Hazard 5. */
int randX6;/*!< X co-ordinate for Hazard 6. */

//global variable for hazard Y co-ordinates
int randY1 = 1;/*!< Y co-ordinate for Hazard 1. */
int randY2 = 1;/*!< Y co-ordinate for Hazard 2. */
int randY3 = 1;/*!< Y co-ordinate for Hazard 3. */
int randY4 = 1;/*!< Y co-ordinate for Hazard 4. */
int randY5 = 1;/*!< Y co-ordinate for Hazard 5. */
int randY6 = 1;/*!< Y co-ordinate for Hazard 6. */

//integers for changing struct ouput states
int state1 = 0;/*!< State number for Output 1.*/
int state2 = 0;/*!< State number for output 2.*/
int state3 = 0;/*!< State number for output 3.*/

//prototypes
void calibrateJoystick();
void updateJoystick();
void timerExpiredA();
void timerExpiredB();
void actionButton();
void randomise();
void resetGame();
void startrek();
void refreshCursor1();
void refreshCursor2();
void refreshCursor3();
void ninjaBoundaries();
void ninjaLeft();
void ninjaRight();
void hazardFall();
void newScore();

void mainMenu();
void exitMenu();
void optionsMenu();
void game();
void difficultyMenu();
void soundFXMenu();
void scores();

/**

*/
void drawNinja();

/**

*/
void drawHazards();

/**

*/
void drawWelcome();

/**

*/
void drawBackground();

/**

*/
void drawSoundFXMenu();

/**

*/
void drawDifficultyMenu();

/**

*/
void drawMainMenu();

/**

*/
void drawOptionsMenu();

/**

*/
void drawExitMenu();