Jump to content
  • Advertisement
Sign in to follow this  
medevilenemy

A Space Shooter Engine

This topic is 4731 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I recently started writing an OpenGL Top-Down Space Shooter Engine and I have, so far, implemented Texture Mapping, a basic (obviously temporary) image for the player's ship, controls for said ship, and a menu system. I'm not sure yet, but i believe i will need the ability to render DXF models, play some rather simple WAV audio (not 3D audio, just BG music, Voices, and sound effects without complicated filters, etc). Can anyone tell me of any tutorials which will teach these things, also, is there anything anyone thinks I should add besides these things?

Share this post


Link to post
Share on other sites
Advertisement
Use DirectMusic for the sound, it's simple.


//Here's how to set up DirectMusic and the sounds you want to play

IDirectMusicLoader8* Loader;
IDirectMusicPerformance8* Performance;
//Create a segment pointer for each sound effect/music track you have
IDirectMusicSegment8* BGMusic;
IDirectMusicSegment8* SoundEffect;

CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC,
IID_IDirectMusicLoader8,(void**)&Loader);

CoCreateInstance(CLSID_DirectMusicPerformance, NULL,CLSCTX_INPROC,
IID_IDirectMusicPerformance8,(void**)&Performance);

Performance->InitAudio(
NULL, // IDirectMusic interface not needed.
NULL, // IDirectSound interface not needed.
hWnd, // Window handle.
DMUS_APATH_SHARED_STEREOPLUSREVERB, // Default audiopath type.
64, // Number of performance channels.
DMUS_AUDIOF_ALL, // Features on synthesizer.
NULL // Audio parameters; use defaults.
);

Loader->SetSearchDirectory(
GUID_DirectMusicAllTypes,
//L"C:\\Program Files\\KaZaA\\My Shared Folder"
NULL, // Where to look. Null for default
FALSE // Don't clear object data.
);

BGMusic = loadSound("bgtitlescreen.mid");
SoundEffect = loadSound("explosion.wav");

//You can set this flag for your music if you want it to repeat forever
BGMusic->SetRepeats(DMUS_SEG_REPEAT_INFINITE);

//Here's the loadSound function definition
IDirectMusicSegment8* Audio::loadSound(char* filename)
{
DMUS_OBJECTDESC desc;
IDirectMusicSegment8* seg;
ZeroMemory(&desc,sizeof(LPDMUS_OBJECTDESC));
desc.dwSize = sizeof(DMUS_OBJECTDESC);
desc.guidClass = CLSID_DirectMusicSegment;
desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH;
mbstowcs(desc.wszFileName, filename, MAX_PATH);
Loader->GetObject(&desc, IID_IDirectMusicSegment8, (LPVOID*)&seg);
return seg;
}

//Here's how to play your sounds, I wrapped up each of my sounds into a function
void playBGMusic()
{
BGMusic->Download(Performance);

Performance->PlaySegmentEx(
BGMusic, // Segment to play.
NULL, // Used for songs; not implemented.
NULL, // For transitions.
NULL, // Flags.
0, // Start time; 0 is immediate.
NULL, // Pointer that receives segment state.
NULL, // Object to stop.
NULL // Audiopath, if not default.
);

//For sound effects, you're gonna want the sound effect to play while the
//background music is playing right? Just set the extra flag in the 4 argument
//to let the Performance object know it's a secondary sound like this:
void Audio::playWallHit()
{
SoundEffect->Download(Performance);

Performance->PlaySegmentEx(
SoundEffect, // Segment to play.
NULL, // Used for songs; not implemented.
NULL, // For transitions.
DMUS_SEGF_SECONDARY, // Flags. This is the flag!
0, // Start time; 0 is immediate.
NULL, // Pointer that receives segment state.
NULL, // Object to stop.
NULL // Audiopath, if not default.
);
}




I wrapped up all my audio into a class. Remember to clean up:
Performance->Stop(
NULL, // Stop all segments.
NULL, // Stop all segment states.
0, // Do it immediately.
0 // Flags.
);
Performance->CloseDown();
BGMusic->Release();
SoundEffect->Release();

Remember to include <dmusici.h>.

This should get you started.

Share this post


Link to post
Share on other sites
Quote:
Original post by medevilenemy
thanks, but i'm not using DX in this program -- sticking with good ol' OpenGL and whatever else i can find.


How about OpenAL for sound? Those two API's (OGL and OAL) looks very simliar in terms of code structure, so you shouldn't have a hard time learning the API and OAL can do the same as DirectSound (I'm not entisure how many features OAL has, but professional games like JK:JA III and SoF II use it, so it must contain the relevant features :-P) and is crossplatform, so you can make 3D sound or whatever with it in future projects.

Share this post


Link to post
Share on other sites
with sdl its very easy to get some sounds up and running

Mix_LoadWAV( "bang.wav" );
Mix_PlayChannel( this_soundchannelID, st.chunk, sound_repeat_number_times );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!