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

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Committer:
el13drt
Date:
Fri May 01 22:07:05 2015 +0000
Revision:
54:8180eec1656d
Parent:
53:a3077af736bb
Child:
55:bb4f6cc196c8
pre timer memory

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el13drt 13:a1b3a373c5a4 1
el13drt 35:9f55326c1b0a 2 //change this to alter tolerance of joystick direction
el13drt 13:a1b3a373c5a4 3 #define DIRECTION_TOLERANCE 0.05
el13drt 54:8180eec1656d 4 #include "ConfigFile.h"
el13drt 12:eedda6554615 5
el13drt 54:8180eec1656d 6 LocalFileSystem local("local");
el13drt 54:8180eec1656d 7 ConfigFile cfg;
el13drt 24:eb80956e2e95 8
el13drt 35:9f55326c1b0a 9 //VCC,SCE,RST,D/C,MOSI,SCLK,LED - set pins for LCD
el13drt 12:eedda6554615 10 N5110 lcd(p7,p8,p9,p10,p11,p13,p22);
el13drt 12:eedda6554615 11
el13drt 54:8180eec1656d 12
el13drt 54:8180eec1656d 13 Serial serial(USBTX, USBRX);
el13drt 54:8180eec1656d 14
el13drt 35:9f55326c1b0a 15 //timers to check state of buttons
el13drt 35:9f55326c1b0a 16 Ticker timerA;//for buttonA
el13drt 35:9f55326c1b0a 17 Ticker timerB;//for buttonB
el13drt 15:ff3eb0091453 18
el13drt 35:9f55326c1b0a 19 //create buzzer objecct
el13drt 13:a1b3a373c5a4 20 Beep buzzer(p21);
el13drt 13:a1b3a373c5a4 21
el13drt 35:9f55326c1b0a 22 //navigation/action buttons
el13drt 40:56ab6d368e9b 23 DigitalIn buttonA(p20);//buttonA
el13drt 40:56ab6d368e9b 24 DigitalIn buttonB(p19);//buttonB
el13drt 13:a1b3a373c5a4 25
el13drt 35:9f55326c1b0a 26 //LED indicators
el13drt 47:88e3e6c0452d 27 AnalogOut ledA(p18);//action LED
el13drt 47:88e3e6c0452d 28 DigitalOut ledP(p24);//Power LED
el13drt 13:a1b3a373c5a4 29
el13drt 35:9f55326c1b0a 30 //connections for joystick
el13drt 14:c2c969e1c6e8 31 InterruptIn joyButton(p17);//Interrupt for ISR
el13drt 35:9f55326c1b0a 32 AnalogIn xPot(p15);//left/right
el13drt 35:9f55326c1b0a 33 AnalogIn yPot(p16);//up/down
el13drt 13:a1b3a373c5a4 34
el13drt 35:9f55326c1b0a 35 //Globabl Variables /////////////////////////
el13drt 12:eedda6554615 36
el13drt 35:9f55326c1b0a 37 //sound FX toggle
el13drt 17:242ccf6a8442 38 int FX = 0;
el13drt 17:242ccf6a8442 39
el13drt 35:9f55326c1b0a 40 //previous Direction
el13drt 40:56ab6d368e9b 41 //stops continuous scrolling on some features
el13drt 38:2006c99bb1fc 42 int preDirection;
el13drt 34:9dc844bdc776 43
el13drt 35:9f55326c1b0a 44 //timer flags to check state of the buttons
el13drt 15:ff3eb0091453 45 int buttonFlagA = 0;
el13drt 15:ff3eb0091453 46 int buttonFlagB = 0;
el13drt 15:ff3eb0091453 47
el13drt 35:9f55326c1b0a 48 //flag for joystick reading
el13drt 14:c2c969e1c6e8 49 int printFlag = 0;
el13drt 14:c2c969e1c6e8 50
el13drt 35:9f55326c1b0a 51 //boundary conditions
el13drt 12:eedda6554615 52 int cells [84][48];
el13drt 12:eedda6554615 53
el13drt 35:9f55326c1b0a 54 //real time score
el13drt 12:eedda6554615 55 int score = 0;
el13drt 12:eedda6554615 56
el13drt 35:9f55326c1b0a 57 //stored high score variables
el13drt 35:9f55326c1b0a 58 int highScore1;
el13drt 35:9f55326c1b0a 59 int highScore2;
el13drt 35:9f55326c1b0a 60 int highScore3;
el13drt 21:1fbbd8ebb3d9 61
el13drt 35:9f55326c1b0a 62 //global char arrays to store initials/score
el13drt 34:9dc844bdc776 63 char player1initials[14] = {"1.AAA.....00"};
el13drt 34:9dc844bdc776 64 char player2initials[14] = {"2.BBB.....00"};
el13drt 34:9dc844bdc776 65 char player3initials[14] = {"3.CCC.....00"};
el13drt 25:70048c7e02c7 66
el13drt 35:9f55326c1b0a 67 //difficulty variable - hazards fall at 2 pixels per refresh
el13drt 12:eedda6554615 68 int fall = 2;
el13drt 12:eedda6554615 69
el13drt 35:9f55326c1b0a 70 //global variables for movement (pixelNinja)
el13drt 12:eedda6554615 71 int a1 = 22;
el13drt 12:eedda6554615 72 int a2 = 24;
el13drt 12:eedda6554615 73 int a3 = 23;
el13drt 12:eedda6554615 74 int a4 = 25;
el13drt 12:eedda6554615 75 int a5 = 20;
el13drt 12:eedda6554615 76 int a6 = 26;
el13drt 12:eedda6554615 77 int a7 = 19;
el13drt 12:eedda6554615 78 int a8 = 21;
el13drt 12:eedda6554615 79
el13drt 35:9f55326c1b0a 80 //global variable for hazard X co-ordinates
el13drt 12:eedda6554615 81 int randX1;
el13drt 12:eedda6554615 82 int randX2;
el13drt 12:eedda6554615 83 int randX3;
el13drt 12:eedda6554615 84 int randX4;
el13drt 12:eedda6554615 85 int randX5;
el13drt 12:eedda6554615 86 int randX6;
el13drt 12:eedda6554615 87
el13drt 35:9f55326c1b0a 88 //global variable for hazard Y co-ordinates
el13drt 52:bb2acf0e248a 89 int randY1 = 1;
el13drt 52:bb2acf0e248a 90 int randY2 = 1;
el13drt 52:bb2acf0e248a 91 int randY3 = 1;
el13drt 52:bb2acf0e248a 92 int randY4 = 1;
el13drt 52:bb2acf0e248a 93 int randY5 = 1;
el13drt 52:bb2acf0e248a 94 int randY6 = 1;
el13drt 12:eedda6554615 95
el13drt 35:9f55326c1b0a 96 //integers for changing struct ouput states
el13drt 39:8cb510bb4f0b 97 int state1 = 0;
el13drt 39:8cb510bb4f0b 98 int state2 = 0;
el13drt 39:8cb510bb4f0b 99 int state3 = 0;
el13drt 35:9f55326c1b0a 100
el13drt 35:9f55326c1b0a 101 //prototypes
el13drt 35:9f55326c1b0a 102 void calibrateJoystick();
el13drt 35:9f55326c1b0a 103 void updateJoystick();
el13drt 35:9f55326c1b0a 104 void timerExpiredA();
el13drt 35:9f55326c1b0a 105 void timerExpiredB();
el13drt 35:9f55326c1b0a 106 void actionButton();
el13drt 35:9f55326c1b0a 107 void randomise();
el13drt 35:9f55326c1b0a 108 void resetGame();
el13drt 35:9f55326c1b0a 109 void startrek();
el13drt 35:9f55326c1b0a 110 void refreshCursor1();
el13drt 35:9f55326c1b0a 111 void refreshCursor2();
el13drt 35:9f55326c1b0a 112 void refreshCursor3();
el13drt 35:9f55326c1b0a 113 void ninjaBoundaries();
el13drt 35:9f55326c1b0a 114 void hazardFall();
el13drt 51:df3bab1d6926 115 void newScore();
el13drt 35:9f55326c1b0a 116
el13drt 35:9f55326c1b0a 117 void mainMenu();
el13drt 35:9f55326c1b0a 118 void exitMenu();
el13drt 35:9f55326c1b0a 119 void optionsMenu();
el13drt 35:9f55326c1b0a 120 void game();
el13drt 35:9f55326c1b0a 121 void difficultyMenu();
el13drt 35:9f55326c1b0a 122 void soundFXMenu();
el13drt 35:9f55326c1b0a 123 void scores();
el13drt 35:9f55326c1b0a 124
el13drt 35:9f55326c1b0a 125 void drawNinja();
el13drt 35:9f55326c1b0a 126 void drawHazards();
el13drt 35:9f55326c1b0a 127 void drawWelcome();
el13drt 35:9f55326c1b0a 128 void drawBackground();
el13drt 35:9f55326c1b0a 129 void drawSoundFXMenu();
el13drt 35:9f55326c1b0a 130 void drawDifficultyMenu();
el13drt 35:9f55326c1b0a 131 void drawMainMenu();
el13drt 35:9f55326c1b0a 132 void drawOptionsMenu();
el13drt 35:9f55326c1b0a 133 void drawExitMenu();