I am aa program a game for school work in C ++, and I have a game that during its execution starts a song, then when I click on the space key to fire the music stops and you only hear the gun shot. / p>
I wanted to be able to play both the background and the game.
Here is my code:
private: System::Void GameForm_Load(System::Object^ sender, System::EventArgs^ e)
{
PlaySound(TEXT("../Musicas/Game.wav"), NULL, SND_ASYNC | SND_LOOP);
}
This song starts when I open the page. And this when I load in space:
private: System::Void GameForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
switch (e->KeyCode)
{
case Keys::A:
Nave->Left -= 20;
break;
case Keys::D:
Nave->Left += 20;
break;
case Keys::W:
Nave->Top -= 20;
break;
case Keys::S:
Nave->Top += 20;
break;
case Keys::Space://Carrego no espaço e o som e executado
PlaySound(TEXT("../Musicas/Laser.wav"), NULL, SND_ASYNC);
break;
}
}
The background music for when I run the space. I wanted both songs at the same time.