Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Revision:
4:db929dab4f13
Parent:
2:532b0225519f
Child:
5:02e7b5197827
--- a/classes/FishEngine.cpp	Wed Mar 24 15:32:13 2021 +0000
+++ b/classes/FishEngine.cpp	Wed Mar 24 16:02:53 2021 +0000
@@ -6,7 +6,10 @@
 
 //attach
 BusOut RGB_led(p24,p23,p22); //RGB bus MSB - LSB, inverted logic 1 = low
-DigitalIn button_A (p29);
+DigitalIn button_A(p29);
+DigitalIn button_B(p28);
+DigitalIn button_C(p27);
+DigitalIn button_D(p26);
 
 //objects
 ShiftReg shift;
@@ -20,11 +23,14 @@
     dac.init();
     shift.write(0x00);
     RGB_led.write(0b111);
+    button_A.mode(PullNone);
+    button_B.mode(PullNone);
+    button_C.mode(PullNone);
+    button_D.mode(PullNone);
 }
 
 // creates intro sequence
 void FishEngine::titleSequence(N5110 &lcd){
-    button_A.mode(PullNone);
     lcd.clear();
     graphics.titleScreen(lcd); //prints titlescreen (held in graphics.h)
     lcd.refresh();
@@ -94,7 +100,12 @@
         
         //implement state machine
         switch(state) {
+            
+            //case for new game
             case 0:
+                if(button_A.read()){
+                    gamePlay(lcd,dac);
+                }
                 switch(direction) {
                     case UP:
                         state = 3;
@@ -107,7 +118,12 @@
                         break;
                 }
                 break;
+                
+            //case for HighScore
             case 1:
+                if(button_A.read()){
+                    highScore(lcd);
+                }
                 switch(direction) {
                     case UP:
                         state = 0;
@@ -120,7 +136,12 @@
                         break;
                 }
                 break;
+                
+            //case for how to play    
             case 2:
+                if(button_A.read()){
+                    Instructions(lcd);
+                }
                 switch(direction) {
                     case UP:
                         state = 1;
@@ -133,7 +154,12 @@
                         break;
                 }
                 break;
+                
+            //case for settings    
             case 3:
+                if(button_A.read()){
+                    Settings(lcd, dac);    
+                }
                 switch(direction) {
                     case UP:
                         state = 2;
@@ -144,6 +170,7 @@
                     case CENTRE: 
                         state = 3;
                         break;
+                    
                 }
                 break;
             default:
@@ -158,3 +185,54 @@
     }
 }
 
+// function for game play
+void FishEngine::gamePlay(N5110 &lcd, Tone &dac){
+    graphics.screenFlash(lcd);
+    
+    do{
+        lcd.clear();
+        lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border
+        lcd.printString(" Play game", 10, 2);
+        lcd.refresh();
+        wait_ms(1000/10);
+    }while(button_B.read() == false);
+}
+
+//function for viewing high score
+void FishEngine::highScore(N5110 &lcd){
+    graphics.screenFlash(lcd);
+    
+    do{
+        lcd.clear();
+        lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border
+        lcd.printString(" High score", 10, 2);
+        lcd.refresh();
+        wait_ms(1000/10);
+    }while(button_B.read() == false);
+}
+
+//function for providing instruction on how to play
+void FishEngine::Instructions(N5110 &lcd){
+    graphics.screenFlash(lcd);
+    
+    do{
+        lcd.clear();
+        lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border
+        lcd.printString(" How to play", 10, 2);
+        lcd.refresh();
+        wait_ms(1000/10);
+    }while(button_B.read() == false);
+}
+
+//functions for changing settings
+void FishEngine::Settings(N5110 &lcd, Tone &dac){
+    graphics.screenFlash(lcd);
+    
+    do{
+        lcd.clear();
+        lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border
+        lcd.printString(" settings", 10, 2);
+        lcd.refresh();
+        wait_ms(1000/10);
+    }while(button_B.read() == false);
+}