el15mh 200929957

Dependencies:   mbed

Committer:
el15mh
Date:
Thu Mar 30 12:22:51 2017 +0000
Revision:
1:8ce2586b5965
Parent:
0:d7701c5c20e6
Child:
2:a488caea1601
game options menu test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el15mh 0:d7701c5c20e6 1 #include "mbed.h"
el15mh 0:d7701c5c20e6 2 #include "N5110.h"
el15mh 0:d7701c5c20e6 3 #include "Gamepad.h"
el15mh 0:d7701c5c20e6 4
el15mh 0:d7701c5c20e6 5 // CREATE OBJECTS //
el15mh 0:d7701c5c20e6 6 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
el15mh 0:d7701c5c20e6 7 Gamepad pad;
el15mh 0:d7701c5c20e6 8
el15mh 0:d7701c5c20e6 9 // FUNCTION PROTOTYPES //
el15mh 0:d7701c5c20e6 10 void init();
el15mh 0:d7701c5c20e6 11
el15mh 0:d7701c5c20e6 12 int main()
el15mh 0:d7701c5c20e6 13 {
el15mh 0:d7701c5c20e6 14 init(); // initialise devices
el15mh 0:d7701c5c20e6 15
el15mh 0:d7701c5c20e6 16 while(1){
el15mh 0:d7701c5c20e6 17
el15mh 1:8ce2586b5965 18 int selected = 0;
el15mh 1:8ce2586b5965 19 int exit = 0;
el15mh 0:d7701c5c20e6 20
el15mh 1:8ce2586b5965 21 while(exit == 0){
el15mh 0:d7701c5c20e6 22
el15mh 1:8ce2586b5965 23 int back = 0;
el15mh 1:8ce2586b5965 24
el15mh 1:8ce2586b5965 25 switch (selected) {
el15mh 0:d7701c5c20e6 26
el15mh 1:8ce2586b5965 27 case 1:
el15mh 0:d7701c5c20e6 28
el15mh 1:8ce2586b5965 29 lcd.clear();
el15mh 1:8ce2586b5965 30 // displays options page with indicator on first
el15mh 1:8ce2586b5965 31 lcd.printString("Game Options:", 0, 0);
el15mh 1:8ce2586b5965 32 lcd.printString(">Difficulty", 0, 2);
el15mh 1:8ce2586b5965 33 lcd.printString(" Ball Colour", 0, 3);
el15mh 1:8ce2586b5965 34 lcd.refresh();
el15mh 0:d7701c5c20e6 35
el15mh 1:8ce2586b5965 36 while (back == 0){
el15mh 0:d7701c5c20e6 37
el15mh 1:8ce2586b5965 38 // if first option selected
el15mh 1:8ce2586b5965 39 if (pad.check_event(Gamepad::A_PRESSED) ||
el15mh 1:8ce2586b5965 40 pad.check_event(Gamepad::JOY_PRESSED)){
el15mh 1:8ce2586b5965 41
el15mh 1:8ce2586b5965 42 switch(selected){
el15mh 0:d7701c5c20e6 43
el15mh 1:8ce2586b5965 44 case 1:
el15mh 0:d7701c5c20e6 45
el15mh 0:d7701c5c20e6 46 lcd.clear();
el15mh 1:8ce2586b5965 47 lcd.printString("Difficulty: ", 0, 0);
el15mh 1:8ce2586b5965 48 lcd.printString(">Easy", 0, 2);
el15mh 1:8ce2586b5965 49 lcd.printString(" Hard", 0, 3);
el15mh 0:d7701c5c20e6 50 lcd.refresh();
el15mh 0:d7701c5c20e6 51
el15mh 1:8ce2586b5965 52 if (pad.check_event(Gamepad::A_PRESSED) ||
el15mh 1:8ce2586b5965 53 pad.check_event(Gamepad::JOY_PRESSED)){
el15mh 1:8ce2586b5965 54
el15mh 1:8ce2586b5965 55 // maze.mazeIndex = 0;
el15mh 1:8ce2586b5965 56 }
el15mh 1:8ce2586b5965 57
el15mh 1:8ce2586b5965 58 wait_ms(250);
el15mh 0:d7701c5c20e6 59
el15mh 1:8ce2586b5965 60 break;
el15mh 1:8ce2586b5965 61
el15mh 1:8ce2586b5965 62 case 2:
el15mh 1:8ce2586b5965 63
el15mh 0:d7701c5c20e6 64 lcd.clear();
el15mh 1:8ce2586b5965 65 lcd.printString("Difficulty: ", 0, 0);
el15mh 1:8ce2586b5965 66 lcd.printString(" Easy", 0, 2);
el15mh 1:8ce2586b5965 67 lcd.printString(">Hard", 0, 3);
el15mh 0:d7701c5c20e6 68 lcd.refresh();
el15mh 0:d7701c5c20e6 69
el15mh 1:8ce2586b5965 70 if (pad.check_event(Gamepad::A_PRESSED) ||
el15mh 1:8ce2586b5965 71 pad.check_event(Gamepad::JOY_PRESSED)){
el15mh 1:8ce2586b5965 72
el15mh 1:8ce2586b5965 73 // maze.mazeIndex = 1;
el15mh 1:8ce2586b5965 74 lcd.printString("Hard selected", 0, 1);
el15mh 1:8ce2586b5965 75 lcd.refresh();
el15mh 1:8ce2586b5965 76 }
el15mh 1:8ce2586b5965 77
el15mh 1:8ce2586b5965 78 wait_ms(250);
el15mh 1:8ce2586b5965 79
el15mh 1:8ce2586b5965 80 break;
el15mh 1:8ce2586b5965 81
el15mh 1:8ce2586b5965 82 default:
el15mh 1:8ce2586b5965 83
el15mh 1:8ce2586b5965 84 selected = 0;
el15mh 1:8ce2586b5965 85
el15mh 1:8ce2586b5965 86 break;
el15mh 1:8ce2586b5965 87
el15mh 1:8ce2586b5965 88 }
el15mh 0:d7701c5c20e6 89 }
el15mh 0:d7701c5c20e6 90
el15mh 0:d7701c5c20e6 91 if (pad.check_event(Gamepad::BACK_PRESSED)){
el15mh 0:d7701c5c20e6 92
el15mh 0:d7701c5c20e6 93 back = 1;
el15mh 0:d7701c5c20e6 94 }
el15mh 0:d7701c5c20e6 95 }
el15mh 0:d7701c5c20e6 96
el15mh 0:d7701c5c20e6 97 wait(1); // 1s propogation delay
el15mh 0:d7701c5c20e6 98
el15mh 1:8ce2586b5965 99 case 2:
el15mh 1:8ce2586b5965 100
el15mh 1:8ce2586b5965 101 lcd.clear();
el15mh 1:8ce2586b5965 102 // displays options page with indicator on second
el15mh 1:8ce2586b5965 103 lcd.printString("Game Options:", 0, 0);
el15mh 1:8ce2586b5965 104 lcd.printString(" Difficulty", 0, 2);
el15mh 1:8ce2586b5965 105 lcd.printString(">Ball Colour", 0, 3);
el15mh 1:8ce2586b5965 106 lcd.refresh();
el15mh 0:d7701c5c20e6 107
el15mh 1:8ce2586b5965 108 while (back == 0){
el15mh 1:8ce2586b5965 109
el15mh 1:8ce2586b5965 110 // if second option selected
el15mh 1:8ce2586b5965 111 if (pad.check_event(Gamepad::A_PRESSED) ||
el15mh 1:8ce2586b5965 112 pad.check_event(Gamepad::JOY_PRESSED)){
el15mh 1:8ce2586b5965 113
el15mh 1:8ce2586b5965 114 switch (selected){
el15mh 1:8ce2586b5965 115
el15mh 1:8ce2586b5965 116 case 1:
el15mh 1:8ce2586b5965 117
el15mh 1:8ce2586b5965 118 lcd.clear();
el15mh 1:8ce2586b5965 119 lcd.printString("Ball colour: ", 0, 0);
el15mh 1:8ce2586b5965 120 lcd.printString(">Transparent", 0, 2);
el15mh 1:8ce2586b5965 121 lcd.printString(" Solid", 0, 3);
el15mh 1:8ce2586b5965 122 lcd.refresh();
el15mh 1:8ce2586b5965 123
el15mh 1:8ce2586b5965 124 if (pad.check_event(Gamepad::A_PRESSED) ||
el15mh 1:8ce2586b5965 125 pad.check_event(Gamepad::JOY_PRESSED)){
el15mh 1:8ce2586b5965 126
el15mh 1:8ce2586b5965 127 // ball.ballColour = 0;
el15mh 1:8ce2586b5965 128 lcd.clear();
el15mh 1:8ce2586b5965 129 lcd.printString("Transparent", 0, 1);
el15mh 1:8ce2586b5965 130 lcd.refresh();
el15mh 1:8ce2586b5965 131
el15mh 1:8ce2586b5965 132 wait(2);
el15mh 1:8ce2586b5965 133 }
el15mh 1:8ce2586b5965 134
el15mh 1:8ce2586b5965 135 break;
el15mh 1:8ce2586b5965 136
el15mh 1:8ce2586b5965 137 case 2:
el15mh 1:8ce2586b5965 138
el15mh 1:8ce2586b5965 139 lcd.printString("Ball colour: ", 0, 0);
el15mh 1:8ce2586b5965 140 lcd.printString(" Transparent", 0, 2);
el15mh 1:8ce2586b5965 141 lcd.printString(">Solid", 0, 3);
el15mh 1:8ce2586b5965 142 lcd.refresh();
el15mh 1:8ce2586b5965 143
el15mh 1:8ce2586b5965 144 if (pad.check_event(Gamepad::A_PRESSED) ||
el15mh 1:8ce2586b5965 145 pad.check_event(Gamepad::JOY_PRESSED)){
el15mh 1:8ce2586b5965 146
el15mh 1:8ce2586b5965 147 // ball.ballColour = 1;
el15mh 1:8ce2586b5965 148 lcd.clear();
el15mh 1:8ce2586b5965 149 lcd.printString("Solid", 0, 1);
el15mh 1:8ce2586b5965 150 lcd.refresh();
el15mh 1:8ce2586b5965 151
el15mh 1:8ce2586b5965 152 wait(2);
el15mh 1:8ce2586b5965 153 }
el15mh 1:8ce2586b5965 154
el15mh 1:8ce2586b5965 155 break;
el15mh 1:8ce2586b5965 156
el15mh 1:8ce2586b5965 157 default:
el15mh 1:8ce2586b5965 158
el15mh 1:8ce2586b5965 159 selected = 0;
el15mh 1:8ce2586b5965 160 break;
el15mh 1:8ce2586b5965 161 }
el15mh 1:8ce2586b5965 162
el15mh 1:8ce2586b5965 163 if (pad.check_event(Gamepad::BACK_PRESSED)){
el15mh 1:8ce2586b5965 164
el15mh 1:8ce2586b5965 165 back = 1;
el15mh 1:8ce2586b5965 166 }
el15mh 1:8ce2586b5965 167 }
el15mh 1:8ce2586b5965 168
el15mh 1:8ce2586b5965 169 wait(1); // 1s propogation delay
el15mh 1:8ce2586b5965 170
el15mh 1:8ce2586b5965 171 }
el15mh 1:8ce2586b5965 172
el15mh 1:8ce2586b5965 173 if (pad.check_event(Gamepad::BACK_PRESSED)){
el15mh 1:8ce2586b5965 174
el15mh 1:8ce2586b5965 175 exit = 1;
el15mh 1:8ce2586b5965 176 }
el15mh 1:8ce2586b5965 177 }
el15mh 0:d7701c5c20e6 178 }
el15mh 1:8ce2586b5965 179
el15mh 0:d7701c5c20e6 180 }
el15mh 0:d7701c5c20e6 181 }
el15mh 0:d7701c5c20e6 182
el15mh 1:8ce2586b5965 183 void init()
el15mh 0:d7701c5c20e6 184 {
el15mh 1:8ce2586b5965 185 lcd.init();
el15mh 1:8ce2586b5965 186 pad.init();
el15mh 0:d7701c5c20e6 187 }