Simple starter skeleton for asteroids video game.

Dependencies:   PinDetect

Revision:
2:30020ddfccf6
Parent:
1:a6872783beca
Child:
3:98aa3db6a48f
--- a/Sounds/Speaker.h	Sat Feb 23 21:38:45 2019 +0000
+++ b/Sounds/Speaker.h	Sat Mar 02 16:11:43 2019 +0000
@@ -10,13 +10,12 @@
 class Speaker : public PwmOut
 {
 public:
-    enum BUZZY_Sounds {BEGIN, SIREN, CHOMP, EAT_GHOST, DEATH, EAT_FRUIT};
+    enum BUZZY_Sounds {NO_SOUND, BEGIN, SIREN, CHOMP, EAT_GHOST, DEATH, EAT_FRUIT};
     
     Speaker(PinName nPin):PwmOut(nPin)
     {
        m_ulAudioArrayIndex = 0;
-       m_enActiveAudioArray = BEGIN;    
-       pAudioArray = NULL;
+       SwitchSound(NO_SOUND);
     }
     
     void PlayNextValue()
@@ -27,10 +26,20 @@
         }       
     }
     
-    void SwitchAudioFile ( const BUZZY_Sounds &newSound)
+    void SwitchSound ( const BUZZY_Sounds &newSound)
     {
+        if (newSound == m_enActiveAudioArray)
+        {
+            return;
+        }
+            
+        m_ulAudioArrayIndex = 0;
+        m_enActiveAudioArray = newSound;
         switch (newSound)
         {           
+            case NO_SOUND:
+                pAudioArray = NULL;
+                break;   
             case BEGIN:
                 pAudioArray = &data_BEGIN[0];
                 break;   
@@ -70,6 +79,10 @@
                 break;
             case DEATH:
                  m_ulAudioArrayIndex %= NUM_DEATH_ELEMENTS;
+                 if (m_ulAudioArrayIndex == 0)
+                 {
+                     SwitchSound(SIREN);
+                 }
                 break;
             case EAT_FRUIT:
                  m_ulAudioArrayIndex %= NUM_EAT_FRUIT_ELEMENTS;
@@ -84,7 +97,7 @@
 private:
     unsigned long m_ulAudioArrayIndex;
     BUZZY_Sounds m_enActiveAudioArray;
-    float *pAudioArray;
+    const float *pAudioArray;
     
 };