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:
Mon Apr 24 23:22:10 2017 +0000
Revision:
4:713ac9379ac6
Parent:
3:b4de529de482
Child:
5:add0351183be
commenting ;

Who changed what in which revision?

UserRevisionLine numberNew 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 2:a2bb794f830c 25 void select(int x, int y, int L);
200923317 2:a2bb794f830c 26 void deselect(int _x, int _y, int _L);
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 4:713ac9379ac6 49 } else if (state == PARTNER) { //choosing your partner
200923317 2:a2bb794f830c 50 int partner = drawPartner();
200923317 2:a2bb794f830c 51 int correct = partnerChoice(partner);
200923317 2:a2bb794f830c 52 if( correct == 1) {
200923317 2:a2bb794f830c 53 state = PARTNER;
200923317 2:a2bb794f830c 54 } else if(correct == 0) {
200923317 2:a2bb794f830c 55 choice(partner);
200923317 2:a2bb794f830c 56 lcd.refresh();
200923317 2:a2bb794f830c 57 state = MENU;
200923317 2:a2bb794f830c 58 }
200923317 3:b4de529de482 59
200923317 4:713ac9379ac6 60 } else if (state == FIGHT) { //fight with wild pokemon
200923317 2:a2bb794f830c 61 state = MENU;
200923317 3:b4de529de482 62
200923317 4:713ac9379ac6 63 } else if (state == SETTINGS) { //settings, screen brightness
200923317 2:a2bb794f830c 64 state = MENU;
200923317 3:b4de529de482 65
200923317 4:713ac9379ac6 66 } else if (state == MENU) { // main menu
200923317 2:a2bb794f830c 67 wait(1.0);
200923317 2:a2bb794f830c 68 int box = drawMenu();
200923317 2:a2bb794f830c 69 if (box == 0) {
200923317 2:a2bb794f830c 70 state = FIGHT;
200923317 2:a2bb794f830c 71 lcd.clear();
200923317 2:a2bb794f830c 72 lcd.printString("FIGHT",8,2);
200923317 2:a2bb794f830c 73 } else if (box ==1) {
200923317 2:a2bb794f830c 74 state = POKEMON;
200923317 2:a2bb794f830c 75 lcd.clear();
200923317 2:a2bb794f830c 76 lcd.printString("POKEMON",20,4);
200923317 2:a2bb794f830c 77 } else if (box ==2) {
200923317 2:a2bb794f830c 78 state = SETTINGS;
200923317 2:a2bb794f830c 79 lcd.clear();
200923317 2:a2bb794f830c 80 lcd.printString("SETTINGS",50,2);
200923317 2:a2bb794f830c 81 }
200923317 2:a2bb794f830c 82 lcd.refresh();
200923317 2:a2bb794f830c 83 wait(2.0);
200923317 2:a2bb794f830c 84 lcd.clear();
200923317 3:b4de529de482 85
200923317 4:713ac9379ac6 86 } else if (state == POKEMON) { //check partner pokemon stats
200923317 2:a2bb794f830c 87 state = MENU;
200923317 2:a2bb794f830c 88 drawPoke();
200923317 2:a2bb794f830c 89 }
200923317 2:a2bb794f830c 90 }
200923317 2:a2bb794f830c 91 }
200923317 2:a2bb794f830c 92
200923317 2:a2bb794f830c 93
200923317 1:af881f58c4f9 94
200923317 1:af881f58c4f9 95 void init()
200923317 1:af881f58c4f9 96 {
200923317 1:af881f58c4f9 97 pad.init();
200923317 1:af881f58c4f9 98 lcd.init();
200923317 1:af881f58c4f9 99 lcd.setBrightness(1.0);
200923317 2:a2bb794f830c 100 }
200923317 2:a2bb794f830c 101
200923317 2:a2bb794f830c 102 void drawStart()
200923317 2:a2bb794f830c 103 {
200923317 2:a2bb794f830c 104
200923317 2:a2bb794f830c 105 lcd.printString(" Welcome to ",0,0);
200923317 2:a2bb794f830c 106 lcd.printString(" the World of ",0,1);
200923317 2:a2bb794f830c 107 lcd.printString(" Pokemon ",0,2);
200923317 2:a2bb794f830c 108 lcd.printString(" Press Start ",0,4);
200923317 2:a2bb794f830c 109 lcd.refresh();
200923317 2:a2bb794f830c 110
200923317 4:713ac9379ac6 111 while( pad.check_event(Gamepad::START_PRESSED) == false) { // until start is pressed, this loop cycles
200923317 4:713ac9379ac6 112 pad.led(1,1); //cycle through LED's on gamepad
200923317 2:a2bb794f830c 113 pad.led(6,1);
200923317 2:a2bb794f830c 114 wait(0.5);
200923317 2:a2bb794f830c 115 pad.led(2,1);
200923317 2:a2bb794f830c 116 pad.led(5,1);
200923317 2:a2bb794f830c 117 wait(0.5);
200923317 2:a2bb794f830c 118 pad.leds_on();
200923317 2:a2bb794f830c 119 wait(0.5);
200923317 2:a2bb794f830c 120 pad.led(1,0);
200923317 2:a2bb794f830c 121 pad.led(6,0);
200923317 2:a2bb794f830c 122 wait(0.5);
200923317 2:a2bb794f830c 123 pad.led(2,0);
200923317 2:a2bb794f830c 124 pad.led(5,0);
200923317 2:a2bb794f830c 125 wait(0.5);
200923317 2:a2bb794f830c 126 pad.leds_off();
200923317 2:a2bb794f830c 127 wait(0.5);
200923317 2:a2bb794f830c 128 }
200923317 2:a2bb794f830c 129 wait(1.0);
200923317 2:a2bb794f830c 130 }
200923317 2:a2bb794f830c 131
200923317 4:713ac9379ac6 132 void select(int x,int y, int L) //select box's
200923317 2:a2bb794f830c 133 {
200923317 4:713ac9379ac6 134 lcd.drawRect(x,y,L,L,FILL_TRANSPARENT);
200923317 2:a2bb794f830c 135 }
200923317 2:a2bb794f830c 136
200923317 4:713ac9379ac6 137 void deselect(int _x,int _y, int _L) //removing select box's
200923317 2:a2bb794f830c 138 {
200923317 3:b4de529de482 139 lcd.drawRect(_x,_y,_L,_L, FILL_WHITE);
200923317 2:a2bb794f830c 140 }
200923317 2:a2bb794f830c 141
200923317 4:713ac9379ac6 142 void balls() //show the pokeballs on the screen for player to choose from
200923317 2:a2bb794f830c 143 {
200923317 2:a2bb794f830c 144 sp.ball(11,18);
200923317 2:a2bb794f830c 145 sp.ball(35,18);
200923317 2:a2bb794f830c 146 sp.ball(59,18);
200923317 2:a2bb794f830c 147 lcd.refresh();
200923317 2:a2bb794f830c 148 }
200923317 4:713ac9379ac6 149
200923317 4:713ac9379ac6 150 float drawPartner() //choice of pokeball
200923317 2:a2bb794f830c 151 {
200923317 2:a2bb794f830c 152 select(9,16,15);
200923317 2:a2bb794f830c 153 int offset = 0;
200923317 2:a2bb794f830c 154 int _d = pad.get_direction();
200923317 2:a2bb794f830c 155 while(pad.check_event(Gamepad::A_PRESSED) == false) {
200923317 2:a2bb794f830c 156 if(_d == E && offset <= 1) {
200923317 2:a2bb794f830c 157 offset ++;
200923317 2:a2bb794f830c 158 } else if(_d == W && offset >=1) {
200923317 2:a2bb794f830c 159 offset --;
200923317 2:a2bb794f830c 160 }
200923317 2:a2bb794f830c 161 if(offset == 0) {
200923317 2:a2bb794f830c 162 deselect(57,16,15);
200923317 2:a2bb794f830c 163 deselect(33,16,15);
200923317 2:a2bb794f830c 164 select(9,16,15);
200923317 2:a2bb794f830c 165 balls();
200923317 2:a2bb794f830c 166 } else if(offset == 1) {
200923317 2:a2bb794f830c 167 deselect(57,16,15);
200923317 2:a2bb794f830c 168 deselect(9,16,15);
200923317 2:a2bb794f830c 169 select(33,16,15);
200923317 2:a2bb794f830c 170 balls();
200923317 2:a2bb794f830c 171 } else if(offset == 2) {
200923317 2:a2bb794f830c 172 deselect(9,16,15);
200923317 2:a2bb794f830c 173 deselect(33,16,15);
200923317 2:a2bb794f830c 174 select(57,16,15);
200923317 2:a2bb794f830c 175 balls();
200923317 2:a2bb794f830c 176 }
200923317 3:b4de529de482 177 lcd.refresh();
200923317 3:b4de529de482 178 wait(0.5);
200923317 2:a2bb794f830c 179 }
200923317 2:a2bb794f830c 180 return offset;
200923317 2:a2bb794f830c 181 }
200923317 2:a2bb794f830c 182
200923317 4:713ac9379ac6 183 float partnerChoice(int choice) //shows pokemon inside ball, gives choice to choose that mon
200923317 2:a2bb794f830c 184 {
200923317 2:a2bb794f830c 185 lcd.clear();
200923317 2:a2bb794f830c 186 int _d = pad.get_direction();
200923317 4:713ac9379ac6 187 int end = 0;
200923317 2:a2bb794f830c 188 if(choice == 0) {
200923317 4:713ac9379ac6 189 sp.bulbasaur(16,0); //grass starter
200923317 2:a2bb794f830c 190 } else if(choice == 1) {
200923317 4:713ac9379ac6 191 sp.charmander(16,0);//fire starter
200923317 2:a2bb794f830c 192 } else if(choice == 2) {
200923317 4:713ac9379ac6 193 sp.squirtle(16,0);//water starter
200923317 2:a2bb794f830c 194 }
200923317 2:a2bb794f830c 195 lcd.printString("Are you",0,2);
200923317 2:a2bb794f830c 196 lcd.printString(" sure??",0,3);
200923317 4:713ac9379ac6 197 lcd.printString("Yes",65,1);
200923317 4:713ac9379ac6 198 lcd.printString("No",65,5);
200923317 4:713ac9379ac6 199 select(62,6,8);
200923317 2:a2bb794f830c 200 lcd.refresh();
200923317 3:b4de529de482 201 while(pad.check_event(Gamepad::A_PRESSED)== false) {
200923317 3:b4de529de482 202 lcd.printString("Yes",65,1);
200923317 2:a2bb794f830c 203 lcd.printString("No",65,5);
200923317 2:a2bb794f830c 204 lcd.refresh();
200923317 4:713ac9379ac6 205 wait(0.25);
200923317 2:a2bb794f830c 206 int offset1 = 0;
200923317 4:713ac9379ac6 207 if(offset1 == 0 && _d == S) { //choose no
200923317 2:a2bb794f830c 208 deselect(62,6,8);
200923317 4:713ac9379ac6 209 select(62,38,8);
200923317 4:713ac9379ac6 210 end = 0;
200923317 4:713ac9379ac6 211 } else if(offset1 == 1 && _d ==N) {//choose yes
200923317 4:713ac9379ac6 212 deselect(62,38,8);
200923317 2:a2bb794f830c 213 select(62,6,8);
200923317 4:713ac9379ac6 214 end = 1;
200923317 2:a2bb794f830c 215 }
200923317 3:b4de529de482 216 return offset1;
200923317 4:713ac9379ac6 217
200923317 2:a2bb794f830c 218 }
200923317 4:713ac9379ac6 219 return end;
200923317 2:a2bb794f830c 220 }
200923317 2:a2bb794f830c 221
200923317 4:713ac9379ac6 222 void choice(int p) //sets up class for your chosen starter
200923317 2:a2bb794f830c 223 {
200923317 2:a2bb794f830c 224 lcd.clear();
200923317 2:a2bb794f830c 225 if (p == 0) {
200923317 2:a2bb794f830c 226 pk.setType(Grass);
200923317 2:a2bb794f830c 227 lcd.printString("You Chose",16,2);
200923317 2:a2bb794f830c 228 lcd.printString("Bulbasaur",15,3);
200923317 2:a2bb794f830c 229 } else if (p == 1) {
200923317 2:a2bb794f830c 230 pk.setType(Fire);
200923317 2:a2bb794f830c 231 lcd.printString("You Chose",16,2);
200923317 2:a2bb794f830c 232 lcd.printString("Charmander",15,3);
200923317 2:a2bb794f830c 233 } else if (p == 2) {
200923317 2:a2bb794f830c 234 pk.setType(Water);
200923317 2:a2bb794f830c 235 lcd.printString("You Chose ",16,2);
200923317 2:a2bb794f830c 236 lcd.printString("Squirtle",15,3);
200923317 2:a2bb794f830c 237 }
200923317 2:a2bb794f830c 238 }
200923317 2:a2bb794f830c 239
200923317 2:a2bb794f830c 240
200923317 3:b4de529de482 241 float drawMenu()
200923317 3:b4de529de482 242 {
200923317 3:b4de529de482 243 }
200923317 3:b4de529de482 244 void drawFight()
200923317 3:b4de529de482 245 {
200923317 3:b4de529de482 246 }
200923317 3:b4de529de482 247 void drawPoke()
200923317 3:b4de529de482 248 {
200923317 3:b4de529de482 249 }
200923317 3:b4de529de482 250 void menu()
200923317 3:b4de529de482 251 {
200923317 3:b4de529de482 252 }
200923317 3:b4de529de482 253 void settings()
200923317 3:b4de529de482 254 {
200923317 3:b4de529de482 255 }
200923317 2:a2bb794f830c 256