來個大哥幫忙看下 為什么 game_music和explode這兩個音樂會延遲播放
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<iostream>
#pragma comment(lib,"Winmm.lib")
#define H 800
#define W 590
IMAGE img_bk;
IMAGE img_planeNormal_1, img_planeNormal_2;
IMAGE img_bullet1, img_bullet2;
IMAGE img_enemyPlane1, img_enemyPlane2;
IMAGE img_planeExplode_1, img_planeExplode_2;
float position_x, position_y;
float bullet_x, bullet_y;
float enemy_x, enemy_y;
int isExplode = 0;
int score = 0;
void startup()
{
mciSendString(_T("open .\\game_music.mp3 alias bkmusic"), NULL, 0, NULL);
mciSendString(_T("play bkmusic repeat"), NULL, 0, NULL);
initgraph(W, H);
loadimage(&img_bk, _T(".\\background.jpg"));
loadimage(&img_planeNormal_1, _T(".\\planeNormal_1.jpg"));
loadimage(&img_planeNormal_2, _T(".\\planeNormal_2.jpg"));
loadimage(&img_bullet1, _T(".\\bullet1.jpg"));
loadimage(&img_bullet2, _T(".\\bullet2.jpg"));
loadimage(&img_enemyPlane1, _T(".\\enemyPlane1.jpg"));
loadimage(&img_enemyPlane2, _T(".\\enemyPlane2.jpg"));
loadimage(&img_planeExplode_1, _T(".\\planeExplode_1.jpg"));
loadimage(&img_planeExplode_2, _T(".\\planeExplode_2.jpg"));
position_x = W * 0.5;
position_y = H * 0.7;
bullet_x = position_x;
bullet_y = -85;
enemy_x = W * 0.5;
enemy_y = 10;
BeginBatchDraw();
}
void show()
{
putimage(0, 0, &img_bk);
if (isExplode == 0)
{
putimage(position_x - 50, position_y - 60, &img_planeNormal_1, NOTSRCERASE);
putimage(position_x - 50, position_y - 60, &img_planeNormal_2, SRCINVERT);
putimage(bullet_x - 7, bullet_y, &img_bullet1, NOTSRCERASE);
putimage(bullet_x - 7, bullet_y, &img_bullet2, SRCINVERT);
putimage(enemy_x, enemy_y, &img_enemyPlane1, NOTSRCERASE);
putimage(enemy_x, enemy_y, &img_enemyPlane2, SRCINVERT);
}
else
{
putimage(position_x - 50, position_y - 60, &img_planeExplode_1, NOTSRCERASE);
putimage(position_x - 50, position_y - 60, &img_planeExplode_2, SRCINVERT);
}
FlushBatchDraw();
Sleep(2);
}
void updatewithoutinput()
{
if (bullet_y > -25)
bullet_y -= 2;
if (enemy_y < H - 25)
enemy_y += 0.5;
else
enemy_y = 10;
if (abs((int)(bullet_x - enemy_x)) + abs((int)(bullet_y - enemy_y)) < 50)
{
enemy_x = rand() % W;
enemy_y = -40;
bullet_y = -85;
mciSendString(_T("close gemusic"), NULL, 0, NULL);
mciSendString(_T("open .\\gotEnemy.mp3 alias gemusic"), NULL, 0, NULL);
mciSendString(_T("play gemusic"), NULL, 0, NULL);
score++;
if ((score > 0) && (score % 5 == 0) && (score % 2 != 0))
{
mciSendString(_T("close 5music"), NULL, 0, NULL);
mciSendString(_T("open .\\5.mp3 alias 5music"), NULL, 0, NULL);
mciSendString(_T("play 5music"), NULL, 0, NULL);
}
if (score % 10 == 0)
{
mciSendString(_T("close 10music"), NULL, 0, NULL);
mciSendString(_T("open .\\10.mp3 alias 10music"), NULL, 0, NULL);
mciSendString(_T("play 10music"), NULL, 0, NULL);
}
}
if (abs((int)(position_x - enemy_x)) + abs((int)(position_y - enemy_y)) < 150)
{
isExplode = 1;
mciSendString(_T("close exmusic"), NULL, 0, NULL);
mciSendString(_T("open .\\explode.mp3 alias exmusic"), NULL, 0, NULL);
mciSendString(_T("play exmusic"), NULL, 0, NULL);
}
}
void updatewithinput()
{
MOUSEMSG m;
while (MouseHit())
{
m = GetMouseMsg();
if (m.uMsg == WM_MOUSEMOVE)
{
position_x = m.x;
position_y = m.y;
}
else if (m.uMsg == WM_LBUTTONDOWN)
{
bullet_x = position_x;
bullet_y = position_y - 85;
mciSendString(_T("close fgmusic"), NULL, 0, NULL);
mciSendString(_T("open .\\f_gun.mp3 alias fgmusic"), NULL, 0, NULL);
mciSendString(_T("play fgmusic"), NULL, 0, NULL);
}
}
}
void gameover()
{
EndBatchDraw();
_getch();
closegraph();
}
int main()
{
startup();
while (1)
{
show();
updatewithoutinput();
updatewithinput();
}
gameover();
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/101665.html
標籤:新手樂園
