Space invaders with a nRF2401A wireless joypad

Dependencies:   Gameduino mbed nRF2401A

Fork of Gameduino_Invaders_game by Chris Dick

Gameduino and an nRF2401A hooked up to an mbed on an mbeduino:

/media/uploads/TheChrisyd/2014-03-08_22.53.54.jpg

Committer:
TheChrisyd
Date:
Sat Sep 29 13:01:42 2012 +0000
Revision:
1:f44175dd69fd
Parent:
0:8a7c58553b44
Child:
2:20a89dc286d5
saved progress

Who changed what in which revision?

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