Accueil > > > Shoot\sound.cpp
[C++] [WIN32] JEUX DE SHOOT ( SPACE SHOOT )
Shoot\sound.cpp
Informations sur ce code source
Voila un petit jeux vidéo. C'est très simple, il faut shooter le max d'aliens. J'ai crée ce jeux pour tester mon moteur 2D. Donc, les sources, en plus du jeux, sont un moteur de jeux 2D entièrement écrit avec l'API Win32 et en C++. J'utilise aussi la
Fichier : Shoot\sound.cpp
Nombre de lignes : 160 lignes
Afficher ce fichier en plein écran
-
- //---------------------------
- // sound.cpp
- //---------------------------
-
- #include "sound.h"
-
- namespace G2D
- {
-
- int cSound::mMixRate = 0;
- int cSound::mMaxChannels = 0;
-
-
- cSound::cSound()
- {
- sSample* sample = NULL;
- sStream* stream = NULL;
- sMusic* music = NULL;
- //mChannel = 0;
- mVolume = 255;
- SetVolume(-100);
-
- }
-
-
- cSound::~cSound()
- {
- /*if(mSample)
- FSOUND_Sample_Free(mSample);
- if(mStream)
- FSOUND_Stream_Close(mStream);
- if(mMusic)
- FMUSIC_FreeSong(mMusic);*/
- }
-
-
- void cSound::LoadSound(std::string file_name, std::string sound_name, cSound::eSoundType sound_type)
- {
- switch(sound_type)
- {
- case SAMPLE:
- sample = new sSample;
- sample->mSample = FSOUND_Sample_Load(FSOUND_FREE, file_name.c_str(), FSOUND_NORMAL, 0, 0);
- break;
- case STREAM:
- stream = new sStream;
- stream->mStream = FSOUND_Stream_Open(file_name.c_str(), FSOUND_NORMAL, 0, 0);
- break;
- case MUSIC:
- music = new sMusic;
- music->mMusic = FMUSIC_LoadSong(file_name.c_str());
- break;
- default:
- MESSAGE_BOX("Failed loading sound!", "Error!");
- break;
- }
- }
-
-
- void cSound::PlaySound(int channel)
- {
- SetChannel(channel);
- switch(mType)
- {
- case SAMPLE:
- FSOUND_PlaySound(mChannel, mSample);
- break;
- case STREAM:
- FSOUND_Stream_Play(mChannel, mStream);
- break;
- case MUSIC:
- FMUSIC_PlaySong(mMusic);
- break;
- default:
- MESSAGE_BOX("Failed playing sound!", "Error!");
- break;
- }
- }
-
-
- void cSound::SetPause(bool pause)
- {
- FSOUND_SetPaused(mChannel, pause);
- }
-
-
- void cSound::SetVolume(int volume)
- {
- mVolume+=volume;
-
- if(mVolume>255)
- mVolume = 255;
- if(mVolume<0)
- mVolume = 0;
-
- FSOUND_SetVolume(mChannel, mVolume);
- }
-
-
- void cSound::FreeSound()
- {
- /*if(mSample)
- {
- FSOUND_Sample_Free(mSample);
- mSample = NULL;
- }
- if(mStream)
- {
- FSOUND_Stream_Stop(mStream);
- mStream = NULL;
- }
- if(mMusic)
- {
- FMUSIC_FreeSong(mMusic);
- mMusic = NULL;
- }*/
-
- }
-
-
- void InitFmod(int mix_rate, int max_channels)
- {
- if((cSound::mMixRate && cSound::mMaxChannels) == 0)
- {
- cSound::SetMixRate(mix_rate);
- cSound::SetMaxChannels(max_channels);
-
- FSOUND_Init(cSound::mMixRate, cSound::mMaxChannels, 0);
- }
- }
-
-
- void CloseFmod()
- {
- FSOUND_Close();
- }
-
- INIT CreateSoundObject(cSound::eSoundType sound_type, cSound** sound)
- {
- *sound = new cSound();
- if(*sound)
- {
- (*sound)->mType = sound_type;
- return G2D_OK;
- }
- else
- return G2D_FAILED;
- }
-
-
- void FmodPause(bool pause)
- {
- FSOUND_SetPaused(FSOUND_ALL, pause);
- }
-
-
- } //namespace G2D
-
|