Jeffery Hurley
/
Asteroids
Simple starter skeleton for asteroids video game.
Diff: Sounds/Speaker.h
- Revision:
- 3:98aa3db6a48f
- Parent:
- 2:30020ddfccf6
diff -r 30020ddfccf6 -r 98aa3db6a48f Sounds/Speaker.h --- a/Sounds/Speaker.h Sat Mar 02 16:11:43 2019 +0000 +++ b/Sounds/Speaker.h Thu Apr 01 19:10:58 2021 +0000 @@ -1,16 +1,17 @@ #include "mbed.h" -#include "buzzy_siren.h" -#include "buzzy_begin.h" -#include "buzzy_chomp.h" -#include "buzzy_eatghost.h" -#include "buzzy_death.h" -#include "buzzy_eatfruit.h" +#include "Fire.h" +#include "beats1.h" +#include "beats2.h" +#include "bangsmall.h" +#include "bangmedium.h" +#include "banglarge.h" +#pragma once class Speaker : public PwmOut { public: - enum BUZZY_Sounds {NO_SOUND, BEGIN, SIREN, CHOMP, EAT_GHOST, DEATH, EAT_FRUIT}; + enum ASTERIODS_SOUNDS {NO_SOUND, BEATS1, BEATS2, FIRE, BANG_SMALL, BANG_MEDIUM, BANG_LARGE}; Speaker(PinName nPin):PwmOut(nPin) { @@ -20,13 +21,13 @@ void PlayNextValue() { - if (pAudioArray != NULL) + if (m_pAudioArray != NULL) { - write(pAudioArray[ GetNextValue() ]); + write((float)m_pAudioArray[ GetNextValue() ]/255.0f); } } - void SwitchSound ( const BUZZY_Sounds &newSound) + void SwitchSound ( const ASTERIODS_SOUNDS &newSound) { if (newSound == m_enActiveAudioArray) { @@ -38,26 +39,28 @@ switch (newSound) { case NO_SOUND: - pAudioArray = NULL; + m_pAudioArray = NULL; + break; + case BEATS1: + m_pAudioArray = &gBeats1Data[0]; break; - case BEGIN: - pAudioArray = &data_BEGIN[0]; + case BEATS2: + m_pAudioArray = &gBeats2Data[0]; break; - case CHOMP: - pAudioArray = &data_CHOMP[0]; + case FIRE: + m_pAudioArray = &gFireData[0]; break; - case EAT_GHOST: - pAudioArray = &data_GHOST[0]; + case BANG_SMALL: + m_pAudioArray = &gBangSmallData[0]; break; - case DEATH: - pAudioArray = &data_DEATH[0]; + case BANG_MEDIUM: + m_pAudioArray = &gBangMediumData[0]; break; - case EAT_FRUIT: - pAudioArray = &data_EAT_FRUIT[0]; + case BANG_LARGE: + m_pAudioArray = &gBangLargeData[0]; break; - case SIREN: default: - pAudioArray = &data_SIREN[0]; + m_pAudioArray = NULL; break; } @@ -68,37 +71,60 @@ m_ulAudioArrayIndex++; switch (m_enActiveAudioArray) { - case BEGIN: - m_ulAudioArrayIndex %= NUM_BEGIN_ELEMENTS; - break; - case CHOMP: - m_ulAudioArrayIndex %= NUM_CHOMP_ELEMENTS; - break; - case EAT_GHOST: - m_ulAudioArrayIndex %= NUM_GHOST_ELEMENTS; - break; - case DEATH: - m_ulAudioArrayIndex %= NUM_DEATH_ELEMENTS; + case BEATS1: + m_ulAudioArrayIndex %= NUM_BEATS1_ELEMENTS; + if (m_ulAudioArrayIndex == 0) + { + SwitchSound(BEATS2); + } + break; + case BEATS2: + m_ulAudioArrayIndex %= NUM_BEATS2_ELEMENTS; + if (m_ulAudioArrayIndex == 0) + { + SwitchSound(BEATS1); + } + break; + case FIRE: + m_ulAudioArrayIndex %= NUM_FIRE_ELEMENTS; if (m_ulAudioArrayIndex == 0) { - SwitchSound(SIREN); + SwitchSound(BEATS1); + } + break; + case BANG_SMALL: + m_ulAudioArrayIndex %= NUM_BANG_SMALL_ELEMENTS; + if (m_ulAudioArrayIndex == 0) + { + SwitchSound(BEATS1); + } + break; + case BANG_MEDIUM: + m_ulAudioArrayIndex %= NUM_BANG_MEDIUM_ELEMENTS; + if (m_ulAudioArrayIndex == 0) + { + SwitchSound(BEATS1); } break; - case EAT_FRUIT: - m_ulAudioArrayIndex %= NUM_EAT_FRUIT_ELEMENTS; - break; - case SIREN: + case BANG_LARGE: + m_ulAudioArrayIndex %= NUM_BANG_LARGE_ELEMENTS; + if (m_ulAudioArrayIndex == 0) + { + SwitchSound(BEATS1); + } + break; default: - m_ulAudioArrayIndex %= NUM_SIREN_ELEMENTS; + m_enActiveAudioArray = BEATS1; + m_ulAudioArrayIndex %= NUM_BEATS1_ELEMENTS; break; } return m_ulAudioArrayIndex; } private: unsigned long m_ulAudioArrayIndex; - BUZZY_Sounds m_enActiveAudioArray; - const float *pAudioArray; + ASTERIODS_SOUNDS m_enActiveAudioArray; + const unsigned char *m_pAudioArray; }; - \ No newline at end of file +