Joshua O'hara 201291390

Dependencies:   mbed

Revision:
24:ff5af5a013b5
Parent:
23:aa86e32b6a74
Child:
33:d8284dee58db
--- a/main.cpp	Thu May 14 08:33:06 2020 +0000
+++ b/main.cpp	Thu May 14 17:35:35 2020 +0000
@@ -21,7 +21,6 @@
 #define ALIEN_SIZE 4
 #define ROW_SIZE 3
 #define COLUMN_SIZE 5
-#define NUMBER_OF_ALIENS 10
 #define COVER_Y 38
 #define COVER1_X 9
 #define COVER2_X 34
@@ -46,18 +45,33 @@
 void start_menu();
 void game_over(int level);
 void next_level(int level);
-void update_game(UserInput input);
+//void update_game(UserInput input);
+void select_difficulty();
+
+int fps;
+int counter;
+int level;
+int difficulty;
+int number_of_aliens;
+bool armada_life;
+bool ship_life;
+
+Direction direction;
 
 int main()
 {
-    int fps = 6;
-    int counter = 0;
-    int level = 1;
-    bool armada_life = true;
-    bool ship_life = true;
+    fps = 6;
+    counter = 0;
+    level = 1;
+    armada_life = true;
+    ship_life = true;
     
     hardware_init();
     start_menu();
+    select_difficulty();
+    
+    number_of_aliens = 5*difficulty;
+    
     draw_game();
     wait(1.0f/fps);
     
@@ -67,7 +81,7 @@
     next_level(level);
     while(1) {
         SpaceInvader.read_input(pad);
-        SpaceInvader.update(pad, lcd, counter);
+        SpaceInvader.update(pad, lcd, counter, level);
         draw_game();
         wait(1.0f/fps);
         counter++;
@@ -113,7 +127,7 @@
 }
 void game_init()
 {
-    SpaceInvader.init(SHIP_HEIGHT,SHIP_WIDTH,ALIEN_SIZE,NUMBER_OF_ALIENS,COLUMN_SIZE,ROW_SIZE,COVER_Y,COVER1_X,COVER2_X,COVER3_X,ROCK_NUMBER);   
+    SpaceInvader.init(SHIP_HEIGHT,SHIP_WIDTH,ALIEN_SIZE,number_of_aliens,COLUMN_SIZE,ROW_SIZE,COVER_Y,COVER1_X,COVER2_X,COVER3_X,ROCK_NUMBER,level);   
 }
 
 void game_over(int level){
@@ -137,4 +151,67 @@
     wait(2);
     lcd.clear();
     }
-  
\ No newline at end of file
+  
+void select_difficulty(){
+    difficulty = 1;
+    bool select = false;
+    
+    while(select == false){
+        lcd.clear();
+        lcd.printString("  Easy",0,0);
+        lcd.printString("  Medium",0,2);
+        lcd.printString("  Hard",0,4);
+        if(difficulty == 1){
+            lcd.drawRect(0,0,3,3,FILL_BLACK);
+        }
+        if(difficulty == 2){
+            lcd.drawRect(0,20,3,3,FILL_BLACK);
+        }
+        if(difficulty == 3){
+            lcd.drawRect(0,40,3,3,FILL_BLACK);
+        }
+        lcd.refresh();
+        wait(1);
+        
+        while(1){    
+            direction = pad.get_direction();
+            if(pad.A_pressed()==true){
+                select = true;
+                break;
+                }
+            if((difficulty==1)&&
+            (direction==N)){
+                difficulty = 3;
+                break;  
+            }
+            if((difficulty==1)&&
+            (direction==S)){
+                difficulty = 2;
+                break;
+            }
+            if((difficulty==2)&&
+            (direction==N)){
+                difficulty = 1; 
+                break;  
+            }
+            if((difficulty==2)&&
+            (direction==S)){
+                difficulty = 3;
+                break;
+            }
+            if((difficulty==3)&&
+            (direction==N)){
+                difficulty = 2;
+                break;
+            }
+            if((difficulty==3)&&
+            (direction==S)){
+                difficulty = 1;
+                break;
+            }
+        }
+        //printf("   difficulty %2d",direction);
+    }
+}
+            
+    
\ No newline at end of file