A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
tower.h@33:bc730c9b4b1c, 2015-04-20 (annotated)
- Committer:
- el13drt
- Date:
- Mon Apr 20 23:46:32 2015 +0000
- Revision:
- 33:bc730c9b4b1c
- Parent:
- 32:f714d0993772
- Child:
- 34:9dc844bdc776
THIS ONE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el13drt | 13:a1b3a373c5a4 | 1 | |
el13drt | 13:a1b3a373c5a4 | 2 | // change this to alter tolerance of joystick direction |
el13drt | 13:a1b3a373c5a4 | 3 | #define DIRECTION_TOLERANCE 0.05 |
el13drt | 12:eedda6554615 | 4 | |
el13drt | 24:eb80956e2e95 | 5 | #include <string> |
el13drt | 24:eb80956e2e95 | 6 | |
el13drt | 24:eb80956e2e95 | 7 | //using namespace :: std; |
el13drt | 24:eb80956e2e95 | 8 | |
el13drt | 12:eedda6554615 | 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 | 15:ff3eb0091453 | 12 | // timers to check state of buttons |
el13drt | 17:242ccf6a8442 | 13 | Ticker timerA;//buttonA |
el13drt | 17:242ccf6a8442 | 14 | Ticker timerB;//buttonB |
el13drt | 15:ff3eb0091453 | 15 | |
el13drt | 13:a1b3a373c5a4 | 16 | // create buzzer objecct |
el13drt | 13:a1b3a373c5a4 | 17 | Beep buzzer(p21); |
el13drt | 13:a1b3a373c5a4 | 18 | |
el13drt | 13:a1b3a373c5a4 | 19 | // create local file system |
el13drt | 13:a1b3a373c5a4 | 20 | //LocalFileSytem local("local"); |
el13drt | 13:a1b3a373c5a4 | 21 | |
el13drt | 13:a1b3a373c5a4 | 22 | // navigation/action buttons |
el13drt | 13:a1b3a373c5a4 | 23 | DigitalIn buttonA(p19); |
el13drt | 13:a1b3a373c5a4 | 24 | DigitalIn buttonB(p20); |
el13drt | 13:a1b3a373c5a4 | 25 | |
el13drt | 13:a1b3a373c5a4 | 26 | // LED indicators |
el13drt | 13:a1b3a373c5a4 | 27 | AnalogOut ledR(p18);// RED LED |
el13drt | 13:a1b3a373c5a4 | 28 | DigitalOut ledY(p24);// YELLOW LED |
el13drt | 13:a1b3a373c5a4 | 29 | |
el13drt | 13:a1b3a373c5a4 | 30 | // connections for joystick |
el13drt | 14:c2c969e1c6e8 | 31 | InterruptIn joyButton(p17);//Interrupt for ISR |
el13drt | 13:a1b3a373c5a4 | 32 | AnalogIn xPot(p15); |
el13drt | 13:a1b3a373c5a4 | 33 | AnalogIn yPot(p16); |
el13drt | 13:a1b3a373c5a4 | 34 | |
el13drt | 12:eedda6554615 | 35 | // Globabl Variables ///////////////////////// |
el13drt | 12:eedda6554615 | 36 | |
el13drt | 17:242ccf6a8442 | 37 | // sound FX toggle |
el13drt | 17:242ccf6a8442 | 38 | int FX = 0; |
el13drt | 17:242ccf6a8442 | 39 | |
el13drt | 15:ff3eb0091453 | 40 | // timer flags to check state of buttons |
el13drt | 15:ff3eb0091453 | 41 | int buttonFlagA = 0; |
el13drt | 15:ff3eb0091453 | 42 | int buttonFlagB = 0; |
el13drt | 15:ff3eb0091453 | 43 | |
el13drt | 14:c2c969e1c6e8 | 44 | // flag for joystick reading |
el13drt | 14:c2c969e1c6e8 | 45 | int printFlag = 0; |
el13drt | 14:c2c969e1c6e8 | 46 | |
el13drt | 12:eedda6554615 | 47 | // boundary conditions |
el13drt | 12:eedda6554615 | 48 | int cells [84][48]; |
el13drt | 12:eedda6554615 | 49 | |
el13drt | 25:70048c7e02c7 | 50 | // player's score (in game) |
el13drt | 12:eedda6554615 | 51 | int score = 0; |
el13drt | 12:eedda6554615 | 52 | |
el13drt | 25:70048c7e02c7 | 53 | //high score details |
el13drt | 33:bc730c9b4b1c | 54 | int highScore1 = 2; |
el13drt | 33:bc730c9b4b1c | 55 | int highScore2 = 1; |
el13drt | 23:548299d45a60 | 56 | int highScore3 = 0; |
el13drt | 21:1fbbd8ebb3d9 | 57 | |
el13drt | 25:70048c7e02c7 | 58 | //player initials |
el13drt | 30:a05628b65926 | 59 | char player1initials[14]; |
el13drt | 30:a05628b65926 | 60 | char player2initials[14]; |
el13drt | 30:a05628b65926 | 61 | char player3initials[14]; |
el13drt | 25:70048c7e02c7 | 62 | |
el13drt | 12:eedda6554615 | 63 | // difficulty - number of pixels hazards incrememnt by |
el13drt | 12:eedda6554615 | 64 | int fall = 2; |
el13drt | 12:eedda6554615 | 65 | |
el13drt | 12:eedda6554615 | 66 | // global variables for movement (pixelNinja) |
el13drt | 12:eedda6554615 | 67 | int a1 = 22; |
el13drt | 12:eedda6554615 | 68 | int a2 = 24; |
el13drt | 12:eedda6554615 | 69 | int a3 = 23; |
el13drt | 12:eedda6554615 | 70 | int a4 = 25; |
el13drt | 12:eedda6554615 | 71 | int a5 = 20; |
el13drt | 12:eedda6554615 | 72 | int a6 = 26; |
el13drt | 12:eedda6554615 | 73 | int a7 = 19; |
el13drt | 12:eedda6554615 | 74 | int a8 = 21; |
el13drt | 12:eedda6554615 | 75 | |
el13drt | 12:eedda6554615 | 76 | //global variable for random X co-ordinates |
el13drt | 12:eedda6554615 | 77 | int randX1; |
el13drt | 12:eedda6554615 | 78 | int randX2; |
el13drt | 12:eedda6554615 | 79 | int randX3; |
el13drt | 12:eedda6554615 | 80 | int randX4; |
el13drt | 12:eedda6554615 | 81 | int randX5; |
el13drt | 12:eedda6554615 | 82 | int randX6; |
el13drt | 12:eedda6554615 | 83 | |
el13drt | 12:eedda6554615 | 84 | // global variable for Y co-ordinates |
el13drt | 12:eedda6554615 | 85 | int randY1 = 0; |
el13drt | 12:eedda6554615 | 86 | int randY2 = 0; |
el13drt | 12:eedda6554615 | 87 | int randY3 = 0; |
el13drt | 12:eedda6554615 | 88 | int randY4 = 0; |
el13drt | 12:eedda6554615 | 89 | int randY5 = 0; |
el13drt | 12:eedda6554615 | 90 | int randY6 = 0; |
el13drt | 12:eedda6554615 | 91 | |
el13drt | 24:eb80956e2e95 | 92 | // struct for choosing initials |
el13drt | 24:eb80956e2e95 | 93 | struct State { |
el13drt | 25:70048c7e02c7 | 94 | char output1; |
el13drt | 25:70048c7e02c7 | 95 | char output2; |
el13drt | 25:70048c7e02c7 | 96 | char output3; |
el13drt | 24:eb80956e2e95 | 97 | int nextState[2]; |
el13drt | 24:eb80956e2e95 | 98 | }; |
el13drt | 24:eb80956e2e95 | 99 | typedef const struct State STYP; |
el13drt | 23:548299d45a60 | 100 | |
el13drt | 31:da1a4875c404 | 101 | int state1 = 0;//integer for changing state 1 |
el13drt | 31:da1a4875c404 | 102 | int state2 = 0;//integer for changing state 2 |
el13drt | 31:da1a4875c404 | 103 | int state3 = 0;//integer for changing state 3 |
el13drt | 23:548299d45a60 | 104 | |
el13drt | 23:548299d45a60 | 105 | // array for Alphabet |
el13drt | 31:da1a4875c404 | 106 | STYP fsm[27] = { |
el13drt | 24:eb80956e2e95 | 107 | |
el13drt | 24:eb80956e2e95 | 108 | //output//nextstate//previousstate// |
el13drt | 24:eb80956e2e95 | 109 | |
el13drt | 31:da1a4875c404 | 110 | {'A','A','A',{1,26}}, |
el13drt | 25:70048c7e02c7 | 111 | {'B','B','B',{2,0}}, |
el13drt | 25:70048c7e02c7 | 112 | {'C','C','C',{3,1}}, |
el13drt | 25:70048c7e02c7 | 113 | {'D','D','D',{4,2}}, |
el13drt | 25:70048c7e02c7 | 114 | {'E','E','E',{5,3}}, |
el13drt | 25:70048c7e02c7 | 115 | {'F','F','F',{6,4}}, |
el13drt | 25:70048c7e02c7 | 116 | {'G','G','G',{7,5}}, |
el13drt | 25:70048c7e02c7 | 117 | {'H','H','H',{8,6}}, |
el13drt | 25:70048c7e02c7 | 118 | {'I','I','I',{9,7}}, |
el13drt | 25:70048c7e02c7 | 119 | {'J','J','J',{10,8}}, |
el13drt | 25:70048c7e02c7 | 120 | {'K','K','K',{11,9}}, |
el13drt | 25:70048c7e02c7 | 121 | {'L','L','L',{12,10}}, |
el13drt | 25:70048c7e02c7 | 122 | {'M','M','M',{13,11}}, |
el13drt | 25:70048c7e02c7 | 123 | {'N','N','N',{14,12}}, |
el13drt | 25:70048c7e02c7 | 124 | {'O','O','O',{15,13}}, |
el13drt | 25:70048c7e02c7 | 125 | {'P','P','P',{16,14}}, |
el13drt | 25:70048c7e02c7 | 126 | {'Q','Q','Q',{17,15}}, |
el13drt | 25:70048c7e02c7 | 127 | {'R','R','R',{18,16}}, |
el13drt | 25:70048c7e02c7 | 128 | {'S','S','S',{19,17}}, |
el13drt | 25:70048c7e02c7 | 129 | {'T','T','T',{20,18}}, |
el13drt | 25:70048c7e02c7 | 130 | {'U','U','U',{21,19}}, |
el13drt | 25:70048c7e02c7 | 131 | {'V','V','V',{22,20}}, |
el13drt | 25:70048c7e02c7 | 132 | {'W','W','W',{23,21}}, |
el13drt | 25:70048c7e02c7 | 133 | {'X','X','X',{24,22}}, |
el13drt | 25:70048c7e02c7 | 134 | {'Y','Y','Y',{25,23}}, |
el13drt | 31:da1a4875c404 | 135 | {'Z','Z','Z',{26,24}}, |
el13drt | 31:da1a4875c404 | 136 | {'.','.','.',{0,25}}, |
el13drt | 23:548299d45a60 | 137 | }; |
el13drt | 23:548299d45a60 | 138 | |
el13drt | 13:a1b3a373c5a4 | 139 | // function prototypes |
el13drt | 13:a1b3a373c5a4 | 140 | void calibrateJoystick(); |
el13drt | 13:a1b3a373c5a4 | 141 | void updateJoystick(); |
el13drt | 13:a1b3a373c5a4 | 142 | |
el13drt | 13:a1b3a373c5a4 | 143 | // timer to regularly read the joystick |
el13drt | 13:a1b3a373c5a4 | 144 | Ticker pollJoystick; |
el13drt | 13:a1b3a373c5a4 | 145 | |
el13drt | 13:a1b3a373c5a4 | 146 | // serial for debug |
el13drt | 13:a1b3a373c5a4 | 147 | Serial serial(USBTX,USBRX); |
el13drt | 13:a1b3a373c5a4 | 148 | |
el13drt | 13:a1b3a373c5a4 | 149 | // create enumerated type (0,1,2,3 etc. for direction) |
el13drt | 13:a1b3a373c5a4 | 150 | // could be extended for diagonals etc. |
el13drt | 13:a1b3a373c5a4 | 151 | enum DirectionName { |
el13drt | 13:a1b3a373c5a4 | 152 | UP, |
el13drt | 13:a1b3a373c5a4 | 153 | DOWN, |
el13drt | 13:a1b3a373c5a4 | 154 | LEFT, |
el13drt | 13:a1b3a373c5a4 | 155 | RIGHT, |
el13drt | 13:a1b3a373c5a4 | 156 | CENTRE, |
el13drt | 13:a1b3a373c5a4 | 157 | UNKNOWN |
el13drt | 13:a1b3a373c5a4 | 158 | }; |
el13drt | 13:a1b3a373c5a4 | 159 | |
el13drt | 13:a1b3a373c5a4 | 160 | // struct for Joystick |
el13drt | 13:a1b3a373c5a4 | 161 | typedef struct JoyStick Joystick; |
el13drt | 13:a1b3a373c5a4 | 162 | struct JoyStick { |
el13drt | 13:a1b3a373c5a4 | 163 | float x; // current x value |
el13drt | 13:a1b3a373c5a4 | 164 | float x0; // 'centred' x value |
el13drt | 13:a1b3a373c5a4 | 165 | float y; // current y value |
el13drt | 13:a1b3a373c5a4 | 166 | float y0; // 'centred' y value |
el13drt | 13:a1b3a373c5a4 | 167 | int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed) |
el13drt | 13:a1b3a373c5a4 | 168 | DirectionName direction; // current direction |
el13drt | 13:a1b3a373c5a4 | 169 | }; |
el13drt | 13:a1b3a373c5a4 | 170 | |
el13drt | 13:a1b3a373c5a4 | 171 | // create struct variable |
el13drt | 13:a1b3a373c5a4 | 172 | Joystick joystick; |
el13drt | 22:e5bfe0e7c508 | 173 | |
el13drt | 22:e5bfe0e7c508 | 174 | // if buttonA set flag A |
el13drt | 15:ff3eb0091453 | 175 | void timerExpiredA() |
el13drt | 15:ff3eb0091453 | 176 | { |
el13drt | 15:ff3eb0091453 | 177 | if(buttonA == 1) { |
el13drt | 15:ff3eb0091453 | 178 | buttonFlagA = 1; |
el13drt | 15:ff3eb0091453 | 179 | serial.printf("flagA set\n"); |
el13drt | 15:ff3eb0091453 | 180 | } |
el13drt | 15:ff3eb0091453 | 181 | } |
el13drt | 15:ff3eb0091453 | 182 | |
el13drt | 22:e5bfe0e7c508 | 183 | // if buttonB set flag B |
el13drt | 15:ff3eb0091453 | 184 | void timerExpiredB() |
el13drt | 15:ff3eb0091453 | 185 | { |
el13drt | 15:ff3eb0091453 | 186 | if(buttonB == 1) { |
el13drt | 15:ff3eb0091453 | 187 | buttonFlagB = 1; |
el13drt | 15:ff3eb0091453 | 188 | serial.printf("flagB set\n"); |
el13drt | 15:ff3eb0091453 | 189 | } |
el13drt | 15:ff3eb0091453 | 190 | } |
el13drt | 13:a1b3a373c5a4 | 191 | |
el13drt | 13:a1b3a373c5a4 | 192 | // set seed/randomise initial co-Ordinates |
el13drt | 13:a1b3a373c5a4 | 193 | void randomise() |
el13drt | 13:a1b3a373c5a4 | 194 | { |
el13drt | 13:a1b3a373c5a4 | 195 | srand (time(NULL));//initial seed for randomisation |
el13drt | 13:a1b3a373c5a4 | 196 | |
el13drt | 13:a1b3a373c5a4 | 197 | // initial random x co-ordinates |
el13drt | 13:a1b3a373c5a4 | 198 | // for falling hazards |
el13drt | 13:a1b3a373c5a4 | 199 | // (values between 3 and 76) |
el13drt | 13:a1b3a373c5a4 | 200 | randX1 = rand() % 74 + 5; |
el13drt | 13:a1b3a373c5a4 | 201 | randX2 = rand() % 74 + 5; |
el13drt | 13:a1b3a373c5a4 | 202 | randX3 = rand() % 74 + 5; |
el13drt | 13:a1b3a373c5a4 | 203 | randX4 = rand() % 74 + 5; |
el13drt | 13:a1b3a373c5a4 | 204 | randX5 = rand() % 74 + 5; |
el13drt | 13:a1b3a373c5a4 | 205 | randX6 = rand() % 74 + 5; |
el13drt | 13:a1b3a373c5a4 | 206 | } |
el13drt | 13:a1b3a373c5a4 | 207 | |
el13drt | 12:eedda6554615 | 208 | // static background |
el13drt | 12:eedda6554615 | 209 | void backGround() |
el13drt | 12:eedda6554615 | 210 | { |
el13drt | 12:eedda6554615 | 211 | // x, y, w, h, fill - draw ground |
el13drt | 12:eedda6554615 | 212 | lcd.drawRect(0,47,84,0,1); |
el13drt | 12:eedda6554615 | 213 | |
el13drt | 12:eedda6554615 | 214 | // x, y, w, h, fill - draw left wall |
el13drt | 12:eedda6554615 | 215 | lcd.drawRect(2,0,0,47,1); |
el13drt | 12:eedda6554615 | 216 | // left wall - brick line 1 |
el13drt | 12:eedda6554615 | 217 | for(int x=0; x<47; x+=4) |
el13drt | 12:eedda6554615 | 218 | lcd.drawLine(1,1,1,48,2); |
el13drt | 12:eedda6554615 | 219 | // left wall - brick line 2 |
el13drt | 12:eedda6554615 | 220 | for(int x=0; x<47; x+=4) |
el13drt | 12:eedda6554615 | 221 | lcd.drawLine(0,0,0,48,2); |
el13drt | 12:eedda6554615 | 222 | |
el13drt | 12:eedda6554615 | 223 | // x, y, w, h, fill - draw right wall |
el13drt | 12:eedda6554615 | 224 | lcd.drawRect(81,0,0,47,1); |
el13drt | 12:eedda6554615 | 225 | // right wall - brick line 1 |
el13drt | 12:eedda6554615 | 226 | for(int x=0; x<WIDTH; x+=4) |
el13drt | 12:eedda6554615 | 227 | lcd.drawLine(82,0,82,48,2); |
el13drt | 12:eedda6554615 | 228 | // right wall - brick line 2 |
el13drt | 12:eedda6554615 | 229 | for(int x=0; x<WIDTH; x+=4) |
el13drt | 12:eedda6554615 | 230 | lcd.drawLine(83,1,83,48,2); |
el13drt | 12:eedda6554615 | 231 | |
el13drt | 12:eedda6554615 | 232 | lcd.refresh(); |
el13drt | 12:eedda6554615 | 233 | } |
el13drt | 12:eedda6554615 | 234 | |
el13drt | 12:eedda6554615 | 235 | //intro screen |
el13drt | 12:eedda6554615 | 236 | void welcome() |
el13drt | 12:eedda6554615 | 237 | { |
el13drt | 12:eedda6554615 | 238 | //bottom border |
el13drt | 12:eedda6554615 | 239 | lcd.drawRect(0,44,84,2,1); |
el13drt | 12:eedda6554615 | 240 | |
el13drt | 12:eedda6554615 | 241 | //top border |
el13drt | 12:eedda6554615 | 242 | lcd.drawRect(0,1,84,2,1); |
el13drt | 12:eedda6554615 | 243 | |
el13drt | 12:eedda6554615 | 244 | //print initials 'DRT' |
el13drt | 12:eedda6554615 | 245 | lcd.printChar('D',30,14); |
el13drt | 12:eedda6554615 | 246 | wait(0.6); |
el13drt | 12:eedda6554615 | 247 | lcd.printChar('R',37,14); |
el13drt | 12:eedda6554615 | 248 | wait(0.6); |
el13drt | 12:eedda6554615 | 249 | lcd.printChar('T',44,14); |
el13drt | 12:eedda6554615 | 250 | wait(0.6); |
el13drt | 12:eedda6554615 | 251 | |
el13drt | 12:eedda6554615 | 252 | //print 'presents...' |
el13drt | 12:eedda6554615 | 253 | lcd.printString("presents...",8,21); |
el13drt | 12:eedda6554615 | 254 | wait(1.0); |
el13drt | 12:eedda6554615 | 255 | |
el13drt | 12:eedda6554615 | 256 | //dramatic flashing |
el13drt | 13:a1b3a373c5a4 | 257 | buzzer.beep(5000,0.3); |
el13drt | 12:eedda6554615 | 258 | lcd.inverseMode(); |
el13drt | 12:eedda6554615 | 259 | wait(0.2); |
el13drt | 12:eedda6554615 | 260 | lcd.normalMode(); |
el13drt | 12:eedda6554615 | 261 | wait(0.2); |
el13drt | 13:a1b3a373c5a4 | 262 | buzzer.beep(5000,0.3); |
el13drt | 12:eedda6554615 | 263 | lcd.inverseMode(); |
el13drt | 12:eedda6554615 | 264 | wait(0.2); |
el13drt | 12:eedda6554615 | 265 | lcd.normalMode(); |
el13drt | 12:eedda6554615 | 266 | wait(1.0); |
el13drt | 12:eedda6554615 | 267 | |
el13drt | 12:eedda6554615 | 268 | //more dramatic flashing |
el13drt | 13:a1b3a373c5a4 | 269 | buzzer.beep(5000,0.3); |
el13drt | 12:eedda6554615 | 270 | lcd.inverseMode(); |
el13drt | 12:eedda6554615 | 271 | wait(0.2); |
el13drt | 12:eedda6554615 | 272 | lcd.normalMode(); |
el13drt | 12:eedda6554615 | 273 | wait(0.2); |
el13drt | 13:a1b3a373c5a4 | 274 | buzzer.beep(5000,0.3); |
el13drt | 12:eedda6554615 | 275 | lcd.inverseMode(); |
el13drt | 12:eedda6554615 | 276 | wait(0.2); |
el13drt | 12:eedda6554615 | 277 | lcd.normalMode(); |
el13drt | 12:eedda6554615 | 278 | wait(0.6); |
el13drt | 12:eedda6554615 | 279 | } |
el13drt | 12:eedda6554615 | 280 | |
el13drt | 12:eedda6554615 | 281 | //pixel ninja character |
el13drt | 12:eedda6554615 | 282 | void pixelNinja() |
el13drt | 12:eedda6554615 | 283 | { |
el13drt | 12:eedda6554615 | 284 | //x, y, w, h, fill - left leg |
el13drt | 12:eedda6554615 | 285 | lcd.drawRect(a1,39,0,7,1); |
el13drt | 12:eedda6554615 | 286 | //right leg |
el13drt | 12:eedda6554615 | 287 | lcd.drawRect(a2,39,0,7,1); |
el13drt | 12:eedda6554615 | 288 | //centre stick |
el13drt | 12:eedda6554615 | 289 | lcd.drawRect(a3,37,0,7,1); |
el13drt | 12:eedda6554615 | 290 | //back of the head |
el13drt | 12:eedda6554615 | 291 | lcd.drawRect(a1,33,0,4,1); |
el13drt | 12:eedda6554615 | 292 | //top of the head |
el13drt | 12:eedda6554615 | 293 | lcd.drawRect(a1,33,4,0,1); |
el13drt | 12:eedda6554615 | 294 | //jaw |
el13drt | 12:eedda6554615 | 295 | lcd.drawRect(a2,38,2,0,1); |
el13drt | 12:eedda6554615 | 296 | //right shoulder |
el13drt | 12:eedda6554615 | 297 | lcd.drawRect(a4,40,1,0,1); |
el13drt | 12:eedda6554615 | 298 | //left shoulder |
el13drt | 12:eedda6554615 | 299 | lcd.drawRect(a5,40,1,0,1); |
el13drt | 12:eedda6554615 | 300 | //left arm |
el13drt | 12:eedda6554615 | 301 | lcd.drawRect(a5,41,0,1,1); |
el13drt | 12:eedda6554615 | 302 | //right arm |
el13drt | 12:eedda6554615 | 303 | lcd.drawRect(a6,41,0,1,1); |
el13drt | 12:eedda6554615 | 304 | //right eye |
el13drt | 12:eedda6554615 | 305 | lcd.drawRect(a6,35,0,0,1); |
el13drt | 12:eedda6554615 | 306 | //mouth piece |
el13drt | 12:eedda6554615 | 307 | lcd.drawRect(a6,37,0,0,1); |
el13drt | 12:eedda6554615 | 308 | //left eye |
el13drt | 12:eedda6554615 | 309 | lcd.drawRect(a2,35,0,0,1); |
el13drt | 12:eedda6554615 | 310 | //sword handle |
el13drt | 12:eedda6554615 | 311 | lcd.drawRect(a7,36,0,0,1); |
el13drt | 12:eedda6554615 | 312 | lcd.drawRect(a5,37,0,0,1); |
el13drt | 12:eedda6554615 | 313 | lcd.drawRect(a8,38,0,0,1); |
el13drt | 12:eedda6554615 | 314 | } |
el13drt | 12:eedda6554615 | 315 | |
el13drt | 12:eedda6554615 | 316 | // stops ninja going through walls |
el13drt | 12:eedda6554615 | 317 | void ninjaBoundaries() |
el13drt | 12:eedda6554615 | 318 | { |
el13drt | 12:eedda6554615 | 319 | if(a6 > 79 ) |
el13drt | 12:eedda6554615 | 320 | a6 = 79; |
el13drt | 12:eedda6554615 | 321 | if(a4 > 78) |
el13drt | 12:eedda6554615 | 322 | a4 = 78; |
el13drt | 12:eedda6554615 | 323 | if(a2 > 77) |
el13drt | 12:eedda6554615 | 324 | a2 = 77; |
el13drt | 12:eedda6554615 | 325 | if(a3 > 76) |
el13drt | 12:eedda6554615 | 326 | a3 = 76; |
el13drt | 12:eedda6554615 | 327 | if(a1 > 75) |
el13drt | 12:eedda6554615 | 328 | a1 = 75; |
el13drt | 12:eedda6554615 | 329 | if(a8 > 74) |
el13drt | 12:eedda6554615 | 330 | a8 = 74; |
el13drt | 12:eedda6554615 | 331 | if(a5 > 73) |
el13drt | 12:eedda6554615 | 332 | a5 = 73; |
el13drt | 12:eedda6554615 | 333 | if(a7 > 72) |
el13drt | 12:eedda6554615 | 334 | a7 = 72; |
el13drt | 12:eedda6554615 | 335 | |
el13drt | 12:eedda6554615 | 336 | if(a6 < 11 ) |
el13drt | 12:eedda6554615 | 337 | a6 = 11; |
el13drt | 12:eedda6554615 | 338 | if(a4 < 10) |
el13drt | 12:eedda6554615 | 339 | a4 = 10; |
el13drt | 12:eedda6554615 | 340 | if(a2 < 9) |
el13drt | 12:eedda6554615 | 341 | a2 = 9; |
el13drt | 12:eedda6554615 | 342 | if(a3 < 8) |
el13drt | 12:eedda6554615 | 343 | a3 = 8; |
el13drt | 12:eedda6554615 | 344 | if(a1 < 7) |
el13drt | 12:eedda6554615 | 345 | a1 = 7; |
el13drt | 12:eedda6554615 | 346 | if(a8 < 6) |
el13drt | 12:eedda6554615 | 347 | a8 = 6; |
el13drt | 12:eedda6554615 | 348 | if(a5 < 5) |
el13drt | 12:eedda6554615 | 349 | a5 = 5; |
el13drt | 12:eedda6554615 | 350 | if(a7 < 4) |
el13drt | 12:eedda6554615 | 351 | a7 = 4; |
el13drt | 12:eedda6554615 | 352 | } |
el13drt | 12:eedda6554615 | 353 | |
el13drt | 12:eedda6554615 | 354 | // resets back to initial values |
el13drt | 12:eedda6554615 | 355 | void resetGame() |
el13drt | 22:e5bfe0e7c508 | 356 | { |
el13drt | 12:eedda6554615 | 357 | score = 0; |
el13drt | 12:eedda6554615 | 358 | |
el13drt | 12:eedda6554615 | 359 | a1 = 22; |
el13drt | 12:eedda6554615 | 360 | a2 = 24; |
el13drt | 12:eedda6554615 | 361 | a3 = 23; |
el13drt | 12:eedda6554615 | 362 | a4 = 25; |
el13drt | 12:eedda6554615 | 363 | a5 = 20; |
el13drt | 12:eedda6554615 | 364 | a6 = 26; |
el13drt | 12:eedda6554615 | 365 | a7 = 19; |
el13drt | 12:eedda6554615 | 366 | a8 = 21; |
el13drt | 12:eedda6554615 | 367 | |
el13drt | 12:eedda6554615 | 368 | // in this case the X values are given a |
el13drt | 12:eedda6554615 | 369 | // new random variable each time the player |
el13drt | 12:eedda6554615 | 370 | // dies or exits and starts a new game |
el13drt | 12:eedda6554615 | 371 | randX1 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 372 | randX2 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 373 | randX3 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 374 | randX4 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 375 | randX5 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 376 | randX6 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 377 | |
el13drt | 12:eedda6554615 | 378 | randY1 = 0; |
el13drt | 12:eedda6554615 | 379 | randY2 = 0; |
el13drt | 12:eedda6554615 | 380 | randY3 = 0; |
el13drt | 12:eedda6554615 | 381 | randY4 = 0; |
el13drt | 12:eedda6554615 | 382 | randY5 = 0; |
el13drt | 12:eedda6554615 | 383 | randY6 = 0; |
el13drt | 12:eedda6554615 | 384 | lcd.clear(); |
el13drt | 12:eedda6554615 | 385 | } |
el13drt | 12:eedda6554615 | 386 | |
el13drt | 12:eedda6554615 | 387 | // draws falling hazards |
el13drt | 12:eedda6554615 | 388 | void hazards() |
el13drt | 12:eedda6554615 | 389 | { |
el13drt | 12:eedda6554615 | 390 | // X, Y, radius, fill |
el13drt | 12:eedda6554615 | 391 | lcd.drawCircle(randX1,randY1,2,1); |
el13drt | 12:eedda6554615 | 392 | lcd.drawCircle(randX2,randY2,2,1); |
el13drt | 12:eedda6554615 | 393 | lcd.drawCircle(randX3,randY3,2,1); |
el13drt | 12:eedda6554615 | 394 | lcd.drawCircle(randX4,randY4,2,1); |
el13drt | 12:eedda6554615 | 395 | lcd.drawCircle(randX5,randY5,2,1); |
el13drt | 12:eedda6554615 | 396 | lcd.drawCircle(randX6,randY6,2,1); |
el13drt | 12:eedda6554615 | 397 | |
el13drt | 12:eedda6554615 | 398 | lcd.refresh(); |
el13drt | 12:eedda6554615 | 399 | } |
el13drt | 12:eedda6554615 | 400 | |
el13drt | 12:eedda6554615 | 401 | // makes hazards fall - randomises X axis co-ordinates |
el13drt | 12:eedda6554615 | 402 | void hazardFall() |
el13drt | 12:eedda6554615 | 403 | { |
el13drt | 12:eedda6554615 | 404 | // increments randY1 variables |
el13drt | 12:eedda6554615 | 405 | // appearing to make them fall |
el13drt | 12:eedda6554615 | 406 | randY1 = randY1 += fall; |
el13drt | 12:eedda6554615 | 407 | randY2 = randY2 += fall; |
el13drt | 12:eedda6554615 | 408 | randY3 = randY3 += fall; |
el13drt | 12:eedda6554615 | 409 | randY4 = randY4 += fall; |
el13drt | 12:eedda6554615 | 410 | randY5 = randY5 += fall; |
el13drt | 12:eedda6554615 | 411 | randY6 = randY6 += fall; |
el13drt | 12:eedda6554615 | 412 | |
el13drt | 12:eedda6554615 | 413 | // loops the objects once they 'hit the floor' |
el13drt | 12:eedda6554615 | 414 | // this imitates a new set of objects falling |
el13drt | 12:eedda6554615 | 415 | |
el13drt | 12:eedda6554615 | 416 | if (randY1>=48) |
el13drt | 12:eedda6554615 | 417 | randY1=0; |
el13drt | 12:eedda6554615 | 418 | |
el13drt | 12:eedda6554615 | 419 | if (randY2>=48) |
el13drt | 12:eedda6554615 | 420 | randY2=0; |
el13drt | 12:eedda6554615 | 421 | |
el13drt | 12:eedda6554615 | 422 | if (randY3>=48) |
el13drt | 12:eedda6554615 | 423 | randY3=0; |
el13drt | 12:eedda6554615 | 424 | |
el13drt | 12:eedda6554615 | 425 | if (randY4>=48) |
el13drt | 12:eedda6554615 | 426 | randY4=0; |
el13drt | 12:eedda6554615 | 427 | |
el13drt | 12:eedda6554615 | 428 | if (randY5>=48) |
el13drt | 12:eedda6554615 | 429 | randY5=0; |
el13drt | 12:eedda6554615 | 430 | |
el13drt | 12:eedda6554615 | 431 | // each time the objects loop, a new pseudo random value |
el13drt | 12:eedda6554615 | 432 | // is assigned to the global variables (randX) to |
el13drt | 12:eedda6554615 | 433 | // randomise their positions |
el13drt | 12:eedda6554615 | 434 | |
el13drt | 12:eedda6554615 | 435 | if (randY6>=48) { |
el13drt | 12:eedda6554615 | 436 | randY6=0; |
el13drt | 12:eedda6554615 | 437 | |
el13drt | 12:eedda6554615 | 438 | score = score++;//increment score by 1 after each wave of hazards |
el13drt | 12:eedda6554615 | 439 | |
el13drt | 12:eedda6554615 | 440 | randX1 = rand() % 74 + 5;// psuedo random number |
el13drt | 12:eedda6554615 | 441 | randX2 = rand() % 74 + 5;// between 5 and 74 |
el13drt | 12:eedda6554615 | 442 | randX3 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 443 | randX4 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 444 | randX5 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 445 | randX6 = rand() % 74 + 5; |
el13drt | 12:eedda6554615 | 446 | } |
el13drt | 12:eedda6554615 | 447 | } |
el13drt | 12:eedda6554615 | 448 | |
el13drt | 12:eedda6554615 | 449 | // clears old pixels and keeps set pixels |
el13drt | 12:eedda6554615 | 450 | void startrek() |
el13drt | 12:eedda6554615 | 451 | { |
el13drt | 12:eedda6554615 | 452 | for (int i=3; i<81; i++)// loops through rows |
el13drt | 12:eedda6554615 | 453 | for (int j=0; j<47; j++) |
el13drt | 12:eedda6554615 | 454 | if (cells[i][j]) {// if there's a pixel then keep it |
el13drt | 12:eedda6554615 | 455 | lcd.setPixel(i,j); |
el13drt | 12:eedda6554615 | 456 | } else { |
el13drt | 12:eedda6554615 | 457 | lcd.clearPixel(i,j);// else remove the old ones |
el13drt | 12:eedda6554615 | 458 | } |
el13drt | 12:eedda6554615 | 459 | lcd.refresh(); |
el13drt | 12:eedda6554615 | 460 | } |
el13drt | 12:eedda6554615 | 461 | |
el13drt | 12:eedda6554615 | 462 | // clears old pixels and keeps set pixels |
el13drt | 12:eedda6554615 | 463 | void refreshCursor1() |
el13drt | 12:eedda6554615 | 464 | { |
el13drt | 12:eedda6554615 | 465 | for (int i=70; i<80; i++)// loops through rows |
el13drt | 12:eedda6554615 | 466 | for (int j=17; j<25; j++) |
el13drt | 12:eedda6554615 | 467 | if (cells[i][j]) {// if there's a pixel then keep it |
el13drt | 12:eedda6554615 | 468 | lcd.setPixel(i,j); |
el13drt | 12:eedda6554615 | 469 | } else { |
el13drt | 12:eedda6554615 | 470 | lcd.clearPixel(i,j);// else remove the old ones |
el13drt | 12:eedda6554615 | 471 | } |
el13drt | 12:eedda6554615 | 472 | lcd.refresh(); |
el13drt | 12:eedda6554615 | 473 | } |
el13drt | 12:eedda6554615 | 474 | |
el13drt | 12:eedda6554615 | 475 | // clears old pixels and keeps set pixels |
el13drt | 12:eedda6554615 | 476 | void refreshCursor2() |
el13drt | 12:eedda6554615 | 477 | { |
el13drt | 12:eedda6554615 | 478 | for (int i=70; i<80; i++)// loops through rows |
el13drt | 12:eedda6554615 | 479 | for (int j=25; j<32; j++) |
el13drt | 12:eedda6554615 | 480 | if (cells[i][j]) {// if there's a pixel then keep it |
el13drt | 12:eedda6554615 | 481 | lcd.setPixel(i,j); |
el13drt | 12:eedda6554615 | 482 | } else { |
el13drt | 12:eedda6554615 | 483 | lcd.clearPixel(i,j);// else remove the old ones |
el13drt | 12:eedda6554615 | 484 | } |
el13drt | 12:eedda6554615 | 485 | lcd.refresh(); |
el13drt | 12:eedda6554615 | 486 | } |
el13drt | 12:eedda6554615 | 487 | |
el13drt | 12:eedda6554615 | 488 | // clears old pixels and keeps set pixels |
el13drt | 12:eedda6554615 | 489 | void refreshCursor3() |
el13drt | 12:eedda6554615 | 490 | { |
el13drt | 12:eedda6554615 | 491 | for (int i=70; i<80; i++)// loops through rows |
el13drt | 12:eedda6554615 | 492 | for (int j=32; j<40; j++) |
el13drt | 12:eedda6554615 | 493 | if (cells[i][j]) {// if there's a pixel then keep it |
el13drt | 12:eedda6554615 | 494 | lcd.setPixel(i,j); |
el13drt | 12:eedda6554615 | 495 | } else { |
el13drt | 12:eedda6554615 | 496 | lcd.clearPixel(i,j);// else remove the old ones |
el13drt | 12:eedda6554615 | 497 | } |
el13drt | 12:eedda6554615 | 498 | lcd.refresh(); |
el13drt | 12:eedda6554615 | 499 | } |
el13drt | 12:eedda6554615 | 500 | |
el13drt | 17:242ccf6a8442 | 501 | // beep/light when buttons are closed |
el13drt | 17:242ccf6a8442 | 502 | void actionButtons() |
el13drt | 17:242ccf6a8442 | 503 | { |
el13drt | 17:242ccf6a8442 | 504 | if((FX == 0)&&(buttonA||buttonB)) { |
el13drt | 17:242ccf6a8442 | 505 | ledY = 1; |
el13drt | 17:242ccf6a8442 | 506 | buzzer.beep(1500,0.3); |
el13drt | 17:242ccf6a8442 | 507 | } |
el13drt | 17:242ccf6a8442 | 508 | if (buttonA || buttonB) { |
el13drt | 17:242ccf6a8442 | 509 | ledY = 1; |
el13drt | 17:242ccf6a8442 | 510 | } else { |
el13drt | 17:242ccf6a8442 | 511 | ledY = 0; |
el13drt | 17:242ccf6a8442 | 512 | } |
el13drt | 17:242ccf6a8442 | 513 | } |
el13drt | 17:242ccf6a8442 | 514 | |
el13drt | 12:eedda6554615 | 515 | // presents main menu options |
el13drt | 12:eedda6554615 | 516 | void mainMenu(int& mainOption) |
el13drt | 12:eedda6554615 | 517 | { |
el13drt | 17:242ccf6a8442 | 518 | actionButtons();//set audible/light for button |
el13drt | 12:eedda6554615 | 519 | |
el13drt | 12:eedda6554615 | 520 | // joystick selection |
el13drt | 14:c2c969e1c6e8 | 521 | if (printFlag) {//if flag set, clear flag and print joystick values to serial port |
el13drt | 12:eedda6554615 | 522 | printFlag = 0; |
el13drt | 12:eedda6554615 | 523 | |
el13drt | 12:eedda6554615 | 524 | // option up |
el13drt | 12:eedda6554615 | 525 | if (joystick.direction == UP) { |
el13drt | 12:eedda6554615 | 526 | serial.printf(" UP\n"); |
el13drt | 12:eedda6554615 | 527 | mainOption = mainOption--; |
el13drt | 12:eedda6554615 | 528 | if (mainOption < 0)mainOption = 0; |
el13drt | 12:eedda6554615 | 529 | } |
el13drt | 12:eedda6554615 | 530 | // option down |
el13drt | 12:eedda6554615 | 531 | if (joystick.direction == DOWN) { |
el13drt | 12:eedda6554615 | 532 | serial.printf(" DOWN\n"); |
el13drt | 12:eedda6554615 | 533 | mainOption = mainOption++; |
el13drt | 12:eedda6554615 | 534 | if (mainOption > 2)mainOption = 2; |
el13drt | 12:eedda6554615 | 535 | } |
el13drt | 12:eedda6554615 | 536 | // Centre / Unknown orientation |
el13drt | 12:eedda6554615 | 537 | if (joystick.direction == CENTRE) |
el13drt | 12:eedda6554615 | 538 | serial.printf(" CENTRE\n"); |
el13drt | 12:eedda6554615 | 539 | if (joystick.direction == UNKNOWN) |
el13drt | 12:eedda6554615 | 540 | serial.printf(" Unsupported direction\n"); |
el13drt | 12:eedda6554615 | 541 | |
el13drt | 12:eedda6554615 | 542 | // 'Play Game' option 1 |
el13drt | 12:eedda6554615 | 543 | if (mainOption == 0) { |
el13drt | 12:eedda6554615 | 544 | lcd.printString("Play Game",3,4); |
el13drt | 12:eedda6554615 | 545 | } |
el13drt | 12:eedda6554615 | 546 | // 'High Scores' option 2 |
el13drt | 12:eedda6554615 | 547 | if (mainOption == 1) { |
el13drt | 12:eedda6554615 | 548 | lcd.printString(" Scores ",3,4); |
el13drt | 12:eedda6554615 | 549 | } |
el13drt | 12:eedda6554615 | 550 | // 'Options' option 3 |
el13drt | 12:eedda6554615 | 551 | if (mainOption == 2) { |
el13drt | 12:eedda6554615 | 552 | lcd.printString(" Options ",3,4); |
el13drt | 12:eedda6554615 | 553 | } |
el13drt | 12:eedda6554615 | 554 | } |
el13drt | 12:eedda6554615 | 555 | } |
el13drt | 12:eedda6554615 | 556 | |
el13drt | 12:eedda6554615 | 557 | // draws main menu |
el13drt | 12:eedda6554615 | 558 | void drawMainMenu() |
el13drt | 12:eedda6554615 | 559 | { |
el13drt | 12:eedda6554615 | 560 | //bottom border |
el13drt | 12:eedda6554615 | 561 | lcd.drawRect(0,47,84,0,1); |
el13drt | 12:eedda6554615 | 562 | //top border |
el13drt | 12:eedda6554615 | 563 | lcd.drawRect(0,0,84,2,1); |
el13drt | 12:eedda6554615 | 564 | |
el13drt | 12:eedda6554615 | 565 | //print 'Xtreme Tower' |
el13drt | 12:eedda6554615 | 566 | lcd.printString("Xtreme",4,25); |
el13drt | 12:eedda6554615 | 567 | lcd.printString("Tower",44,25); |
el13drt | 12:eedda6554615 | 568 | |
el13drt | 12:eedda6554615 | 569 | //title outline |
el13drt | 12:eedda6554615 | 570 | lcd.drawRect(3,6,77,10,0); |
el13drt | 12:eedda6554615 | 571 | |
el13drt | 12:eedda6554615 | 572 | ////castle //x, y, w, h, fill////////////////////// |
el13drt | 12:eedda6554615 | 573 | |
el13drt | 12:eedda6554615 | 574 | //castle main bulk |
el13drt | 12:eedda6554615 | 575 | lcd.drawRect(59,32,21,8,1); |
el13drt | 12:eedda6554615 | 576 | |
el13drt | 12:eedda6554615 | 577 | //left window bulk |
el13drt | 12:eedda6554615 | 578 | lcd.drawRect(59,22,2,10,1); |
el13drt | 12:eedda6554615 | 579 | //centre left window bulk |
el13drt | 12:eedda6554615 | 580 | lcd.drawRect(65,22,2,10,1); |
el13drt | 12:eedda6554615 | 581 | //centre right window bulk |
el13drt | 12:eedda6554615 | 582 | lcd.drawRect(72,22,2,10,1); |
el13drt | 12:eedda6554615 | 583 | //right window bulk |
el13drt | 12:eedda6554615 | 584 | lcd.drawRect(78,22,2,10,1); |
el13drt | 12:eedda6554615 | 585 | //central window bulk |
el13drt | 12:eedda6554615 | 586 | lcd.drawRect(68,25,3,7,1); |
el13drt | 12:eedda6554615 | 587 | |
el13drt | 12:eedda6554615 | 588 | //central window bulk |
el13drt | 12:eedda6554615 | 589 | lcd.drawRect(75,28,0,0,1); |
el13drt | 12:eedda6554615 | 590 | lcd.drawRect(77,28,0,0,1); |
el13drt | 12:eedda6554615 | 591 | lcd.drawRect(64,28,0,0,1); |
el13drt | 12:eedda6554615 | 592 | lcd.drawRect(62,28,0,0,1); |
el13drt | 12:eedda6554615 | 593 | |
el13drt | 12:eedda6554615 | 594 | //above left window bulk |
el13drt | 12:eedda6554615 | 595 | lcd.drawRect(62,25,3,2,1); |
el13drt | 12:eedda6554615 | 596 | //above right window bulk |
el13drt | 12:eedda6554615 | 597 | lcd.drawRect(75,25,2,2,1); |
el13drt | 12:eedda6554615 | 598 | |
el13drt | 12:eedda6554615 | 599 | //lower right line |
el13drt | 12:eedda6554615 | 600 | lcd.drawRect(71,42,9,0,1); |
el13drt | 12:eedda6554615 | 601 | //upper right line |
el13drt | 12:eedda6554615 | 602 | lcd.drawRect(70,41,10,0,1); |
el13drt | 12:eedda6554615 | 603 | |
el13drt | 12:eedda6554615 | 604 | //upper left line |
el13drt | 12:eedda6554615 | 605 | lcd.drawRect(59,41,10,0,1); |
el13drt | 12:eedda6554615 | 606 | //lower left line |
el13drt | 12:eedda6554615 | 607 | lcd.drawRect(59,42,9,0,1); |
el13drt | 12:eedda6554615 | 608 | |
el13drt | 12:eedda6554615 | 609 | //bottom left bulk |
el13drt | 12:eedda6554615 | 610 | lcd.drawRect(59,43,8,3,1); |
el13drt | 12:eedda6554615 | 611 | //bottom right bulk |
el13drt | 12:eedda6554615 | 612 | lcd.drawRect(72,43,8,3,1); |
el13drt | 12:eedda6554615 | 613 | |
el13drt | 12:eedda6554615 | 614 | //option arrows - lower |
el13drt | 12:eedda6554615 | 615 | lcd.drawRect(27,42,4,0,1); |
el13drt | 12:eedda6554615 | 616 | lcd.drawRect(28,43,2,0,1); |
el13drt | 12:eedda6554615 | 617 | lcd.drawRect(29,44,0,0,1); |
el13drt | 12:eedda6554615 | 618 | |
el13drt | 12:eedda6554615 | 619 | //option arrows - higher |
el13drt | 12:eedda6554615 | 620 | lcd.drawRect(27,29,4,0,1); |
el13drt | 12:eedda6554615 | 621 | lcd.drawRect(28,28,2,0,1); |
el13drt | 12:eedda6554615 | 622 | lcd.drawRect(29,27,0,0,1); |
el13drt | 12:eedda6554615 | 623 | } |
el13drt | 12:eedda6554615 | 624 | |
el13drt | 12:eedda6554615 | 625 | // presents exit menu options |
el13drt | 12:eedda6554615 | 626 | void exitMenu(int& exitOption) |
el13drt | 12:eedda6554615 | 627 | { |
el13drt | 17:242ccf6a8442 | 628 | actionButtons(); |
el13drt | 14:c2c969e1c6e8 | 629 | if (printFlag) {//if flag set, clear flag and print joystick values to serial port |
el13drt | 12:eedda6554615 | 630 | printFlag = 0; |
el13drt | 12:eedda6554615 | 631 | |
el13drt | 12:eedda6554615 | 632 | // check joystick direction |
el13drt | 12:eedda6554615 | 633 | if (joystick.direction == LEFT) { |
el13drt | 12:eedda6554615 | 634 | serial.printf(" LEFT\n"); |
el13drt | 12:eedda6554615 | 635 | exitOption--; |
el13drt | 12:eedda6554615 | 636 | if(exitOption < 0)exitOption = 0; |
el13drt | 12:eedda6554615 | 637 | } |
el13drt | 12:eedda6554615 | 638 | if (joystick.direction == RIGHT) { |
el13drt | 12:eedda6554615 | 639 | serial.printf(" RIGHT\n"); |
el13drt | 12:eedda6554615 | 640 | exitOption++; |
el13drt | 12:eedda6554615 | 641 | if(exitOption > 1)exitOption = 1; |
el13drt | 12:eedda6554615 | 642 | } |
el13drt | 12:eedda6554615 | 643 | if (joystick.direction == CENTRE) |
el13drt | 12:eedda6554615 | 644 | serial.printf(" CENTRE\n"); |
el13drt | 12:eedda6554615 | 645 | if (joystick.direction == UNKNOWN) |
el13drt | 12:eedda6554615 | 646 | serial.printf(" Unsupported direction\n"); |
el13drt | 12:eedda6554615 | 647 | } |
el13drt | 12:eedda6554615 | 648 | // draws option cursor |
el13drt | 12:eedda6554615 | 649 | if(exitOption == 0) { |
el13drt | 12:eedda6554615 | 650 | lcd.printString("YES",29,27); |
el13drt | 12:eedda6554615 | 651 | } |
el13drt | 12:eedda6554615 | 652 | if(exitOption == 1) { |
el13drt | 12:eedda6554615 | 653 | lcd.printString(" NO",29,27); |
el13drt | 12:eedda6554615 | 654 | } |
el13drt | 12:eedda6554615 | 655 | } |
el13drt | 12:eedda6554615 | 656 | |
el13drt | 12:eedda6554615 | 657 | // draws exit menu |
el13drt | 12:eedda6554615 | 658 | void drawExitMenu() |
el13drt | 12:eedda6554615 | 659 | { |
el13drt | 12:eedda6554615 | 660 | // set exit menu |
el13drt | 12:eedda6554615 | 661 | lcd.clear(); |
el13drt | 12:eedda6554615 | 662 | lcd.drawRect(8,6,70,30,0);//title outline |
el13drt | 12:eedda6554615 | 663 | lcd.printString("Exit Game?",10,25); |
el13drt | 12:eedda6554615 | 664 | backGround(); |
el13drt | 12:eedda6554615 | 665 | |
el13drt | 12:eedda6554615 | 666 | // option arrow - right |
el13drt | 12:eedda6554615 | 667 | lcd.drawRect(55,25,0,4,1); |
el13drt | 12:eedda6554615 | 668 | lcd.drawRect(56,26,0,2,1); |
el13drt | 12:eedda6554615 | 669 | lcd.drawRect(57,27,0,0,1); |
el13drt | 12:eedda6554615 | 670 | |
el13drt | 12:eedda6554615 | 671 | // option arrow - left |
el13drt | 12:eedda6554615 | 672 | lcd.drawRect(27,25,0,4,1); |
el13drt | 12:eedda6554615 | 673 | lcd.drawRect(26,26,0,2,1); |
el13drt | 12:eedda6554615 | 674 | lcd.drawRect(25,27,0,0,1); |
el13drt | 12:eedda6554615 | 675 | } |
el13drt | 12:eedda6554615 | 676 | |
el13drt | 12:eedda6554615 | 677 | // presents the options |
el13drt | 12:eedda6554615 | 678 | void optionsMenu(int& option) |
el13drt | 12:eedda6554615 | 679 | { |
el13drt | 12:eedda6554615 | 680 | // joystick selection |
el13drt | 12:eedda6554615 | 681 | if (printFlag) { //if flag set, clear flag and print joystick values to serial port |
el13drt | 12:eedda6554615 | 682 | printFlag = 0; |
el13drt | 12:eedda6554615 | 683 | |
el13drt | 12:eedda6554615 | 684 | // option up |
el13drt | 12:eedda6554615 | 685 | if (joystick.direction == UP) { |
el13drt | 12:eedda6554615 | 686 | serial.printf(" UP\n"); |
el13drt | 12:eedda6554615 | 687 | option = option--; |
el13drt | 12:eedda6554615 | 688 | if (option < 0)option = 0; |
el13drt | 12:eedda6554615 | 689 | } |
el13drt | 12:eedda6554615 | 690 | // option down |
el13drt | 12:eedda6554615 | 691 | if (joystick.direction == DOWN) { |
el13drt | 12:eedda6554615 | 692 | serial.printf(" DOWN\n"); |
el13drt | 12:eedda6554615 | 693 | option = option++; |
el13drt | 12:eedda6554615 | 694 | if (option > 1)option = 1; |
el13drt | 12:eedda6554615 | 695 | } |
el13drt | 12:eedda6554615 | 696 | // Centre / Unknown orientation |
el13drt | 12:eedda6554615 | 697 | if (joystick.direction == CENTRE) |
el13drt | 12:eedda6554615 | 698 | serial.printf(" CENTRE\n"); |
el13drt | 12:eedda6554615 | 699 | if (joystick.direction == UNKNOWN) |
el13drt | 12:eedda6554615 | 700 | serial.printf(" Unsupported direction\n"); |
el13drt | 12:eedda6554615 | 701 | |
el13drt | 12:eedda6554615 | 702 | // 'Difficulty' option 1 |
el13drt | 12:eedda6554615 | 703 | if (option == 0) { |
el13drt | 12:eedda6554615 | 704 | lcd.drawCircle(72,27,2,1); |
el13drt | 12:eedda6554615 | 705 | refreshCursor3(); |
el13drt | 12:eedda6554615 | 706 | } |
el13drt | 12:eedda6554615 | 707 | // 'Sound FX' option 2 |
el13drt | 12:eedda6554615 | 708 | if (option == 1) { |
el13drt | 12:eedda6554615 | 709 | lcd.drawCircle(72,35,2,1); |
el13drt | 12:eedda6554615 | 710 | refreshCursor2(); |
el13drt | 12:eedda6554615 | 711 | } |
el13drt | 12:eedda6554615 | 712 | } |
el13drt | 12:eedda6554615 | 713 | } |
el13drt | 12:eedda6554615 | 714 | |
el13drt | 12:eedda6554615 | 715 | // draws options menu |
el13drt | 12:eedda6554615 | 716 | void drawOptionsMenu() |
el13drt | 12:eedda6554615 | 717 | { |
el13drt | 12:eedda6554615 | 718 | lcd.clear();//clear screen |
el13drt | 12:eedda6554615 | 719 | backGround(); |
el13drt | 12:eedda6554615 | 720 | lcd.drawRect(3,6,77,10,0);//title outline |
el13drt | 12:eedda6554615 | 721 | lcd.drawRect(0,47,84,0,1);//bottom border |
el13drt | 12:eedda6554615 | 722 | lcd.drawRect(0,0,84,2,1);//top border |
el13drt | 12:eedda6554615 | 723 | lcd.printString("Options",20,7);//title |
el13drt | 12:eedda6554615 | 724 | lcd.printString("Difficulty",3,9); |
el13drt | 12:eedda6554615 | 725 | lcd.printString("Sound FX",3,10); |
el13drt | 12:eedda6554615 | 726 | } |
el13drt | 12:eedda6554615 | 727 | |
el13drt | 12:eedda6554615 | 728 | // present difficulty options |
el13drt | 12:eedda6554615 | 729 | void difficultyMenu(int& subOption) |
el13drt | 12:eedda6554615 | 730 | { |
el13drt | 17:242ccf6a8442 | 731 | actionButtons(); |
el13drt | 12:eedda6554615 | 732 | |
el13drt | 12:eedda6554615 | 733 | // joystick selection |
el13drt | 12:eedda6554615 | 734 | if (printFlag) {//if flag set, clear flag,print joystick values |
el13drt | 12:eedda6554615 | 735 | printFlag = 0; |
el13drt | 12:eedda6554615 | 736 | |
el13drt | 12:eedda6554615 | 737 | // option up |
el13drt | 12:eedda6554615 | 738 | if (joystick.direction == UP) { |
el13drt | 12:eedda6554615 | 739 | serial.printf(" UP\n"); |
el13drt | 12:eedda6554615 | 740 | subOption = subOption--; |
el13drt | 12:eedda6554615 | 741 | if (subOption < 0)subOption = 0; |
el13drt | 12:eedda6554615 | 742 | } |
el13drt | 12:eedda6554615 | 743 | // option down |
el13drt | 12:eedda6554615 | 744 | if (joystick.direction == DOWN) { |
el13drt | 12:eedda6554615 | 745 | serial.printf(" DOWN\n"); |
el13drt | 12:eedda6554615 | 746 | subOption = subOption++; |
el13drt | 12:eedda6554615 | 747 | if (subOption > 2)subOption = 2; |
el13drt | 12:eedda6554615 | 748 | } |
el13drt | 12:eedda6554615 | 749 | // Centre / Unknown orientation |
el13drt | 12:eedda6554615 | 750 | if (joystick.direction == CENTRE) |
el13drt | 12:eedda6554615 | 751 | serial.printf(" CENTRE\n"); |
el13drt | 12:eedda6554615 | 752 | if (joystick.direction == UNKNOWN) |
el13drt | 12:eedda6554615 | 753 | serial.printf(" Unsupported direction\n"); |
el13drt | 12:eedda6554615 | 754 | |
el13drt | 12:eedda6554615 | 755 | // 'Easy' option 1 |
el13drt | 12:eedda6554615 | 756 | if (subOption == 0) { |
el13drt | 12:eedda6554615 | 757 | lcd.drawCircle(72,19,2,1); |
el13drt | 12:eedda6554615 | 758 | refreshCursor2(); |
el13drt | 12:eedda6554615 | 759 | refreshCursor3(); |
el13drt | 18:c38e1966d870 | 760 | if(buttonFlagA) { //select easy |
el13drt | 18:c38e1966d870 | 761 | buttonFlagA = 0; |
el13drt | 12:eedda6554615 | 762 | fall = 1; |
el13drt | 12:eedda6554615 | 763 | } |
el13drt | 12:eedda6554615 | 764 | } |
el13drt | 12:eedda6554615 | 765 | // 'Normal' option 2 |
el13drt | 12:eedda6554615 | 766 | if (subOption == 1) { |
el13drt | 12:eedda6554615 | 767 | lcd.drawCircle(72,27,2,1); |
el13drt | 12:eedda6554615 | 768 | refreshCursor1(); |
el13drt | 12:eedda6554615 | 769 | refreshCursor3(); |
el13drt | 12:eedda6554615 | 770 | |
el13drt | 18:c38e1966d870 | 771 | if(buttonFlagA) { //select normal |
el13drt | 18:c38e1966d870 | 772 | buttonFlagA = 0; |
el13drt | 12:eedda6554615 | 773 | fall = 2; |
el13drt | 12:eedda6554615 | 774 | } |
el13drt | 12:eedda6554615 | 775 | } |
el13drt | 12:eedda6554615 | 776 | // 'Forget It' option 3 |
el13drt | 12:eedda6554615 | 777 | if (subOption == 2) { |
el13drt | 12:eedda6554615 | 778 | lcd.drawCircle(72,35,2,1); |
el13drt | 12:eedda6554615 | 779 | refreshCursor1(); |
el13drt | 12:eedda6554615 | 780 | refreshCursor2(); |
el13drt | 12:eedda6554615 | 781 | |
el13drt | 18:c38e1966d870 | 782 | if(buttonFlagA) { //select difficult |
el13drt | 18:c38e1966d870 | 783 | buttonFlagA = 0; |
el13drt | 12:eedda6554615 | 784 | fall = 3; |
el13drt | 12:eedda6554615 | 785 | } |
el13drt | 12:eedda6554615 | 786 | } |
el13drt | 12:eedda6554615 | 787 | } |
el13drt | 12:eedda6554615 | 788 | } |
el13drt | 12:eedda6554615 | 789 | |
el13drt | 12:eedda6554615 | 790 | // draw difficulty settings |
el13drt | 12:eedda6554615 | 791 | void drawDifficultyMenu() |
el13drt | 12:eedda6554615 | 792 | { |
el13drt | 12:eedda6554615 | 793 | lcd.clear(); |
el13drt | 12:eedda6554615 | 794 | backGround(); |
el13drt | 12:eedda6554615 | 795 | lcd.drawRect(0,47,84,0,1);//bottom border |
el13drt | 12:eedda6554615 | 796 | lcd.drawRect(0,0,84,2,1);//top border |
el13drt | 12:eedda6554615 | 797 | lcd.printString("*Difficulty*",5,7);//title |
el13drt | 12:eedda6554615 | 798 | lcd.printString("Easy",5,8);//title |
el13drt | 12:eedda6554615 | 799 | lcd.printString("Normal",5,9);//title |
el13drt | 12:eedda6554615 | 800 | lcd.printString("Forget It",5,10);//title |
el13drt | 12:eedda6554615 | 801 | } |
el13drt | 12:eedda6554615 | 802 | |
el13drt | 13:a1b3a373c5a4 | 803 | // present sound FX options |
el13drt | 13:a1b3a373c5a4 | 804 | void soundFXMenu(int& fxOption) |
el13drt | 13:a1b3a373c5a4 | 805 | { |
el13drt | 17:242ccf6a8442 | 806 | actionButtons(); |
el13drt | 13:a1b3a373c5a4 | 807 | |
el13drt | 13:a1b3a373c5a4 | 808 | // joystick selection |
el13drt | 13:a1b3a373c5a4 | 809 | if (printFlag) {//if flag set, clear flag,print joystick values |
el13drt | 13:a1b3a373c5a4 | 810 | printFlag = 0; |
el13drt | 13:a1b3a373c5a4 | 811 | |
el13drt | 13:a1b3a373c5a4 | 812 | // option up |
el13drt | 13:a1b3a373c5a4 | 813 | if (joystick.direction == UP) { |
el13drt | 13:a1b3a373c5a4 | 814 | serial.printf(" UP\n"); |
el13drt | 13:a1b3a373c5a4 | 815 | fxOption = fxOption--; |
el13drt | 13:a1b3a373c5a4 | 816 | if (fxOption < 0)fxOption = 0; |
el13drt | 13:a1b3a373c5a4 | 817 | } |
el13drt | 13:a1b3a373c5a4 | 818 | // option down |
el13drt | 13:a1b3a373c5a4 | 819 | if (joystick.direction == DOWN) { |
el13drt | 13:a1b3a373c5a4 | 820 | serial.printf(" DOWN\n"); |
el13drt | 13:a1b3a373c5a4 | 821 | fxOption = fxOption++; |
el13drt | 20:993c12c6a7bc | 822 | if (fxOption > 1)fxOption = 1; |
el13drt | 13:a1b3a373c5a4 | 823 | } |
el13drt | 13:a1b3a373c5a4 | 824 | // Centre / Unknown orientation |
el13drt | 13:a1b3a373c5a4 | 825 | if (joystick.direction == CENTRE) |
el13drt | 13:a1b3a373c5a4 | 826 | serial.printf(" CENTRE\n"); |
el13drt | 13:a1b3a373c5a4 | 827 | if (joystick.direction == UNKNOWN) |
el13drt | 13:a1b3a373c5a4 | 828 | serial.printf(" Unsupported direction\n"); |
el13drt | 17:242ccf6a8442 | 829 | } |
el13drt | 13:a1b3a373c5a4 | 830 | |
el13drt | 17:242ccf6a8442 | 831 | // 'ON' option 1 |
el13drt | 17:242ccf6a8442 | 832 | if (fxOption == 0) { |
el13drt | 17:242ccf6a8442 | 833 | lcd.drawCircle(72,27,2,1);//draw cursor 'ON' |
el13drt | 17:242ccf6a8442 | 834 | refreshCursor1(); |
el13drt | 17:242ccf6a8442 | 835 | refreshCursor3(); |
el13drt | 13:a1b3a373c5a4 | 836 | |
el13drt | 17:242ccf6a8442 | 837 | if(buttonFlagA) { |
el13drt | 17:242ccf6a8442 | 838 | buttonFlagA =0; |
el13drt | 17:242ccf6a8442 | 839 | FX = 0; |
el13drt | 19:e0fd493816ae | 840 | serial.printf("FX = %d\n",FX); |
el13drt | 13:a1b3a373c5a4 | 841 | } |
el13drt | 17:242ccf6a8442 | 842 | } |
el13drt | 17:242ccf6a8442 | 843 | // 'OFF' option 2 |
el13drt | 17:242ccf6a8442 | 844 | if (fxOption == 1) { |
el13drt | 17:242ccf6a8442 | 845 | lcd.drawCircle(72,35,2,1);//draw cursor 'OFF' |
el13drt | 17:242ccf6a8442 | 846 | refreshCursor1(); |
el13drt | 17:242ccf6a8442 | 847 | refreshCursor2(); |
el13drt | 13:a1b3a373c5a4 | 848 | |
el13drt | 17:242ccf6a8442 | 849 | if(buttonFlagA) { |
el13drt | 17:242ccf6a8442 | 850 | buttonFlagA =0; |
el13drt | 17:242ccf6a8442 | 851 | FX = 1; |
el13drt | 19:e0fd493816ae | 852 | serial.printf("FX = %d\n",FX); |
el13drt | 13:a1b3a373c5a4 | 853 | } |
el13drt | 13:a1b3a373c5a4 | 854 | } |
el13drt | 13:a1b3a373c5a4 | 855 | } |
el13drt | 13:a1b3a373c5a4 | 856 | |
el13drt | 13:a1b3a373c5a4 | 857 | // draw Sound FX settings |
el13drt | 13:a1b3a373c5a4 | 858 | void drawSoundFXMenu() |
el13drt | 13:a1b3a373c5a4 | 859 | { |
el13drt | 13:a1b3a373c5a4 | 860 | lcd.clear(); |
el13drt | 13:a1b3a373c5a4 | 861 | backGround(); |
el13drt | 13:a1b3a373c5a4 | 862 | lcd.drawRect(0,47,84,0,1);//bottom border |
el13drt | 13:a1b3a373c5a4 | 863 | lcd.drawRect(0,0,84,2,1);//top border |
el13drt | 13:a1b3a373c5a4 | 864 | lcd.printString("*Sound FX*",10,7);//title |
el13drt | 13:a1b3a373c5a4 | 865 | lcd.printString("ON",35,9);//title |
el13drt | 13:a1b3a373c5a4 | 866 | lcd.printString("OFF",33,10);//title |
el13drt | 13:a1b3a373c5a4 | 867 | } |
el13drt | 13:a1b3a373c5a4 | 868 | |
el13drt | 21:1fbbd8ebb3d9 | 869 | // if any of the high scores are beaten, they are replaced. |
el13drt | 33:bc730c9b4b1c | 870 | // player enters initials using struct |
el13drt | 21:1fbbd8ebb3d9 | 871 | void newScore() |
el13drt | 30:a05628b65926 | 872 | { |
el13drt | 33:bc730c9b4b1c | 873 | if(score >= highScore3) {//entry condition |
el13drt | 22:e5bfe0e7c508 | 874 | |
el13drt | 22:e5bfe0e7c508 | 875 | lcd.clear(); |
el13drt | 22:e5bfe0e7c508 | 876 | backGround(); |
el13drt | 23:548299d45a60 | 877 | lcd.printString("High Score!!",7,0);//title |
el13drt | 23:548299d45a60 | 878 | lcd.printString("Enter ID",19,4);//title |
el13drt | 22:e5bfe0e7c508 | 879 | int n;//local variable used for storing temporary global variable |
el13drt | 25:70048c7e02c7 | 880 | int initial = 0;//used for isolating which initial is being selected |
el13drt | 30:a05628b65926 | 881 | |
el13drt | 33:bc730c9b4b1c | 882 | //put conditions here |
el13drt | 33:bc730c9b4b1c | 883 | |
el13drt | 22:e5bfe0e7c508 | 884 | while(1) { |
el13drt | 30:a05628b65926 | 885 | |
el13drt | 22:e5bfe0e7c508 | 886 | // joystick selection |
el13drt | 22:e5bfe0e7c508 | 887 | if (printFlag) {//if flag set, clear flag,print joystick values |
el13drt | 22:e5bfe0e7c508 | 888 | printFlag = 0; |
el13drt | 22:e5bfe0e7c508 | 889 | // option up |
el13drt | 22:e5bfe0e7c508 | 890 | if (joystick.direction == UP) { |
el13drt | 22:e5bfe0e7c508 | 891 | serial.printf(" UP\n"); |
el13drt | 31:da1a4875c404 | 892 | state1 = state1--; |
el13drt | 31:da1a4875c404 | 893 | if (state1 < 0)state1 = 0; |
el13drt | 31:da1a4875c404 | 894 | state2 = state2--; |
el13drt | 31:da1a4875c404 | 895 | if (state2 < 0)state2 = 0; |
el13drt | 31:da1a4875c404 | 896 | state3 = state3--; |
el13drt | 31:da1a4875c404 | 897 | if (state3 < 0)state3 = 0; |
el13drt | 22:e5bfe0e7c508 | 898 | } |
el13drt | 22:e5bfe0e7c508 | 899 | // option down |
el13drt | 22:e5bfe0e7c508 | 900 | if (joystick.direction == DOWN) { |
el13drt | 22:e5bfe0e7c508 | 901 | serial.printf(" DOWN\n"); |
el13drt | 31:da1a4875c404 | 902 | state1 = state1++; |
el13drt | 31:da1a4875c404 | 903 | if (state1 > 26)state1 = 26; |
el13drt | 31:da1a4875c404 | 904 | state2 = state2++; |
el13drt | 31:da1a4875c404 | 905 | if (state2 > 26)state2 = 26; |
el13drt | 31:da1a4875c404 | 906 | state3 = state3++; |
el13drt | 31:da1a4875c404 | 907 | if (state3 > 26)state3 = 26; |
el13drt | 22:e5bfe0e7c508 | 908 | } |
el13drt | 24:eb80956e2e95 | 909 | if (joystick.direction == LEFT) { |
el13drt | 24:eb80956e2e95 | 910 | serial.printf(" LEFT\n"); |
el13drt | 24:eb80956e2e95 | 911 | initial = initial--; |
el13drt | 24:eb80956e2e95 | 912 | if (initial < 0)initial = 0; |
el13drt | 24:eb80956e2e95 | 913 | } |
el13drt | 24:eb80956e2e95 | 914 | if (joystick.direction == RIGHT) { |
el13drt | 24:eb80956e2e95 | 915 | serial.printf(" RIGHT\n"); |
el13drt | 24:eb80956e2e95 | 916 | initial = initial++; |
el13drt | 24:eb80956e2e95 | 917 | if (initial > 2)initial = 2; |
el13drt | 33:bc730c9b4b1c | 918 | |
el13drt | 24:eb80956e2e95 | 919 | } |
el13drt | 22:e5bfe0e7c508 | 920 | // Centre / Unknown orientation |
el13drt | 22:e5bfe0e7c508 | 921 | if (joystick.direction == CENTRE) |
el13drt | 22:e5bfe0e7c508 | 922 | serial.printf(" CENTRE\n"); |
el13drt | 22:e5bfe0e7c508 | 923 | if (joystick.direction == UNKNOWN) |
el13drt | 22:e5bfe0e7c508 | 924 | serial.printf(" Unsupported direction\n"); |
el13drt | 22:e5bfe0e7c508 | 925 | } |
el13drt | 23:548299d45a60 | 926 | |
el13drt | 30:a05628b65926 | 927 | char x[1];//create storage |
el13drt | 30:a05628b65926 | 928 | char y[1];//for initials |
el13drt | 30:a05628b65926 | 929 | char z[1]; |
el13drt | 30:a05628b65926 | 930 | |
el13drt | 33:bc730c9b4b1c | 931 | // if initial 3 display selected character |
el13drt | 24:eb80956e2e95 | 932 | if (initial == 0) { |
el13drt | 33:bc730c9b4b1c | 933 | int initial1 = sprintf(x,"%c",fsm[state1].output1);//insert into letter in x |
el13drt | 30:a05628b65926 | 934 | lcd.printString(x,25,26);//print x buffer |
el13drt | 24:eb80956e2e95 | 935 | } |
el13drt | 33:bc730c9b4b1c | 936 | // if initial 1 display selected character |
el13drt | 24:eb80956e2e95 | 937 | if(initial == 1) { |
el13drt | 33:bc730c9b4b1c | 938 | int initial2 = sprintf(y,"%c",fsm[state2].output2);//insert into letter in y |
el13drt | 30:a05628b65926 | 939 | lcd.printString(y,37,26);//print y buffer |
el13drt | 24:eb80956e2e95 | 940 | } |
el13drt | 33:bc730c9b4b1c | 941 | // if initial 2 display selected character |
el13drt | 24:eb80956e2e95 | 942 | if(initial == 2) { |
el13drt | 33:bc730c9b4b1c | 943 | int initial3 = sprintf(z,"%c",fsm[state3].output3);//insert into letter z |
el13drt | 30:a05628b65926 | 944 | lcd.printString(z,49,26);//print z buffer |
el13drt | 30:a05628b65926 | 945 | } |
el13drt | 30:a05628b65926 | 946 | // if player beats High Score 3, replace it with new score |
el13drt | 33:bc730c9b4b1c | 947 | if(score >= highScore3 && score<highScore2 ) { |
el13drt | 30:a05628b65926 | 948 | n = score; |
el13drt | 30:a05628b65926 | 949 | highScore3 = n; |
el13drt | 33:bc730c9b4b1c | 950 | // |
el13drt | 31:da1a4875c404 | 951 | int insert3 = sprintf (player3initials, "3.%s%s%s....%i",x,y,z,highScore3); |
el13drt | 24:eb80956e2e95 | 952 | } |
el13drt | 30:a05628b65926 | 953 | // if player beats High Score 3 and 2, replace HighScore2 with new score |
el13drt | 33:bc730c9b4b1c | 954 | if(score >= highScore2 && score< highScore1) { |
el13drt | 33:bc730c9b4b1c | 955 | highScore3 = highScore2; |
el13drt | 30:a05628b65926 | 956 | n = score; |
el13drt | 30:a05628b65926 | 957 | highScore2 = n; |
el13drt | 31:da1a4875c404 | 958 | int insert2 = sprintf (player2initials, "2.%s%s%s....%i",x,y,z,highScore2); |
el13drt | 30:a05628b65926 | 959 | } |
el13drt | 30:a05628b65926 | 960 | // if player beats High Score 1, 2 and 3, replace highScore1 with new score |
el13drt | 30:a05628b65926 | 961 | if(score >= highScore1 ) { |
el13drt | 33:bc730c9b4b1c | 962 | highScore3 = highScore2; |
el13drt | 30:a05628b65926 | 963 | highScore2 = highScore1; |
el13drt | 30:a05628b65926 | 964 | n = score; |
el13drt | 30:a05628b65926 | 965 | highScore1 = n; |
el13drt | 31:da1a4875c404 | 966 | int insert1 = sprintf (player1initials, "1.%s%s%s....%i",x,y,z,highScore1); |
el13drt | 30:a05628b65926 | 967 | } |
el13drt | 30:a05628b65926 | 968 | // goes back to main menu after storing initials |
el13drt | 25:70048c7e02c7 | 969 | if(buttonFlagA) { |
el13drt | 25:70048c7e02c7 | 970 | buttonFlagA = 0; |
el13drt | 25:70048c7e02c7 | 971 | buttonFlagB = 0; |
el13drt | 25:70048c7e02c7 | 972 | break; |
el13drt | 25:70048c7e02c7 | 973 | } |
el13drt | 22:e5bfe0e7c508 | 974 | } |
el13drt | 21:1fbbd8ebb3d9 | 975 | } |
el13drt | 21:1fbbd8ebb3d9 | 976 | } |
el13drt | 21:1fbbd8ebb3d9 | 977 | |
el13drt | 25:70048c7e02c7 | 978 | |
el13drt | 12:eedda6554615 | 979 | // actual game |
el13drt | 12:eedda6554615 | 980 | void game(int& exitFlag, int& exitOption) |
el13drt | 12:eedda6554615 | 981 | { |
el13drt | 17:242ccf6a8442 | 982 | actionButtons(); |
el13drt | 12:eedda6554615 | 983 | lcd.clear();//clears screen |
el13drt | 12:eedda6554615 | 984 | backGround();//draw background |
el13drt | 12:eedda6554615 | 985 | |
el13drt | 12:eedda6554615 | 986 | ///game/// |
el13drt | 12:eedda6554615 | 987 | while(1) { |
el13drt | 12:eedda6554615 | 988 | // print score - top left of display |
el13drt | 12:eedda6554615 | 989 | char buffer[14];//create buffer for string |
el13drt | 12:eedda6554615 | 990 | int length = sprintf(buffer,"Level:%d",score);//insert buffer |
el13drt | 30:a05628b65926 | 991 | lcd.printString(buffer,3,0);//display |
el13drt | 12:eedda6554615 | 992 | |
el13drt | 17:242ccf6a8442 | 993 | actionButtons(); |
el13drt | 12:eedda6554615 | 994 | pixelNinja();//set character |
el13drt | 12:eedda6554615 | 995 | hazards();//initiates hazards |
el13drt | 12:eedda6554615 | 996 | hazardFall();//increments hazards towards floor |
el13drt | 12:eedda6554615 | 997 | |
el13drt | 12:eedda6554615 | 998 | if (printFlag) { //if flag set, clear flag and print joystick values to serial port |
el13drt | 12:eedda6554615 | 999 | printFlag = 0; |
el13drt | 12:eedda6554615 | 1000 | |
el13drt | 12:eedda6554615 | 1001 | // check joystick direction |
el13drt | 12:eedda6554615 | 1002 | if (joystick.direction == LEFT) { |
el13drt | 12:eedda6554615 | 1003 | serial.printf(" LEFT\n"); |
el13drt | 12:eedda6554615 | 1004 | a1 = a1-=2; |
el13drt | 12:eedda6554615 | 1005 | a2 = a2-=2; |
el13drt | 12:eedda6554615 | 1006 | a3 = a3-=2; |
el13drt | 12:eedda6554615 | 1007 | a4 = a4-=2; |
el13drt | 12:eedda6554615 | 1008 | a5 = a5-=2; |
el13drt | 12:eedda6554615 | 1009 | a6 = a6-=2; |
el13drt | 12:eedda6554615 | 1010 | a7 = a7-=2; |
el13drt | 12:eedda6554615 | 1011 | a8 = a8-=2; |
el13drt | 12:eedda6554615 | 1012 | ninjaBoundaries(); |
el13drt | 12:eedda6554615 | 1013 | } |
el13drt | 12:eedda6554615 | 1014 | if (joystick.direction == RIGHT) { |
el13drt | 12:eedda6554615 | 1015 | serial.printf(" RIGHT\n"); |
el13drt | 12:eedda6554615 | 1016 | a1 = a1+=2; |
el13drt | 12:eedda6554615 | 1017 | a2 = a2+=2; |
el13drt | 12:eedda6554615 | 1018 | a3 = a3+=2; |
el13drt | 12:eedda6554615 | 1019 | a4 = a4+=2; |
el13drt | 12:eedda6554615 | 1020 | a5 = a5+=2; |
el13drt | 12:eedda6554615 | 1021 | a6 = a6+=2; |
el13drt | 12:eedda6554615 | 1022 | a7 = a7+=2; |
el13drt | 12:eedda6554615 | 1023 | a8 = a8+=2; |
el13drt | 12:eedda6554615 | 1024 | ninjaBoundaries(); |
el13drt | 12:eedda6554615 | 1025 | } |
el13drt | 22:e5bfe0e7c508 | 1026 | |
el13drt | 21:1fbbd8ebb3d9 | 1027 | /////////////////////readWrite(); |
el13drt | 22:e5bfe0e7c508 | 1028 | |
el13drt | 12:eedda6554615 | 1029 | if (joystick.direction == CENTRE) |
el13drt | 12:eedda6554615 | 1030 | serial.printf(" CENTRE\n"); |
el13drt | 12:eedda6554615 | 1031 | if (joystick.direction == UNKNOWN) |
el13drt | 12:eedda6554615 | 1032 | serial.printf(" Unsupported direction\n"); |
el13drt | 22:e5bfe0e7c508 | 1033 | |
el13drt | 12:eedda6554615 | 1034 | // integer to represent character being |
el13drt | 12:eedda6554615 | 1035 | // struck by falling object |
el13drt | 12:eedda6554615 | 1036 | int contactPoint = 0; |
el13drt | 12:eedda6554615 | 1037 | |
el13drt | 12:eedda6554615 | 1038 | // contact points |
el13drt | 12:eedda6554615 | 1039 | if(lcd.getPixel((a1+4),32)) |
el13drt | 12:eedda6554615 | 1040 | contactPoint++; |
el13drt | 12:eedda6554615 | 1041 | if(lcd.getPixel((a1),32)) |
el13drt | 12:eedda6554615 | 1042 | contactPoint++; |
el13drt | 12:eedda6554615 | 1043 | if(lcd.getPixel((a7),32)) |
el13drt | 12:eedda6554615 | 1044 | contactPoint++; |
el13drt | 12:eedda6554615 | 1045 | |
el13drt | 12:eedda6554615 | 1046 | // if contact point is not zero |
el13drt | 12:eedda6554615 | 1047 | // character has been hit |
el13drt | 12:eedda6554615 | 1048 | // and the game ends |
el13drt | 12:eedda6554615 | 1049 | if ( contactPoint !=0) { |
el13drt | 12:eedda6554615 | 1050 | lcd.printString("Game Over",17,2); |
el13drt | 12:eedda6554615 | 1051 | lcd.inverseMode(); |
el13drt | 13:a1b3a373c5a4 | 1052 | buzzer.beep(2000,0.2);//frequeny/duration |
el13drt | 12:eedda6554615 | 1053 | wait(0.5); |
el13drt | 12:eedda6554615 | 1054 | lcd.normalMode(); |
el13drt | 12:eedda6554615 | 1055 | wait(0.5); |
el13drt | 12:eedda6554615 | 1056 | lcd.inverseMode(); |
el13drt | 13:a1b3a373c5a4 | 1057 | buzzer.beep(2000,0.2); |
el13drt | 12:eedda6554615 | 1058 | wait(0.5); |
el13drt | 12:eedda6554615 | 1059 | lcd.normalMode(); |
el13drt | 12:eedda6554615 | 1060 | wait(0.5); |
el13drt | 13:a1b3a373c5a4 | 1061 | lcd.inverseMode(); |
el13drt | 13:a1b3a373c5a4 | 1062 | buzzer.beep(2000,0.2); |
el13drt | 13:a1b3a373c5a4 | 1063 | wait(0.5); |
el13drt | 13:a1b3a373c5a4 | 1064 | lcd.normalMode(); |
el13drt | 30:a05628b65926 | 1065 | newScore();//enter initial screen if previous scores are beaten |
el13drt | 12:eedda6554615 | 1066 | resetGame(); |
el13drt | 12:eedda6554615 | 1067 | break; |
el13drt | 12:eedda6554615 | 1068 | } |
el13drt | 12:eedda6554615 | 1069 | startrek();//clears unset pixels, keeps set pixels |
el13drt | 17:242ccf6a8442 | 1070 | |
el13drt | 12:eedda6554615 | 1071 | /// Exit Menu (Back button pressed)/// |
el13drt | 18:c38e1966d870 | 1072 | if(buttonFlagB) { |
el13drt | 20:993c12c6a7bc | 1073 | buttonFlagB = 0;//reset flags |
el13drt | 20:993c12c6a7bc | 1074 | buttonFlagA = 0; |
el13drt | 17:242ccf6a8442 | 1075 | actionButtons(); |
el13drt | 12:eedda6554615 | 1076 | drawExitMenu();//draws the exit menu |
el13drt | 12:eedda6554615 | 1077 | |
el13drt | 12:eedda6554615 | 1078 | while(1) { |
el13drt | 12:eedda6554615 | 1079 | exitMenu(exitOption);//presents exit options |
el13drt | 12:eedda6554615 | 1080 | |
el13drt | 12:eedda6554615 | 1081 | // 'exit' option YES |
el13drt | 18:c38e1966d870 | 1082 | if((buttonFlagA)&&(exitOption == 0)) { //returns to menu |
el13drt | 20:993c12c6a7bc | 1083 | buttonFlagA = 0;//reset flags |
el13drt | 20:993c12c6a7bc | 1084 | buttonFlagB = 0; |
el13drt | 17:242ccf6a8442 | 1085 | actionButtons(); |
el13drt | 12:eedda6554615 | 1086 | lcd.clear();//clears screen |
el13drt | 12:eedda6554615 | 1087 | resetGame();//resets scores/objects |
el13drt | 12:eedda6554615 | 1088 | exitFlag = 1;//sets exit flag |
el13drt | 12:eedda6554615 | 1089 | break; |
el13drt | 12:eedda6554615 | 1090 | } |
el13drt | 12:eedda6554615 | 1091 | // 'exit' option NO - returns to game |
el13drt | 18:c38e1966d870 | 1092 | if((buttonFlagA)&&(exitOption == 1)) { |
el13drt | 20:993c12c6a7bc | 1093 | buttonFlagA = 0;//resets flags |
el13drt | 20:993c12c6a7bc | 1094 | buttonFlagB = 0; |
el13drt | 12:eedda6554615 | 1095 | break; |
el13drt | 12:eedda6554615 | 1096 | } |
el13drt | 18:c38e1966d870 | 1097 | sleep();//put while to sleep |
el13drt | 12:eedda6554615 | 1098 | } |
el13drt | 12:eedda6554615 | 1099 | // if 'exit' option YES, resets |
el13drt | 12:eedda6554615 | 1100 | // game values returns to main menu |
el13drt | 12:eedda6554615 | 1101 | if (exitFlag!=0) { //if exit flag set |
el13drt | 12:eedda6554615 | 1102 | exitFlag = 0;//reset flag |
el13drt | 12:eedda6554615 | 1103 | break;//break to main menu |
el13drt | 12:eedda6554615 | 1104 | } |
el13drt | 12:eedda6554615 | 1105 | } |
el13drt | 12:eedda6554615 | 1106 | serial.printf("Score: %i \n",score); |
el13drt | 12:eedda6554615 | 1107 | } |
el13drt | 12:eedda6554615 | 1108 | } |
el13drt | 12:eedda6554615 | 1109 | } |
el13drt | 12:eedda6554615 | 1110 | |
el13drt | 12:eedda6554615 | 1111 | // high scores screen |
el13drt | 12:eedda6554615 | 1112 | void scores() |
el13drt | 12:eedda6554615 | 1113 | { |
el13drt | 17:242ccf6a8442 | 1114 | actionButtons(); |
el13drt | 12:eedda6554615 | 1115 | lcd.clear();//clear screen |
el13drt | 12:eedda6554615 | 1116 | backGround();//set background |
el13drt | 12:eedda6554615 | 1117 | lcd.printString("High Scores",10,0);//title |
el13drt | 25:70048c7e02c7 | 1118 | |
el13drt | 30:a05628b65926 | 1119 | // prints scores with names |
el13drt | 30:a05628b65926 | 1120 | lcd.printString(player1initials,5,2);//display |
el13drt | 12:eedda6554615 | 1121 | |
el13drt | 30:a05628b65926 | 1122 | lcd.printString(player2initials,5,3);//display |
el13drt | 12:eedda6554615 | 1123 | |
el13drt | 30:a05628b65926 | 1124 | lcd.printString(player3initials,5,4);//display |
el13drt | 12:eedda6554615 | 1125 | |
el13drt | 12:eedda6554615 | 1126 | while(1) { |
el13drt | 17:242ccf6a8442 | 1127 | actionButtons();//select |
el13drt | 12:eedda6554615 | 1128 | |
el13drt | 12:eedda6554615 | 1129 | // back to menu |
el13drt | 18:c38e1966d870 | 1130 | if(buttonFlagB) { |
el13drt | 25:70048c7e02c7 | 1131 | buttonFlagA = 0;//reset flags |
el13drt | 25:70048c7e02c7 | 1132 | buttonFlagB = 0; |
el13drt | 12:eedda6554615 | 1133 | lcd.clear(); |
el13drt | 12:eedda6554615 | 1134 | break; |
el13drt | 12:eedda6554615 | 1135 | } |
el13drt | 18:c38e1966d870 | 1136 | sleep();//put while to sleep |
el13drt | 12:eedda6554615 | 1137 | } |
el13drt | 13:a1b3a373c5a4 | 1138 | } |
el13drt | 13:a1b3a373c5a4 | 1139 | |
el13drt | 13:a1b3a373c5a4 | 1140 | // options menu |
el13drt | 14:c2c969e1c6e8 | 1141 | void optionsMenu() |
el13drt | 13:a1b3a373c5a4 | 1142 | { |
el13drt | 14:c2c969e1c6e8 | 1143 | int option = 0; |
el13drt | 14:c2c969e1c6e8 | 1144 | int subOption = 0; |
el13drt | 14:c2c969e1c6e8 | 1145 | int fxOption = 0; |
el13drt | 17:242ccf6a8442 | 1146 | actionButtons(); |
el13drt | 15:ff3eb0091453 | 1147 | drawOptionsMenu();//draws options menu |
el13drt | 15:ff3eb0091453 | 1148 | // counters for navigation |
el13drt | 17:242ccf6a8442 | 1149 | |
el13drt | 13:a1b3a373c5a4 | 1150 | while(1) { |
el13drt | 17:242ccf6a8442 | 1151 | actionButtons(); |
el13drt | 13:a1b3a373c5a4 | 1152 | optionsMenu(option);//presents options |
el13drt | 13:a1b3a373c5a4 | 1153 | |
el13drt | 13:a1b3a373c5a4 | 1154 | ////////////////////// difficulty menu //////////////////////////////////// |
el13drt | 15:ff3eb0091453 | 1155 | if ((option == 0)&&(buttonFlagA)) { |
el13drt | 15:ff3eb0091453 | 1156 | buttonFlagA = 0;//reset flag |
el13drt | 17:242ccf6a8442 | 1157 | actionButtons(); |
el13drt | 13:a1b3a373c5a4 | 1158 | drawDifficultyMenu();//draws difficulty menu |
el13drt | 13:a1b3a373c5a4 | 1159 | |
el13drt | 13:a1b3a373c5a4 | 1160 | while(1) { |
el13drt | 17:242ccf6a8442 | 1161 | actionButtons(); |
el13drt | 13:a1b3a373c5a4 | 1162 | difficultyMenu(subOption);//presents difficulty options |
el13drt | 13:a1b3a373c5a4 | 1163 | |
el13drt | 15:ff3eb0091453 | 1164 | if(buttonFlagB) { |
el13drt | 20:993c12c6a7bc | 1165 | buttonFlagB = 0;//reset flags |
el13drt | 20:993c12c6a7bc | 1166 | buttonFlagA = 0; |
el13drt | 15:ff3eb0091453 | 1167 | lcd.clear();//clear screen |
el13drt | 15:ff3eb0091453 | 1168 | break;//return back |
el13drt | 13:a1b3a373c5a4 | 1169 | } |
el13drt | 17:242ccf6a8442 | 1170 | sleep();//put while to sleep |
el13drt | 13:a1b3a373c5a4 | 1171 | } |
el13drt | 17:242ccf6a8442 | 1172 | drawOptionsMenu(); |
el13drt | 13:a1b3a373c5a4 | 1173 | } |
el13drt | 13:a1b3a373c5a4 | 1174 | ///////////////////// sound FX menu ////////////////////////////////////// |
el13drt | 15:ff3eb0091453 | 1175 | if((option ==1)&&(buttonFlagA)) { |
el13drt | 20:993c12c6a7bc | 1176 | buttonFlagA = 0;//reset flags |
el13drt | 20:993c12c6a7bc | 1177 | buttonFlagB = 0; |
el13drt | 17:242ccf6a8442 | 1178 | actionButtons(); |
el13drt | 13:a1b3a373c5a4 | 1179 | drawSoundFXMenu();//draw menu |
el13drt | 13:a1b3a373c5a4 | 1180 | |
el13drt | 13:a1b3a373c5a4 | 1181 | while(1) { |
el13drt | 17:242ccf6a8442 | 1182 | actionButtons(); |
el13drt | 17:242ccf6a8442 | 1183 | soundFXMenu(fxOption);//presents options |
el13drt | 13:a1b3a373c5a4 | 1184 | |
el13drt | 13:a1b3a373c5a4 | 1185 | // back to options menu |
el13drt | 15:ff3eb0091453 | 1186 | if(buttonFlagB) { |
el13drt | 20:993c12c6a7bc | 1187 | buttonFlagB = 0;//reset flags |
el13drt | 20:993c12c6a7bc | 1188 | buttonFlagA = 0; |
el13drt | 15:ff3eb0091453 | 1189 | lcd.clear();//clear screen |
el13drt | 15:ff3eb0091453 | 1190 | break;//return back |
el13drt | 13:a1b3a373c5a4 | 1191 | } |
el13drt | 17:242ccf6a8442 | 1192 | sleep();//put while to sleep |
el13drt | 13:a1b3a373c5a4 | 1193 | } |
el13drt | 15:ff3eb0091453 | 1194 | drawOptionsMenu(); |
el13drt | 13:a1b3a373c5a4 | 1195 | } |
el13drt | 13:a1b3a373c5a4 | 1196 | // back to mainmenu |
el13drt | 15:ff3eb0091453 | 1197 | if(buttonFlagB) { |
el13drt | 20:993c12c6a7bc | 1198 | buttonFlagB = 0;//reset flags |
el13drt | 20:993c12c6a7bc | 1199 | buttonFlagA = 0; |
el13drt | 15:ff3eb0091453 | 1200 | lcd.clear();//clear |
el13drt | 15:ff3eb0091453 | 1201 | break;//return back |
el13drt | 13:a1b3a373c5a4 | 1202 | } |
el13drt | 22:e5bfe0e7c508 | 1203 | sleep();//put while to sleep |
el13drt | 13:a1b3a373c5a4 | 1204 | } |
el13drt | 13:a1b3a373c5a4 | 1205 | } |
el13drt | 13:a1b3a373c5a4 | 1206 | |
el13drt | 13:a1b3a373c5a4 | 1207 | // read default positions of the joystick to calibrate later readings |
el13drt | 13:a1b3a373c5a4 | 1208 | void calibrateJoystick() |
el13drt | 13:a1b3a373c5a4 | 1209 | { |
el13drt | 14:c2c969e1c6e8 | 1210 | joyButton.mode(PullDown); |
el13drt | 13:a1b3a373c5a4 | 1211 | // must not move during calibration |
el13drt | 13:a1b3a373c5a4 | 1212 | joystick.x0 = xPot; //initial positions in the range 0.0 to 1.0 (0.5 if centred exactly) |
el13drt | 13:a1b3a373c5a4 | 1213 | joystick.y0 = yPot; |
el13drt | 13:a1b3a373c5a4 | 1214 | } |
el13drt | 13:a1b3a373c5a4 | 1215 | |
el13drt | 30:a05628b65926 | 1216 | //reads and updates position of joystick according to voltage readings |
el13drt | 13:a1b3a373c5a4 | 1217 | void updateJoystick() |
el13drt | 13:a1b3a373c5a4 | 1218 | { |
el13drt | 13:a1b3a373c5a4 | 1219 | // read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred) |
el13drt | 13:a1b3a373c5a4 | 1220 | joystick.x = xPot - joystick.x0; |
el13drt | 13:a1b3a373c5a4 | 1221 | joystick.y = yPot - joystick.y0; |
el13drt | 13:a1b3a373c5a4 | 1222 | // read button state |
el13drt | 14:c2c969e1c6e8 | 1223 | joystick.button = joyButton; |
el13drt | 13:a1b3a373c5a4 | 1224 | |
el13drt | 13:a1b3a373c5a4 | 1225 | // calculate direction depending on x,y values |
el13drt | 13:a1b3a373c5a4 | 1226 | // tolerance allows a little lee-way in case joystick not exactly in the stated direction |
el13drt | 13:a1b3a373c5a4 | 1227 | if ( fabs(joystick.y) < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { |
el13drt | 13:a1b3a373c5a4 | 1228 | joystick.direction = CENTRE; |
el13drt | 13:a1b3a373c5a4 | 1229 | } else if ( joystick.y > DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { |
el13drt | 13:a1b3a373c5a4 | 1230 | joystick.direction = UP; |
el13drt | 13:a1b3a373c5a4 | 1231 | } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { |
el13drt | 13:a1b3a373c5a4 | 1232 | joystick.direction = DOWN; |
el13drt | 13:a1b3a373c5a4 | 1233 | } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) { |
el13drt | 13:a1b3a373c5a4 | 1234 | joystick.direction = RIGHT; |
el13drt | 13:a1b3a373c5a4 | 1235 | } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) { |
el13drt | 13:a1b3a373c5a4 | 1236 | joystick.direction = LEFT; |
el13drt | 13:a1b3a373c5a4 | 1237 | } else { |
el13drt | 13:a1b3a373c5a4 | 1238 | joystick.direction = UNKNOWN; |
el13drt | 13:a1b3a373c5a4 | 1239 | } |
el13drt | 13:a1b3a373c5a4 | 1240 | |
el13drt | 13:a1b3a373c5a4 | 1241 | // set flag for printing |
el13drt | 13:a1b3a373c5a4 | 1242 | printFlag = 1; |
el13drt | 12:eedda6554615 | 1243 | } |