Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Revision:
12:20ac766b3175
Parent:
11:7c1e2a9303d3
Child:
13:183bd19f3d7d
--- a/classes/Game.cpp	Wed Apr 21 11:08:02 2021 +0000
+++ b/classes/Game.cpp	Wed Apr 21 15:24:31 2021 +0000
@@ -1,12 +1,16 @@
 #include "Game.h"
 
+//objects
 ShiftReg _shift;
-Graphics _graphics; 
-
+Graphics _graphics;
+Sound _sound;
+ 
+//attach
 BusOut _RGB_led(p24,p23,p22); //RGB bus MSB - LSB, inverted logic 1 = low
+Tone _dac(p18);
 
 //plays the game
-void Game::gamePlay(N5110 &lcd, DIRECTION direction){ 
+void Game::gamePlay(N5110 &lcd, Tone &dac, DIRECTION direction){ 
     lcd.clear();
     lcd.drawRect(0,0,40,9, FILL_TRANSPARENT); //creates the growth bar
     lcd.drawRect(0,8,84,40,FILL_TRANSPARENT); //draws screen border
@@ -22,7 +26,7 @@
     fishPos(direction);
     drawFish(lcd);
     enemyFish(lcd);
-    Collision();
+    Collision(dac);
     Score(lcd);
     Lives();
     
@@ -31,7 +35,7 @@
     wait_ms(1000/30);
 }
     
-//initiates game.            20,     20,        1          
+//initialies game.            20,     20,        1          
 void Game::init(N5110 &lcd, int x, int y, int Fish_size){
     _x = x;
     _y = y;
@@ -45,7 +49,7 @@
     barIncrement = 0;
     check_width = 0;
     lives = 3;
-    _shift.write(0x4F); //initiate lives
+    _shift.write(0x4F);
     
     //draw fish 
     drawFish(lcd);
@@ -210,20 +214,23 @@
 }
 
 //checks for collision with other fish
-int Game::Collision(){
+int Game::Collision(Tone &dac){
     centre_xpos = E_CENTRE_X - CENTRE_X;
     centre_ypos = E_CENTRE_Y - CENTRE_Y;
     
     if((centre_xpos == 2 && centre_ypos <= 1) && (centre_xpos == 2 && centre_ypos >= -1)){
         if(FISH_SIZE < E_FISH){
+            
             //remove one life
             lives--;
+            
             //flicker busout
             _RGB_led.write(6); //red
             wait_ms(100);
             _RGB_led.write(7); //off  
              
-        }else if(FISH_SIZE >= E_FISH){           
+        }else if(FISH_SIZE >= E_FISH){ 
+                  
             //increase score by 10
             SCORE = SCORE + 10;
             //remove eaten fish