ELEC2645 (2016/17) / Mbed 2 deprecated 2645_Game_Project_2

Dependencies:   Gamepad N5110 Pokemon mbed

Fork of 2645_Game_Project_2 by ELEC2645 (2016/17)

Committer:
200923317
Date:
Wed May 03 15:16:27 2017 +0000
Revision:
7:13333933413d
Parent:
6:6e9a415436e0
Child:
8:e47c48551124
comment start;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
200923317 7:13333933413d 1 /** Pokemon Game
200923317 7:13333933413d 2 @brief Game based on the main series Pokemon games by the pokemon company and Gamefreak.
200923317 7:13333933413d 3 @brief whole game is a battle simulator, where you can level up your companion by battling other wild pokemon
200923317 7:13333933413d 4 @brief You can view your pokemons stats and change the screen brightness from the menus.
200923317 7:13333933413d 5
200923317 7:13333933413d 6 @brief Revision 1.1
200923317 7:13333933413d 7
200923317 7:13333933413d 8 @author Aaron Lad
200923317 7:13333933413d 9 @date 2nd May 2017
200923317 7:13333933413d 10
200923317 7:13333933413d 11 @code
200923317 7:13333933413d 12 */
200923317 7:13333933413d 13
200923317 0:cd3f75767e71 14 #include "mbed.h"
200923317 0:cd3f75767e71 15 #include "Gamepad.h"
200923317 0:cd3f75767e71 16 #include "N5110.h"
200923317 0:cd3f75767e71 17 #include "Pokemon.h"
200923317 3:b4de529de482 18 #include "Images.h"
200923317 4:713ac9379ac6 19 #include "Bitmap.h"
200923317 7:13333933413d 20 #include "Script.h"
200923317 0:cd3f75767e71 21
200923317 0:cd3f75767e71 22 //rewritten code to implement new/better ideas. part of the code is same as before but lots of changes were needed.
200923317 0:cd3f75767e71 23
200923317 0:cd3f75767e71 24 //-------------------------------- objects -------------------------------------
200923317 0:cd3f75767e71 25 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
200923317 0:cd3f75767e71 26 Gamepad pad;
200923317 0:cd3f75767e71 27 Pokemon pk;
200923317 3:b4de529de482 28 Images sp;
200923317 7:13333933413d 29 Script sc;
200923317 0:cd3f75767e71 30 //--------------------------- Structs/Typedefs ---------------------------------
200923317 0:cd3f75767e71 31 struct joyInput {
200923317 0:cd3f75767e71 32 Direction d; //direction of joystick to navigate menu's
200923317 0:cd3f75767e71 33 };
200923317 0:cd3f75767e71 34
200923317 0:cd3f75767e71 35 typedef enum State {START, PARTNER, MENU, FIGHT, POKEMON, SETTINGS} Gamepage;
200923317 0:cd3f75767e71 36 //assigning names to different states
200923317 0:cd3f75767e71 37
200923317 0:cd3f75767e71 38 void init();
200923317 0:cd3f75767e71 39 void drawStart();
200923317 6:6e9a415436e0 40 void select(int x, int y);
200923317 6:6e9a415436e0 41 void deselect(int _x, int _y);
200923317 2:a2bb794f830c 42 void balls();
200923317 2:a2bb794f830c 43 float drawPartner();
200923317 2:a2bb794f830c 44 float partnerChoice(int choice);
200923317 2:a2bb794f830c 45 void choice(int p);
200923317 0:cd3f75767e71 46 float drawMenu();
200923317 0:cd3f75767e71 47 void drawFight();
200923317 0:cd3f75767e71 48 void drawPoke();
200923317 0:cd3f75767e71 49 void menu();
200923317 1:af881f58c4f9 50 void settings();
200923317 7:13333933413d 51 void ledCycle();
200923317 7:13333933413d 52 float YesNo();
200923317 7:13333933413d 53 void battleStats();
200923317 7:13333933413d 54 float rndm(int RA);
200923317 7:13333933413d 55 //-----------------------------Functions----------------------------------------
200923317 1:af881f58c4f9 56
200923317 1:af881f58c4f9 57 int main()
200923317 1:af881f58c4f9 58 {
200923317 4:713ac9379ac6 59 init(); //initialising screen and gamepad
200923317 4:713ac9379ac6 60 drawStart(); //screen shows startup screen
200923317 4:713ac9379ac6 61 Gamepage state = START; //go to start state
200923317 2:a2bb794f830c 62 //-----------------------GAME LOOP START-------------------------------
200923317 2:a2bb794f830c 63 while(1) {
200923317 2:a2bb794f830c 64 if (state == START) {
200923317 7:13333933413d 65
200923317 2:a2bb794f830c 66 state = PARTNER;
200923317 3:b4de529de482 67
200923317 5:add0351183be 68 } else if (state == PARTNER) { //choosing your partner
200923317 7:13333933413d 69
200923317 2:a2bb794f830c 70 int partner = drawPartner();
200923317 2:a2bb794f830c 71 int correct = partnerChoice(partner);
200923317 6:6e9a415436e0 72 if( correct == 2) {
200923317 6:6e9a415436e0 73 state = START;
200923317 6:6e9a415436e0 74 } else if(correct == 1) {
200923317 2:a2bb794f830c 75 choice(partner);
200923317 2:a2bb794f830c 76 lcd.refresh();
200923317 2:a2bb794f830c 77 state = MENU;
200923317 2:a2bb794f830c 78 }
200923317 6:6e9a415436e0 79 }
200923317 3:b4de529de482 80
200923317 6:6e9a415436e0 81 else if (state == FIGHT) { //fight with wild pokemon
200923317 7:13333933413d 82
200923317 6:6e9a415436e0 83 drawFight();
200923317 2:a2bb794f830c 84 state = MENU;
200923317 3:b4de529de482 85
200923317 4:713ac9379ac6 86 } else if (state == SETTINGS) { //settings, screen brightness
200923317 7:13333933413d 87
200923317 6:6e9a415436e0 88 settings();
200923317 2:a2bb794f830c 89 state = MENU;
200923317 3:b4de529de482 90
200923317 4:713ac9379ac6 91 } else if (state == MENU) { // main menu
200923317 7:13333933413d 92
200923317 2:a2bb794f830c 93 wait(1.0);
200923317 2:a2bb794f830c 94 int box = drawMenu();
200923317 2:a2bb794f830c 95 if (box == 0) {
200923317 2:a2bb794f830c 96 state = FIGHT;
200923317 2:a2bb794f830c 97 lcd.clear();
200923317 2:a2bb794f830c 98 } else if (box ==1) {
200923317 2:a2bb794f830c 99 state = POKEMON;
200923317 2:a2bb794f830c 100 lcd.clear();
200923317 2:a2bb794f830c 101 } else if (box ==2) {
200923317 2:a2bb794f830c 102 state = SETTINGS;
200923317 2:a2bb794f830c 103 lcd.clear();
200923317 2:a2bb794f830c 104 }
200923317 2:a2bb794f830c 105 lcd.refresh();
200923317 2:a2bb794f830c 106 wait(2.0);
200923317 3:b4de529de482 107
200923317 4:713ac9379ac6 108 } else if (state == POKEMON) { //check partner pokemon stats
200923317 7:13333933413d 109
200923317 2:a2bb794f830c 110 state = MENU;
200923317 2:a2bb794f830c 111 drawPoke();
200923317 2:a2bb794f830c 112 }
200923317 2:a2bb794f830c 113 }
200923317 2:a2bb794f830c 114 }
200923317 2:a2bb794f830c 115
200923317 7:13333933413d 116 /** initialise screen and pad
200923317 7:13333933413d 117 *powers up the display and configures the gamepad
200923317 7:13333933413d 118 *sets the screen brightness to 100%
200923317 7:13333933413d 119 */
200923317 1:af881f58c4f9 120 void init()
200923317 1:af881f58c4f9 121 {
200923317 1:af881f58c4f9 122 pad.init();
200923317 1:af881f58c4f9 123 lcd.init();
200923317 1:af881f58c4f9 124 lcd.setBrightness(1.0);
200923317 2:a2bb794f830c 125 }
200923317 2:a2bb794f830c 126
200923317 7:13333933413d 127 void ledCycle()
200923317 7:13333933413d 128 {
200923317 7:13333933413d 129 pad.led(1,1); //cycle through LED's on gamepad
200923317 7:13333933413d 130 pad.led(6,1);
200923317 7:13333933413d 131 wait(0.5);
200923317 7:13333933413d 132 pad.led(2,1);
200923317 7:13333933413d 133 pad.led(5,1);
200923317 7:13333933413d 134 wait(0.5);
200923317 7:13333933413d 135 pad.leds_on();
200923317 7:13333933413d 136 wait(0.5);
200923317 7:13333933413d 137 pad.led(1,0);
200923317 7:13333933413d 138 pad.led(6,0);
200923317 7:13333933413d 139 wait(0.5);
200923317 7:13333933413d 140 pad.led(2,0);
200923317 7:13333933413d 141 pad.led(5,0);
200923317 7:13333933413d 142 wait(0.5);
200923317 7:13333933413d 143 pad.leds_off();
200923317 7:13333933413d 144 wait(0.5);
200923317 7:13333933413d 145 }
200923317 7:13333933413d 146
200923317 7:13333933413d 147 /**
200923317 7:13333933413d 148 *
200923317 7:13333933413d 149 */
200923317 2:a2bb794f830c 150 void drawStart()
200923317 2:a2bb794f830c 151 {
200923317 7:13333933413d 152 sc.Start(lcd);
200923317 2:a2bb794f830c 153
200923317 4:713ac9379ac6 154 while( pad.check_event(Gamepad::START_PRESSED) == false) { // until start is pressed, this loop cycles
200923317 7:13333933413d 155 ledCycle();
200923317 2:a2bb794f830c 156 }
200923317 6:6e9a415436e0 157 wait(0.5);
200923317 6:6e9a415436e0 158 pad.init();
200923317 6:6e9a415436e0 159 lcd.clear();
200923317 2:a2bb794f830c 160 }
200923317 2:a2bb794f830c 161
200923317 6:6e9a415436e0 162 void select(int x,int y)
200923317 2:a2bb794f830c 163 {
200923317 6:6e9a415436e0 164
200923317 6:6e9a415436e0 165 lcd.setPixel(x,y);
200923317 6:6e9a415436e0 166 lcd.setPixel(x-1,y+1);
200923317 6:6e9a415436e0 167 lcd.setPixel(x-1,y-1);
200923317 6:6e9a415436e0 168 lcd.refresh();
200923317 2:a2bb794f830c 169 }
200923317 2:a2bb794f830c 170
200923317 6:6e9a415436e0 171 void deselect(int _x,int _y)
200923317 2:a2bb794f830c 172 {
200923317 6:6e9a415436e0 173
200923317 6:6e9a415436e0 174 lcd.setPixel(_x,_y,false);
200923317 6:6e9a415436e0 175 lcd.setPixel(_x-1,_y+1,false);
200923317 6:6e9a415436e0 176 lcd.setPixel(_x-1,_y-1,false);
200923317 6:6e9a415436e0 177 lcd.refresh();
200923317 2:a2bb794f830c 178 }
200923317 2:a2bb794f830c 179
200923317 4:713ac9379ac6 180 void balls() //show the pokeballs on the screen for player to choose from
200923317 2:a2bb794f830c 181 {
200923317 6:6e9a415436e0 182 sp.ball(lcd, pad);
200923317 2:a2bb794f830c 183 lcd.refresh();
200923317 7:13333933413d 184 wait(1.0);
200923317 2:a2bb794f830c 185 }
200923317 5:add0351183be 186
200923317 4:713ac9379ac6 187 float drawPartner() //choice of pokeball
200923317 2:a2bb794f830c 188 {
200923317 6:6e9a415436e0 189 lcd.clear();
200923317 6:6e9a415436e0 190 int offset = 1;
200923317 2:a2bb794f830c 191 while(pad.check_event(Gamepad::A_PRESSED) == false) {
200923317 6:6e9a415436e0 192 int _d = pad.get_direction();
200923317 6:6e9a415436e0 193 if(_d == E && offset == 1||_d == E && offset == 0) {
200923317 6:6e9a415436e0 194 offset = offset + 1;
200923317 6:6e9a415436e0 195 } else if(_d == W && offset == 1 || _d == W && offset == 2 ) {
200923317 6:6e9a415436e0 196 offset = offset - 1;
200923317 2:a2bb794f830c 197 }
200923317 2:a2bb794f830c 198 if(offset == 0) {
200923317 6:6e9a415436e0 199 deselect(33,25);
200923317 6:6e9a415436e0 200 deselect(57,25);
200923317 6:6e9a415436e0 201 select(9,25);
200923317 2:a2bb794f830c 202 balls();
200923317 2:a2bb794f830c 203 } else if(offset == 1) {
200923317 6:6e9a415436e0 204 deselect(9,25);
200923317 6:6e9a415436e0 205 deselect(57,25);
200923317 6:6e9a415436e0 206 select(33,25);
200923317 2:a2bb794f830c 207 balls();
200923317 2:a2bb794f830c 208 } else if(offset == 2) {
200923317 6:6e9a415436e0 209 deselect(9,25);
200923317 6:6e9a415436e0 210 deselect(33,25);
200923317 6:6e9a415436e0 211 select(57,25);
200923317 2:a2bb794f830c 212 balls();
200923317 2:a2bb794f830c 213 }
200923317 2:a2bb794f830c 214 }
200923317 6:6e9a415436e0 215 wait(0.5);
200923317 6:6e9a415436e0 216 pad.init();
200923317 2:a2bb794f830c 217 return offset;
200923317 7:13333933413d 218 }
200923317 6:6e9a415436e0 219
200923317 7:13333933413d 220 float YesNo()
200923317 7:13333933413d 221 {
200923317 7:13333933413d 222 lcd.printString("Are you",0,2);
200923317 7:13333933413d 223 lcd.printString(" sure??",0,3);
200923317 7:13333933413d 224 lcd.printString("A-Yes",50,1);
200923317 7:13333933413d 225 lcd.printString("B-No",50,5);
200923317 7:13333933413d 226 lcd.refresh();
200923317 7:13333933413d 227 int end = 0;
200923317 7:13333933413d 228 wait(1.0);
200923317 7:13333933413d 229 while(end == 0) {
200923317 7:13333933413d 230 lcd.refresh();
200923317 7:13333933413d 231 if(pad.check_event(Gamepad::A_PRESSED)== true) { //choose yes
200923317 7:13333933413d 232 end = 1;
200923317 7:13333933413d 233 } else if(pad.check_event(Gamepad::B_PRESSED)== true) {//choose no
200923317 7:13333933413d 234 end = 2;
200923317 7:13333933413d 235 }
200923317 7:13333933413d 236 lcd.refresh();
200923317 7:13333933413d 237 }
200923317 7:13333933413d 238 return end;
200923317 2:a2bb794f830c 239 }
200923317 2:a2bb794f830c 240
200923317 4:713ac9379ac6 241 float partnerChoice(int choice) //shows pokemon inside ball, gives choice to choose that mon
200923317 2:a2bb794f830c 242 {
200923317 2:a2bb794f830c 243 lcd.clear();
200923317 2:a2bb794f830c 244 if(choice == 0) {
200923317 6:6e9a415436e0 245 sp.bulbasaur(lcd, pad); //grass starter
200923317 2:a2bb794f830c 246 } else if(choice == 1) {
200923317 6:6e9a415436e0 247 sp.charmander(lcd, pad);//fire starter
200923317 2:a2bb794f830c 248 } else if(choice == 2) {
200923317 6:6e9a415436e0 249 sp.squirtle(lcd, pad);//water starter
200923317 2:a2bb794f830c 250 }
200923317 6:6e9a415436e0 251 lcd.refresh();
200923317 6:6e9a415436e0 252 wait(3.5);
200923317 6:6e9a415436e0 253 lcd.clear();
200923317 7:13333933413d 254 int end = YesNo();
200923317 6:6e9a415436e0 255 wait(0.5);
200923317 6:6e9a415436e0 256 pad.init();
200923317 6:6e9a415436e0 257 return end;
200923317 4:713ac9379ac6 258
200923317 2:a2bb794f830c 259 }
200923317 2:a2bb794f830c 260
200923317 4:713ac9379ac6 261 void choice(int p) //sets up class for your chosen starter
200923317 2:a2bb794f830c 262 {
200923317 2:a2bb794f830c 263 lcd.clear();
200923317 2:a2bb794f830c 264 if (p == 0) {
200923317 2:a2bb794f830c 265 pk.setType(Grass);
200923317 2:a2bb794f830c 266 lcd.printString("You Chose",16,2);
200923317 2:a2bb794f830c 267 lcd.printString("Bulbasaur",15,3);
200923317 2:a2bb794f830c 268 } else if (p == 1) {
200923317 2:a2bb794f830c 269 pk.setType(Fire);
200923317 2:a2bb794f830c 270 lcd.printString("You Chose",16,2);
200923317 2:a2bb794f830c 271 lcd.printString("Charmander",15,3);
200923317 2:a2bb794f830c 272 } else if (p == 2) {
200923317 2:a2bb794f830c 273 pk.setType(Water);
200923317 2:a2bb794f830c 274 lcd.printString("You Chose ",16,2);
200923317 2:a2bb794f830c 275 lcd.printString("Squirtle",15,3);
200923317 2:a2bb794f830c 276 }
200923317 2:a2bb794f830c 277 }
200923317 2:a2bb794f830c 278
200923317 5:add0351183be 279 void menu()
200923317 5:add0351183be 280 {
200923317 5:add0351183be 281 lcd.clear();
200923317 6:6e9a415436e0 282 lcd.printString("FIGHT",8,1);
200923317 6:6e9a415436e0 283 lcd.printString("POKEMON",8,3);
200923317 6:6e9a415436e0 284 lcd.printString("SETTINGS",8,5);
200923317 5:add0351183be 285 }
200923317 2:a2bb794f830c 286
200923317 3:b4de529de482 287 float drawMenu()
200923317 3:b4de529de482 288 {
200923317 5:add0351183be 289 menu();
200923317 6:6e9a415436e0 290 int Xo = 6;
200923317 5:add0351183be 291 int Yo = 11;
200923317 6:6e9a415436e0 292 select(Xo, Yo);
200923317 5:add0351183be 293 lcd.refresh();
200923317 5:add0351183be 294 wait(1.0);
200923317 5:add0351183be 295 int box = 0;
200923317 5:add0351183be 296 while( pad.check_event(Gamepad::A_PRESSED) == false) {
200923317 5:add0351183be 297 int d = pad.get_direction();
200923317 6:6e9a415436e0 298 if (d == S && box == 0 ||d == S && box == 1) {
200923317 6:6e9a415436e0 299 deselect(Xo,Yo);
200923317 5:add0351183be 300 Yo = Yo + 16;
200923317 6:6e9a415436e0 301 select(Xo,Yo);
200923317 5:add0351183be 302 lcd.refresh();
200923317 5:add0351183be 303 box = box + 1;
200923317 5:add0351183be 304 wait(1.0);
200923317 6:6e9a415436e0 305 } else if (d == N && box == 1||d == N && box == 2) {
200923317 6:6e9a415436e0 306 deselect(Xo,Yo);
200923317 5:add0351183be 307 Yo = Yo - 16;
200923317 6:6e9a415436e0 308 select(Xo,Yo);
200923317 5:add0351183be 309 lcd.refresh();
200923317 5:add0351183be 310 box = box - 1;
200923317 5:add0351183be 311 wait(1.0);
200923317 5:add0351183be 312 }
200923317 5:add0351183be 313 }
200923317 5:add0351183be 314 return box;
200923317 3:b4de529de482 315 }
200923317 5:add0351183be 316
200923317 7:13333933413d 317 float rndm(int RA)
200923317 7:13333933413d 318 {
200923317 7:13333933413d 319 int R = rand() %2;
200923317 7:13333933413d 320
200923317 7:13333933413d 321 if (R ==1) {
200923317 7:13333933413d 322 } else {
200923317 7:13333933413d 323 if ( RA <= 6 ) {
200923317 7:13333933413d 324 R = R;
200923317 7:13333933413d 325 } else if ( RA >= 13 ) {
200923317 7:13333933413d 326 R = R + 4;
200923317 7:13333933413d 327 } else {
200923317 7:13333933413d 328 R = R + 2;
200923317 7:13333933413d 329 }
200923317 7:13333933413d 330 }
200923317 7:13333933413d 331 return R;
200923317 7:13333933413d 332 }
200923317 7:13333933413d 333 void battleStats()
200923317 7:13333933413d 334 {
200923317 7:13333933413d 335 std::string pkn = pk.Name();
200923317 7:13333933413d 336 std::string pkl = pk.Level();
200923317 7:13333933413d 337 char aa[50];
200923317 7:13333933413d 338 char bb[50];
200923317 7:13333933413d 339 strncpy(aa, pkn.c_str(), sizeof(aa));
200923317 7:13333933413d 340 strncpy(bb, pkl.c_str(), sizeof(bb));
200923317 7:13333933413d 341 lcd.printString(aa,2,4);
200923317 7:13333933413d 342 lcd.printString(bb,2,5);
200923317 7:13333933413d 343 lcd.refresh();
200923317 7:13333933413d 344 wait(2.0);
200923317 7:13333933413d 345 lcd.clear();
200923317 7:13333933413d 346 lcd.printString(aa,2,4);
200923317 7:13333933413d 347 }
200923317 7:13333933413d 348
200923317 3:b4de529de482 349 void drawFight()
200923317 3:b4de529de482 350 {
200923317 6:6e9a415436e0 351 lcd.clear();
200923317 6:6e9a415436e0 352 srand(time(NULL));
200923317 6:6e9a415436e0 353 std::string PokemonNames[18] = {"Charmander","Cyndaquil","Torchic","Chimchar","Tepig","Fennekin","Bulbasaur","Chikorita","Treeko","Turtwig","Snivy","Chespin","Squirtle","Totodile","Mudkip","Piplup","Oshawott","Froakie"};
200923317 6:6e9a415436e0 354 Pokemon enemy[6] = {Pokemon(5,20,Fire), Pokemon(10,30,Fire), Pokemon(5,20,Grass), Pokemon(10,30,Grass), Pokemon(5,20,Water), Pokemon(10,30,Water)};
200923317 6:6e9a415436e0 355 int ene = rand() % 18;
200923317 7:13333933413d 356 int ene2 = rndm(ene);
200923317 6:6e9a415436e0 357 std::string Pokename = PokemonNames[ene];
200923317 6:6e9a415436e0 358 Pokemon opponent = enemy[ene2];
200923317 6:6e9a415436e0 359 char buffer[64];
200923317 6:6e9a415436e0 360 std::string nameStr = Pokename;
200923317 6:6e9a415436e0 361 strncpy(buffer, nameStr.c_str(), sizeof(buffer));
200923317 6:6e9a415436e0 362 lcd.printString("A wild",25,2);
200923317 6:6e9a415436e0 363 lcd.printString(buffer,18,3);
200923317 6:6e9a415436e0 364 lcd.printString("appeared",20,4);
200923317 6:6e9a415436e0 365 lcd.refresh();
200923317 6:6e9a415436e0 366 wait(2.0);
200923317 6:6e9a415436e0 367 lcd.clear();
200923317 6:6e9a415436e0 368 lcd.printString(buffer,35,0);
200923317 7:13333933413d 369 lcd.printString("LVL:??",35,1);
200923317 7:13333933413d 370 battleStats();
200923317 6:6e9a415436e0 371 lcd.printString(buffer,35,0);
200923317 6:6e9a415436e0 372 char HP1[10];
200923317 6:6e9a415436e0 373 char HP2[10];
200923317 6:6e9a415436e0 374 int HPOT;
200923317 6:6e9a415436e0 375 int HPAT;
200923317 6:6e9a415436e0 376 int HPO = HPOT = pk.HPO(opponent);
200923317 6:6e9a415436e0 377 int HPA = HPAT = pk.HPA();
200923317 6:6e9a415436e0 378 int win = 0; //1 = win, 2 = loss, 3 = draw
200923317 6:6e9a415436e0 379 // After HP cycles past 0, The HP counter goes to above 429,000,000 ;
200923317 7:13333933413d 380 //
200923317 6:6e9a415436e0 381 while ( win == 0 ) {
200923317 6:6e9a415436e0 382 HPAT = HPAT - pk.OpponentTurn(opponent);
200923317 6:6e9a415436e0 383 HPOT = HPOT - pk.YourTurn(opponent);
200923317 6:6e9a415436e0 384 wait(1.5);
200923317 6:6e9a415436e0 385 if( HPOT >> HPO) {
200923317 6:6e9a415436e0 386 win = 1;
200923317 6:6e9a415436e0 387 lcd.printString("HP:0",2,5);
200923317 7:13333933413d 388 pk.win(lcd);
200923317 6:6e9a415436e0 389 } else if( HPAT >> HPA) {
200923317 6:6e9a415436e0 390 win = 2;
200923317 6:6e9a415436e0 391 lcd.printString("HP:0",35,1);
200923317 6:6e9a415436e0 392 } else if( HPOT >> HPO && HPAT >> HPA) {
200923317 6:6e9a415436e0 393 win = 3;
200923317 6:6e9a415436e0 394 lcd.printString("HP:0",2,5);
200923317 6:6e9a415436e0 395 lcd.printString("HP:0",35,1);
200923317 6:6e9a415436e0 396 } else {
200923317 7:13333933413d 397 lcd.drawRect(2,40,50,8,FILL_WHITE);
200923317 7:13333933413d 398 lcd.drawRect(35,8,50,8,FILL_WHITE);
200923317 6:6e9a415436e0 399 sprintf(HP1, "HP:%u",HPAT);
200923317 6:6e9a415436e0 400 sprintf(HP2, "HP:%u",HPOT);
200923317 6:6e9a415436e0 401 lcd.printString(HP1,2,5);
200923317 6:6e9a415436e0 402 lcd.printString(HP2,35,1);
200923317 6:6e9a415436e0 403 lcd.refresh();
200923317 6:6e9a415436e0 404 }
200923317 6:6e9a415436e0 405 }
200923317 7:13333933413d 406 sc.Battle(lcd, win);
200923317 6:6e9a415436e0 407 lcd.refresh();
200923317 6:6e9a415436e0 408 wait(2.0);
200923317 6:6e9a415436e0 409 pad.init();
200923317 3:b4de529de482 410 }
200923317 6:6e9a415436e0 411
200923317 3:b4de529de482 412 void drawPoke()
200923317 3:b4de529de482 413 {
200923317 5:add0351183be 414 lcd.clear();
200923317 5:add0351183be 415 while(pad.check_event(Gamepad::B_PRESSED) == false) {
200923317 5:add0351183be 416 std::string pkn = pk.Name();
200923317 5:add0351183be 417 std::string pkl = pk.Level();
200923317 5:add0351183be 418 std::string pkh = pk.HP();
200923317 5:add0351183be 419 std::string pkt = pk.Type();
200923317 5:add0351183be 420 char a[50];
200923317 5:add0351183be 421 char b[50];
200923317 5:add0351183be 422 char c[50];
200923317 5:add0351183be 423 char d[50];
200923317 5:add0351183be 424 strncpy(a, pkn.c_str(), sizeof(a));
200923317 5:add0351183be 425 strncpy(b, pkl.c_str(), sizeof(b));
200923317 5:add0351183be 426 strncpy(c, pkt.c_str(), sizeof(c));
200923317 5:add0351183be 427 strncpy(d, pkh.c_str(), sizeof(d));
200923317 5:add0351183be 428 lcd.printString("Pokemon:",2,0);
200923317 5:add0351183be 429 lcd.printString(a,2,1);
200923317 5:add0351183be 430 lcd.printString(b,2,2);
200923317 5:add0351183be 431 lcd.printString(c,2,3);
200923317 5:add0351183be 432 lcd.printString(d,2,4);
200923317 5:add0351183be 433 lcd.printString(" B = Back ",24,5);
200923317 5:add0351183be 434 lcd.refresh();
200923317 5:add0351183be 435 }
200923317 3:b4de529de482 436 }
200923317 5:add0351183be 437
200923317 3:b4de529de482 438 void settings()
200923317 3:b4de529de482 439 {
200923317 5:add0351183be 440 lcd.clear();
200923317 5:add0351183be 441 int bright = 1;
200923317 6:6e9a415436e0 442 lcd.printString("SET BRIGHTNESS", 2, 20);
200923317 6:6e9a415436e0 443 lcd.printString("B = BACK", 4, 20);
200923317 6:6e9a415436e0 444 lcd.refresh();
200923317 5:add0351183be 445 while(pad.check_event(Gamepad::B_PRESSED) == false) {
200923317 5:add0351183be 446 bright = pad.read_pot();
200923317 5:add0351183be 447 float brightness = 0.5*bright;
200923317 5:add0351183be 448 lcd.setBrightness(brightness);
200923317 6:6e9a415436e0 449 lcd.refresh();
200923317 5:add0351183be 450 }
200923317 3:b4de529de482 451 }
200923317 2:a2bb794f830c 452