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:
Sat May 02 02:14:58 2015 +0000
Revision:
57:bd8e064020fc
Parent:
55:bb4f6cc196c8
Child:
59:be7a31cb8cd1
1D;

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