![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Invaders game for the Gameduino
sound.cpp@4:e82f4a87df9e, 2013-10-26 (annotated)
- Committer:
- TheChrisyd
- Date:
- Sat Oct 26 22:32:18 2013 +0000
- Revision:
- 4:e82f4a87df9e
- Parent:
- 2:20a89dc286d5
Shields are now destroyed when hit, corrected score displays
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TheChrisyd | 2:20a89dc286d5 | 1 | /*------------------------------------------------------------------ |
TheChrisyd | 2:20a89dc286d5 | 2 | Game sounds |
TheChrisyd | 2:20a89dc286d5 | 3 | ------------------------------------------------------------------*/ |
TheChrisyd | 2:20a89dc286d5 | 4 | #include "game.h" |
TheChrisyd | 2:20a89dc286d5 | 5 | #include "samples.h" |
TheChrisyd | 2:20a89dc286d5 | 6 | |
TheChrisyd | 2:20a89dc286d5 | 7 | |
TheChrisyd | 2:20a89dc286d5 | 8 | /*------------------------------------------------------------------ |
TheChrisyd | 2:20a89dc286d5 | 9 | Set these flags to start a sound playing |
TheChrisyd | 2:20a89dc286d5 | 10 | ------------------------------------------------------------------*/ |
TheChrisyd | 2:20a89dc286d5 | 11 | bool playerShootSound; |
TheChrisyd | 2:20a89dc286d5 | 12 | bool alienDeathSound; |
TheChrisyd | 2:20a89dc286d5 | 13 | bool playerDeathSound; |
TheChrisyd | 2:20a89dc286d5 | 14 | bool alienBeatSound; |
TheChrisyd | 2:20a89dc286d5 | 15 | bool saucerSound,stopSaucerSnd,saucerDieSound; |
TheChrisyd | 2:20a89dc286d5 | 16 | static byte alienBeat; |
TheChrisyd | 2:20a89dc286d5 | 17 | |
TheChrisyd | 2:20a89dc286d5 | 18 | #if SYNTHSOUNDS |
TheChrisyd | 2:20a89dc286d5 | 19 | SoundPlayer soundPlayer; |
TheChrisyd | 2:20a89dc286d5 | 20 | Sound shootSound; |
TheChrisyd | 2:20a89dc286d5 | 21 | #endif |
TheChrisyd | 2:20a89dc286d5 | 22 | |
TheChrisyd | 2:20a89dc286d5 | 23 | /*------------------------------------------------------------------ |
TheChrisyd | 2:20a89dc286d5 | 24 | Sound functions |
TheChrisyd | 2:20a89dc286d5 | 25 | ------------------------------------------------------------------*/ |
TheChrisyd | 2:20a89dc286d5 | 26 | void resetGameSounds() |
TheChrisyd | 2:20a89dc286d5 | 27 | { |
TheChrisyd | 2:20a89dc286d5 | 28 | SoundController::reset(); |
TheChrisyd | 2:20a89dc286d5 | 29 | playerShootSound = false; |
TheChrisyd | 2:20a89dc286d5 | 30 | alienDeathSound = false; |
TheChrisyd | 2:20a89dc286d5 | 31 | playerDeathSound = false; |
TheChrisyd | 2:20a89dc286d5 | 32 | alienBeatSound = false; |
TheChrisyd | 2:20a89dc286d5 | 33 | saucerSound = stopSaucerSnd = saucerDieSound = false; |
TheChrisyd | 2:20a89dc286d5 | 34 | alienBeat = 0; |
TheChrisyd | 2:20a89dc286d5 | 35 | } |
TheChrisyd | 2:20a89dc286d5 | 36 | |
TheChrisyd | 2:20a89dc286d5 | 37 | void updateGameSounds() |
TheChrisyd | 2:20a89dc286d5 | 38 | { |
TheChrisyd | 2:20a89dc286d5 | 39 | if (1) { |
TheChrisyd | 2:20a89dc286d5 | 40 | if (playerShootSound) { |
TheChrisyd | 2:20a89dc286d5 | 41 | playerShootSound = false; |
TheChrisyd | 2:20a89dc286d5 | 42 | SoundController::playSample((prog_char*)shoot_snd, sizeof(shoot_snd),0); |
TheChrisyd | 2:20a89dc286d5 | 43 | } |
TheChrisyd | 2:20a89dc286d5 | 44 | if (alienDeathSound) { |
TheChrisyd | 2:20a89dc286d5 | 45 | alienDeathSound = false; |
TheChrisyd | 2:20a89dc286d5 | 46 | SoundController::playSample((prog_char*)aliendeath_snd, sizeof(aliendeath_snd),1); |
TheChrisyd | 2:20a89dc286d5 | 47 | } |
TheChrisyd | 2:20a89dc286d5 | 48 | if (playerDeathSound) { |
TheChrisyd | 2:20a89dc286d5 | 49 | playerDeathSound = false; |
TheChrisyd | 2:20a89dc286d5 | 50 | SoundController::playSample((prog_char*)playerdeath_snd, sizeof(playerdeath_snd),1); |
TheChrisyd | 2:20a89dc286d5 | 51 | } |
TheChrisyd | 2:20a89dc286d5 | 52 | if (saucerSound) { |
TheChrisyd | 2:20a89dc286d5 | 53 | saucerSound = false; |
TheChrisyd | 2:20a89dc286d5 | 54 | SoundController::playSample((prog_char*)saucer_snd, -sizeof(saucer_snd),2); |
TheChrisyd | 2:20a89dc286d5 | 55 | } |
TheChrisyd | 2:20a89dc286d5 | 56 | if (stopSaucerSnd) { |
TheChrisyd | 2:20a89dc286d5 | 57 | stopSaucerSnd = false; |
TheChrisyd | 2:20a89dc286d5 | 58 | SoundController::playSample((prog_char*)0,0,2); |
TheChrisyd | 2:20a89dc286d5 | 59 | } |
TheChrisyd | 2:20a89dc286d5 | 60 | if (saucerDieSound) { |
TheChrisyd | 2:20a89dc286d5 | 61 | saucerDieSound = false; |
TheChrisyd | 2:20a89dc286d5 | 62 | SoundController::playSample((prog_char*)playerdeath_snd, sizeof(playerdeath_snd),2); |
TheChrisyd | 2:20a89dc286d5 | 63 | } |
TheChrisyd | 2:20a89dc286d5 | 64 | if (alienBeatSound) { |
TheChrisyd | 2:20a89dc286d5 | 65 | alienBeatSound = false; |
TheChrisyd | 2:20a89dc286d5 | 66 | prog_char *b = 0; unsigned int n = 0; |
TheChrisyd | 2:20a89dc286d5 | 67 | switch (alienBeat&3) { |
TheChrisyd | 2:20a89dc286d5 | 68 | case 0: b = (prog_char*)beat1_snd; n = sizeof(beat1_snd); break; |
TheChrisyd | 2:20a89dc286d5 | 69 | case 1: b = (prog_char*)beat2_snd; n = sizeof(beat2_snd); break; |
TheChrisyd | 2:20a89dc286d5 | 70 | case 2: b = (prog_char*)beat3_snd; n = sizeof(beat3_snd); break; |
TheChrisyd | 2:20a89dc286d5 | 71 | case 3: b = (prog_char*)beat4_snd; n = sizeof(beat4_snd); break; |
TheChrisyd | 2:20a89dc286d5 | 72 | } |
TheChrisyd | 2:20a89dc286d5 | 73 | SoundController::playSample(b,n,3); |
TheChrisyd | 2:20a89dc286d5 | 74 | ++alienBeat; |
TheChrisyd | 2:20a89dc286d5 | 75 | } |
TheChrisyd | 2:20a89dc286d5 | 76 | SoundController::update(); |
TheChrisyd | 2:20a89dc286d5 | 77 | } |
TheChrisyd | 2:20a89dc286d5 | 78 | #if SYNTHSOUNDS |
TheChrisyd | 2:20a89dc286d5 | 79 | else { |
TheChrisyd | 2:20a89dc286d5 | 80 | if (playerShootSound) { |
TheChrisyd | 2:20a89dc286d5 | 81 | playerShootSound = false; |
TheChrisyd | 2:20a89dc286d5 | 82 | shootSound.adsr = ADSR(10,15,100,36); |
TheChrisyd | 2:20a89dc286d5 | 83 | soundPlayer.setVolume(200).setSound(shootSound).play(440,100); |
TheChrisyd | 2:20a89dc286d5 | 84 | } |
TheChrisyd | 2:20a89dc286d5 | 85 | SoundController::update(); |
TheChrisyd | 2:20a89dc286d5 | 86 | } |
TheChrisyd | 2:20a89dc286d5 | 87 | #endif |
TheChrisyd | 2:20a89dc286d5 | 88 | |
TheChrisyd | 2:20a89dc286d5 | 89 | } |