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)

Revision:
2:a2bb794f830c
Parent:
1:af881f58c4f9
Child:
3:b4de529de482
--- a/main.cpp	Thu Apr 20 15:35:28 2017 +0000
+++ b/main.cpp	Thu Apr 20 17:27:48 2017 +0000
@@ -10,6 +10,7 @@
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
 Pokemon pk;
+Sprites sp;
 //--------------------------- Structs/Typedefs ---------------------------------
 struct joyInput {
     Direction d; //direction of joystick to navigate menu's
@@ -20,14 +21,15 @@
 
 void init();
 void drawStart();
-void drawPartner();
-void partner1();
-void partner2();
-void partner3();
+void select(int x, int y, int L);
+void deselect(int _x, int _y, int _L);
+void balls();
+float drawPartner();
+float partnerChoice(int choice);
+void choice(int p);
 float drawMenu();
 void drawFight();
 void drawPoke();
-void select();
 void menu();
 void settings();
 
@@ -38,12 +40,192 @@
     init();
     drawStart();
     Gamepage state = START;
-    
-    
+//-----------------------GAME LOOP START-------------------------------
+    while(1) {
+        if (state == START) {
+            state = PARTNER;
+            
+        } else if (state == PARTNER) {
+            int partner = drawPartner();
+            int correct = partnerChoice(partner);
+            if( correct == 1) {
+                state = PARTNER;
+            } else if(correct == 0) {
+                choice(partner);
+                lcd.refresh();
+                state = MENU;
+            }
+        
+        } else if (state == FIGHT) {
+            state = MENU;
+            
+        } else if (state == SETTINGS) {
+            state = MENU;
+            
+        } else if (state == MENU) {
+            wait(1.0);
+            int box = drawMenu();
+            if (box == 0) {
+                state = FIGHT;
+                lcd.clear();
+                lcd.printString("FIGHT",8,2);
+            } else if (box ==1) {
+                state = POKEMON;
+                lcd.clear();
+                lcd.printString("POKEMON",20,4);
+            } else if (box ==2) {
+                state = SETTINGS;
+                lcd.clear();
+                lcd.printString("SETTINGS",50,2);
+            }
+            lcd.refresh();
+            wait(2.0);
+            lcd.clear();
+            
+        } else if (state == POKEMON) {
+            state = MENU;
+            drawPoke();
+        }
+    }
+}
+
+
 
 void init()
 {
     pad.init();
     lcd.init();
     lcd.setBrightness(1.0);
-}
\ No newline at end of file
+}
+
+void  drawStart()
+{
+
+    lcd.printString("  Welcome to  ",0,0);
+    lcd.printString(" the World of ",0,1);
+    lcd.printString("    Pokemon   ",0,2);
+    lcd.printString("  Press Start ",0,4);
+    lcd.refresh();
+
+    while( pad.check_event(Gamepad::START_PRESSED) == false) {
+        pad.led(1,1);
+        pad.led(6,1);
+        wait(0.5);
+        pad.led(2,1);
+        pad.led(5,1);
+        wait(0.5);
+        pad.leds_on();
+        wait(0.5);
+        pad.led(1,0);
+        pad.led(6,0);
+        wait(0.5);
+        pad.led(2,0);
+        pad.led(5,0);
+        wait(0.5);
+        pad.leds_off();
+        wait(0.5);
+    }
+    wait(1.0);
+}
+
+void select(int x,int y, int L)
+{
+    lcd.drawRect(x,y,L,L,FILL_TRANSPARENT);
+}
+
+void select(int _x,int _y, int _L)
+{
+    lcd.drawRect(_x,_y,_L,_L,2);
+}
+
+void balls()
+{
+    sp.ball(11,18);
+    sp.ball(35,18);
+    sp.ball(59,18);
+    lcd.refresh();
+}
+
+float drawPartner()
+{
+    select(9,16,15);
+    int offset = 0;
+    int _d = pad.get_direction();
+    while(pad.check_event(Gamepad::A_PRESSED) == false) {
+        if(_d == E && offset <= 1) {
+            offset ++;
+        } else if(_d == W && offset >=1) {
+            offset --;
+        }
+        if(offset == 0) {
+            deselect(57,16,15);
+            deselect(33,16,15);
+            select(9,16,15);
+            balls();
+        } else if(offset == 1) {
+            deselect(57,16,15);
+            deselect(9,16,15);
+            select(33,16,15);
+            balls();
+        } else if(offset == 2) {
+            deselect(9,16,15);
+            deselect(33,16,15);
+            select(57,16,15);
+            balls();
+        }
+    }
+    return offset;
+}
+
+float partnerChoice(int choice)
+{
+    lcd.clear();
+    int _d = pad.get_direction();
+    if(choice == 0) {
+        sp.bulbasaur(16,0);
+    } else if(choice == 1) {
+        sp.charmander(16,0);
+    } else if(choice == 2) {
+        sp.squirtle(16,0);
+    }
+    lcd.printString("Are you",0,2);
+    lcd.printString(" sure??",0,3);
+    lcd.refresh();
+    while(pad.check_event(Gamepad::A_PRESSED) == false {
+    lcd.printString("Yes",65,1);
+        lcd.printString("No",65,5);
+        select(62,6,8);
+        lcd.refresh();
+        int offset1 = 0;
+        if(offset1 == 0 && _d == S) {
+            deselect(62,6,8);
+            select(62,6,8);
+        } else if(offset1 == 1 && _d ==N) {
+            deselect(62,38,8);
+            select(62,38,8);
+        }
+    }
+    return offset1;
+}
+
+void choice(int p)
+{
+    lcd.clear();
+    if (p == 0) {
+        pk.setType(Grass);
+        lcd.printString("You Chose",16,2);
+        lcd.printString("Bulbasaur",15,3);
+    } else if (p == 1) {
+        pk.setType(Fire);
+        lcd.printString("You Chose",16,2);
+        lcd.printString("Charmander",15,3);
+    } else if (p == 2) {
+        pk.setType(Water);
+        lcd.printString("You Chose ",16,2);
+        lcd.printString("Squirtle",15,3);
+    }
+}
+
+
+
+