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-01
Revision:
54:8180eec1656d
Parent:
53:a3077af736bb
Child:
55:bb4f6cc196c8

File content as of revision 54:8180eec1656d:


//change this to alter tolerance of joystick direction
#define DIRECTION_TOLERANCE 0.05
#include "ConfigFile.h"

LocalFileSystem local("local");
ConfigFile cfg;

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


Serial serial(USBTX, USBRX);

//timers to check state of buttons
Ticker timerA;//for buttonA
Ticker timerB;//for buttonB

//create buzzer objecct
Beep buzzer(p21);

//navigation/action buttons
DigitalIn buttonA(p20);//buttonA
DigitalIn buttonB(p19);//buttonB

//LED indicators
AnalogOut ledA(p18);//action LED
DigitalOut ledP(p24);//Power LED

//connections for joystick
InterruptIn joyButton(p17);//Interrupt for ISR
AnalogIn xPot(p15);//left/right
AnalogIn yPot(p16);//up/down

//Globabl Variables /////////////////////////

//sound FX toggle
int FX = 0;

//previous Direction
//stops continuous scrolling on some features
int preDirection;

//timer flags to check state of the buttons
int buttonFlagA = 0;
int buttonFlagB = 0;

//flag for joystick reading
int printFlag = 0;

//boundary conditions
int cells [84][48];

//real time score
int score = 0;

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

//global char arrays to store initials/score
char player1initials[14] = {"1.AAA.....00"};
char player2initials[14] = {"2.BBB.....00"};
char player3initials[14] = {"3.CCC.....00"};

//difficulty variable - hazards fall at 2 pixels per refresh
int fall = 2;

//global variables for movement (pixelNinja)
int a1 = 22;
int a2 = 24;
int a3 = 23;
int a4 = 25;
int a5 = 20;
int a6 = 26;
int a7 = 19;
int a8 = 21;

//global variable for hazard X co-ordinates
int randX1;
int randX2;
int randX3;
int randX4;
int randX5;
int randX6;

//global variable for hazard Y co-ordinates
int randY1 = 1;
int randY2 = 1;
int randY3 = 1;
int randY4 = 1;
int randY5 = 1;
int randY6 = 1;

//integers for changing struct ouput states
int state1 = 0;
int state2 = 0;
int state3 = 0;

//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 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();