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