Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Revision:
11:7c1e2a9303d3
Parent:
10:e221bd1ce3ec
Child:
12:20ac766b3175
--- a/classes/Game.cpp	Tue Apr 20 15:35:00 2021 +0000
+++ b/classes/Game.cpp	Wed Apr 21 11:08:02 2021 +0000
@@ -3,6 +3,8 @@
 ShiftReg _shift;
 Graphics _graphics; 
 
+BusOut _RGB_led(p24,p23,p22); //RGB bus MSB - LSB, inverted logic 1 = low
+
 //plays the game
 void Game::gamePlay(N5110 &lcd, DIRECTION direction){ 
     lcd.clear();
@@ -13,7 +15,7 @@
     //check if enemy fish if fully off screen
     if(X == -24){
         X = 85; //reset enemy fish position to 85
-        Y = rand() % 36 + 9; //randomly generate Y position for enemy fish
+        Y = rand() % 36 + 9; //randomly generate new Y position for enemy fish
         E_FISH = rand() % 4 + 1; //randomly select a new enemy fish
     }
     
@@ -122,10 +124,13 @@
     //check play position agains the boundaries of the playing area
     if(_x <= 1){
         _x = 1;
+        
     }else if (x_bound >= 82){
         _x = 82 - FISH_WIDTH;  
+        
     }else if (_y <= 9){
         _y = 9;    
+        
     }else if (y_bound >= 47){
         _y = 47 - FISH_HEIGHT;
     }
@@ -141,12 +146,15 @@
     if (SCORE < 100){
         FISH_SIZE = 1;                          //smallest fish
         barIncrement = 4; //increments the width of the growth bar by 4 pixels
+        
     }else if(SCORE >= 100 && SCORE < 300){
         FISH_SIZE = 2;                          //fish 2
         barIncrement = 2;
+        
     }else if (SCORE >= 300 && SCORE <= 700){
         FISH_SIZE = 3;                          //fish 3
         barIncrement = 1;
+        
     }else if (SCORE >= 700){
         FISH_SIZE = 4;                          //largest fish
         barIncrement = 0;
@@ -156,10 +164,13 @@
     if(check_score != SCORE){
         if(FISH_SIZE == 1){
             rect_width = rect_width + 4;
+            
         }else if(FISH_SIZE == 2){
             rect_width = rect_width + 2;
+            
         }else if(FISH_SIZE == 3){
             rect_width = rect_width + 1;
+            
         }else if(FISH_SIZE == 4){
             rect_width = 40;
         }
@@ -171,6 +182,7 @@
     if(check_width != barIncrement){
         if(FISH_SIZE == 4){ //if largest fish than growth bar is max
             rect_width = 40;
+            
         }else{
             rect_width = 0;
         }
@@ -184,10 +196,13 @@
 int Game::Lives(){
     if (lives == 3){
         _shift.write(0x4F); //write 3
+        
     }else if (lives == 2){
         _shift.write(0x5B); //write 2
+        
     }else if (lives == 1){
         _shift.write(0x06); //write 1
+        
     }else if (lives == 0){
         _shift.write(0x3F); //write 0
     }
@@ -202,14 +217,29 @@
     if((centre_xpos == 2 && centre_ypos <= 1) && (centre_xpos == 2 && centre_ypos >= -1)){
         if(FISH_SIZE < E_FISH){
             //remove one life
-            lives--;    
+            lives--;
+            //flicker busout
+            _RGB_led.write(6); //red
+            wait_ms(100);
+            _RGB_led.write(7); //off  
+             
         }else if(FISH_SIZE >= E_FISH){           
             //increase score by 10
             SCORE = SCORE + 10;
             //remove eaten fish
             X = -23;  
+            //flicker busout
+            i = 0;
+            while(i < 3){
+                colour = rand() % 6 + 1;
+                _RGB_led.write(colour);
+                wait_ms(100);
+                _RGB_led.write(7);
+                i++;
+            }
+            _RGB_led.write(7);
+            i = 0;
         }
-
         collision = 1;
     }else{
         collision = 0;