Reputation: 1609
I am trying to develope a pc game with ships. I have a function fire()
void Sprite::fire()
{
PlaySound("Sounds/azafire.wav", NULL, SND_FILENAME);//SND_FILENAME SND_SYNC
}
witch just play a sound but when I call this function then all program frizing and when sound fish then program continue.
My code were I call fire
function show bellow
LRESULT CALLBACK
WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Circle bc; // Not needed in this demo, leave default.
Vec2 p0(gClientCenter);
Vec2 v0(0.0f, 0.0f);
switch( msg )
{
// Create application resources.
case WM_CREATE:
// Create the sprites
gBackground = new Sprite(ghAppInst,
IDB_BACKGROUND1024X768, IDB_BACKGROUND1024X768MASK, bc, p0, v0);
gF15 = new Sprite(ghAppInst, IDB_F15, IDB_F15MASK,
bc, p0, v0);
p0.x = 100;
p0.y = 100;
gF18 = new Sprite(ghAppInst, IDB_F18, IDB_F18MASK,
bc, p0, v0);
gF18->mDirection = -1;
p0.x = 600;
p0.y = 100;
gF117 = new Sprite(ghAppInst, IDB_F117, IDB_F117MASK,
bc, p0, v0);
//Start move
gF117->mDirection = 1;
p0.x = 0.0f;
p0.y = 0.0f;
gBullet = new Sprite(ghAppInst, IDB_BULLET, IDB_BULLETMASK,
bc, p0, v0);
//Enemy Bullet
p0.x = 0.0f;
p0.y = 0.0f;
gEnemyBullet = new Sprite(ghAppInst, IDB_ENEMYBULLET, IDB_ENEMYBULLETMASK,
bc, p0, v0);
// Create system memory DCs
ghSpriteDC = CreateCompatibleDC(0);
// Create the backbuffer.
gBackBuffer = new BackBuffer(
hWnd,
gClientWidth,
gClientHeight);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
// Destroy the window when the user selects the 'exit'
// menu item.
case ID_FILE_EXIT:
DestroyWindow(ghMainWnd);
break;
}
return 0;
case WM_KEYDOWN:
switch(wParam)
{
// Accelerate left.
case 'A':
gF15->mVelocity.x -= 5.0f;
break;
// Accelerate right.
case 'D':
gF15->mVelocity.x += 5.0f;
break;
// Accelerate up (remember +y goes down and -y goes up)
case 'W':
gF15->mVelocity.y -= 5.0f;
break;
// Accelerate down.
case 'S':
gF15->mVelocity.y += 5.0f;
break;
case VK_SPACE:
// Add a bullet to the bullet list.
gBulletPos.push_back(gF15->mPosition);
gF15->fire(); // !!!! Here is the problem !!!!
break;
case VK_LEFT:
//Add LEFT ARROW key (0x25)
gF15->mVelocity.x -= 5.0f;
break;
case VK_RIGHT:
//Add Right ARROW Key
gF15->mVelocity.x += 5.0f;
break;
case VK_UP:
//Add UP ARROW Key (0x26)
gF15->mVelocity.y -= 5.0f;
break;
case VK_DOWN:
//Add DOWN ARROW Key (0x28)
gF15->mVelocity.y += 5.0f;
break;
}
return 0;
case WM_LBUTTONDOWN:
//Add Left mouse button
gBulletPos.push_back(gF15->mPosition);
gF15->fire(); // !!!! Here is the problem !!!!
return 0;
case WM_RBUTTONDOWN:
//Add Right mouse button
gEnemyBulletPos.push_back(gF117->mPosition);
return 0;
// Destroy application resources.
case WM_DESTROY:
delete gBackground;
delete gF15;
delete gF18;
delete gF117;
delete gBullet;
delete gBackBuffer;
DeleteDC(ghSpriteDC);
PostQuitMessage(0);
return 0;
}
// Forward any other messages we didn't handle to the
// default window procedure.
return DefWindowProc(hWnd, msg, wParam, lParam);
}
Can anyone help me? Thank you
Upvotes: 1
Views: 1721
Reputation:
You can use OGRE libraries to develop games
with c++
http://www.ogre3d.org/
It is free and Open Source. You can found an example game with ships. Have a look
Upvotes: 1
Reputation: 1609
Solution is here
void Sprite::fire()
{
PlaySound("Sounds/azafire.wav", NULL, SND_ASYNC);
}
for me works perfect.
Upvotes: 3