Invaders game for the Gameduino

Dependencies:   Gameduino mbed

Committer:
TheChrisyd
Date:
Thu Jun 21 19:13:34 2012 +0000
Revision:
0:8a7c58553b44
Child:
1:f44175dd69fd
backup before adding more features

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TheChrisyd 0:8a7c58553b44 1 /*------------------------------------------------------------------
TheChrisyd 0:8a7c58553b44 2 Game sounds
TheChrisyd 0:8a7c58553b44 3 ------------------------------------------------------------------*/
TheChrisyd 0:8a7c58553b44 4 #include "game.h"
TheChrisyd 0:8a7c58553b44 5 #include "samples.h"
TheChrisyd 0:8a7c58553b44 6
TheChrisyd 0:8a7c58553b44 7
TheChrisyd 0:8a7c58553b44 8 /*------------------------------------------------------------------
TheChrisyd 0:8a7c58553b44 9 Set these flags to start a sound playing
TheChrisyd 0:8a7c58553b44 10 ------------------------------------------------------------------*/
TheChrisyd 0:8a7c58553b44 11 bool playerShootSound;
TheChrisyd 0:8a7c58553b44 12 bool alienDeathSound;
TheChrisyd 0:8a7c58553b44 13 bool playerDeathSound;
TheChrisyd 0:8a7c58553b44 14 bool alienBeatSound;
TheChrisyd 0:8a7c58553b44 15 bool saucerSound,stopSaucerSnd,saucerDieSound;
TheChrisyd 0:8a7c58553b44 16 static byte alienBeat;
TheChrisyd 0:8a7c58553b44 17
TheChrisyd 0:8a7c58553b44 18 #if SYNTHSOUNDS
TheChrisyd 0:8a7c58553b44 19 SoundPlayer soundPlayer;
TheChrisyd 0:8a7c58553b44 20 Sound shootSound;
TheChrisyd 0:8a7c58553b44 21 #endif
TheChrisyd 0:8a7c58553b44 22
TheChrisyd 0:8a7c58553b44 23 /*------------------------------------------------------------------
TheChrisyd 0:8a7c58553b44 24 Sound functions
TheChrisyd 0:8a7c58553b44 25 ------------------------------------------------------------------*/
TheChrisyd 0:8a7c58553b44 26 void resetGameSounds()
TheChrisyd 0:8a7c58553b44 27 {
TheChrisyd 0:8a7c58553b44 28 SoundController::reset();
TheChrisyd 0:8a7c58553b44 29 playerShootSound = false;
TheChrisyd 0:8a7c58553b44 30 alienDeathSound = false;
TheChrisyd 0:8a7c58553b44 31 playerDeathSound = false;
TheChrisyd 0:8a7c58553b44 32 alienBeatSound = false;
TheChrisyd 0:8a7c58553b44 33 saucerSound = stopSaucerSnd = saucerDieSound = false;
TheChrisyd 0:8a7c58553b44 34 alienBeat = 0;
TheChrisyd 0:8a7c58553b44 35 }
TheChrisyd 0:8a7c58553b44 36
TheChrisyd 0:8a7c58553b44 37 void updateGameSounds()
TheChrisyd 0:8a7c58553b44 38 {
TheChrisyd 0:8a7c58553b44 39 if (1) {
TheChrisyd 0:8a7c58553b44 40 if (playerShootSound) {
TheChrisyd 0:8a7c58553b44 41 playerShootSound = false;
TheChrisyd 0:8a7c58553b44 42 SoundController::playSample((prog_char*)shoot_snd, sizeof(shoot_snd),0);
TheChrisyd 0:8a7c58553b44 43 }
TheChrisyd 0:8a7c58553b44 44 if (alienDeathSound) {
TheChrisyd 0:8a7c58553b44 45 alienDeathSound = false;
TheChrisyd 0:8a7c58553b44 46 SoundController::playSample((prog_char*)aliendeath_snd, sizeof(aliendeath_snd),1);
TheChrisyd 0:8a7c58553b44 47 }
TheChrisyd 0:8a7c58553b44 48 if (playerDeathSound) {
TheChrisyd 0:8a7c58553b44 49 playerDeathSound = false;
TheChrisyd 0:8a7c58553b44 50 SoundController::playSample((prog_char*)playerdeath_snd, sizeof(playerdeath_snd),1);
TheChrisyd 0:8a7c58553b44 51 }
TheChrisyd 0:8a7c58553b44 52 if (saucerSound) {
TheChrisyd 0:8a7c58553b44 53 saucerSound = false;
TheChrisyd 0:8a7c58553b44 54 SoundController::playSample((prog_char*)saucer_snd, -sizeof(saucer_snd),2);
TheChrisyd 0:8a7c58553b44 55 }
TheChrisyd 0:8a7c58553b44 56 if (stopSaucerSnd) {
TheChrisyd 0:8a7c58553b44 57 stopSaucerSnd = false;
TheChrisyd 0:8a7c58553b44 58 SoundController::playSample((prog_char*)0,0,2);
TheChrisyd 0:8a7c58553b44 59 }
TheChrisyd 0:8a7c58553b44 60 if (saucerDieSound) {
TheChrisyd 0:8a7c58553b44 61 saucerDieSound = false;
TheChrisyd 0:8a7c58553b44 62 SoundController::playSample((prog_char*)playerdeath_snd, sizeof(playerdeath_snd),2);
TheChrisyd 0:8a7c58553b44 63 }
TheChrisyd 0:8a7c58553b44 64 if (alienBeatSound) {
TheChrisyd 0:8a7c58553b44 65 alienBeatSound = false;
TheChrisyd 0:8a7c58553b44 66 prog_char *b = 0; unsigned int n = 0;
TheChrisyd 0:8a7c58553b44 67 switch (alienBeat&3) {
TheChrisyd 0:8a7c58553b44 68 case 0: b = (prog_char*)beat1_snd; n = sizeof(beat1_snd); break;
TheChrisyd 0:8a7c58553b44 69 case 1: b = (prog_char*)beat2_snd; n = sizeof(beat2_snd); break;
TheChrisyd 0:8a7c58553b44 70 case 2: b = (prog_char*)beat3_snd; n = sizeof(beat3_snd); break;
TheChrisyd 0:8a7c58553b44 71 case 3: b = (prog_char*)beat4_snd; n = sizeof(beat4_snd); break;
TheChrisyd 0:8a7c58553b44 72 }
TheChrisyd 0:8a7c58553b44 73 SoundController::playSample(b,n,3);
TheChrisyd 0:8a7c58553b44 74 ++alienBeat;
TheChrisyd 0:8a7c58553b44 75 }
TheChrisyd 0:8a7c58553b44 76 SoundController::update();
TheChrisyd 0:8a7c58553b44 77 }
TheChrisyd 0:8a7c58553b44 78 #if SYNTHSOUNDS
TheChrisyd 0:8a7c58553b44 79 else {
TheChrisyd 0:8a7c58553b44 80 if (playerShootSound) {
TheChrisyd 0:8a7c58553b44 81 playerShootSound = false;
TheChrisyd 0:8a7c58553b44 82 shootSound.adsr = ADSR(10,15,100,36);
TheChrisyd 0:8a7c58553b44 83 soundPlayer.setVolume(200).setSound(shootSound).play(440,100);
TheChrisyd 0:8a7c58553b44 84 }
TheChrisyd 0:8a7c58553b44 85 SoundController::update();
TheChrisyd 0:8a7c58553b44 86 }
TheChrisyd 0:8a7c58553b44 87 #endif
TheChrisyd 0:8a7c58553b44 88
TheChrisyd 0:8a7c58553b44 89 }