📄 btplane.cpp
字号:
{
bulletTimer = 0;
for (int i=0; i<m_iMaxBullet; i++)
{
if (m_Bullet[i].stat == Bullet::idle)
{
m_Bullet[i].pos.x = random(-50, 370);
if (m_Bullet[i].pos.x > 0 && m_Bullet[i].pos.x < 320)
{
int j = random(2);
m_Bullet[i].pos.y = (j ? random(-50, 0) : random(240, 290));
}
else
{
m_Bullet[i].pos.y = random(0, 240);
}
if (m_iDummyTimer)
{
m_Bullet[i].des.x = m_rDummyPos.left+7;
m_Bullet[i].des.y = m_rDummyPos.top+7;
}
else
{
m_Bullet[i].des.x = m_rPlanePos.left+7;
m_Bullet[i].des.y = m_rPlanePos.top+7;
}
float k,b;
sPoint s = m_Bullet[i].des - m_Bullet[i].pos;
k = (float)s.y / (s.x ? s.x : 0.001f);
b = m_Bullet[i].pos.y - k * m_Bullet[i].pos.x;
if (m_Bullet[i].pos.x < m_rPlanePos.left) s.x = random(320,370);
else s.x = random(-50, 0);
float fk = random(0, 30) / 100.f;
s.y = (k+fk)*s.x + b;
m_Bullet[i].des = s;
m_Bullet[i].stat = Bullet::inst;
m_Bullet[i].speed = m_iSpeed;// + random(-1, 2);
//m_Bullet[i].speed = m_Bullet[i].speed<=0? 1 : m_Bullet[i].speed;
}
}
static int addflag = 0;
++addflag;
if (addflag==5)
{
if (m_bSound) SoundPlayer.play(m_BkSnd);
if (random(30)==1)
{
if (m_bSound) SoundPlayer.play(m_AmmSnd);
m_iDummyTimer = 2000;
int x = random(0,320);
int y = random(0,240);
m_rDummyPos = RECT(x,y,x+16, y+16);
}
++m_iMaxBullet;
addflag = 0;
}
//
}
static DWORD starFTimer = 0, starBTimer = 0;
starBTimer += timer.GetDalyTimes();
if (starBTimer > 800)
{
starBTimer = 0;
WORD *starb;
m_psufStarB->Lock((void**)&starb);
for(int i=239; i>0; i--)
{
memcpy(starb+i*320, starb+(i-1)*320, 320*2);
}
CreateStar(starb);
m_psufStarB->unLock();
//bDrawStar = true;
}
starFTimer += timer.GetDalyTimes();
if (starFTimer > 100)
{
starFTimer = 0;
WORD *starf;
m_psufStarF->Lock((void**)&starf);
for(int i=239; i>0; i--)
{
memcpy(starf+i*320, starf+(i-1)*320, 320*2);
}
CreateStar(starf);
m_psufStarF->unLock();
//bDrawStar = true;
}
}
else if (m_iStat == 1)
{
static int bomb = 0;
m_rPlanePic = RECT(bomb*16, 16, bomb*16+16, 32);
bomb++;
if (bomb == 5)
{
m_iStat = 2;
bomb = 0;
}
}
}
void CBSFYApp::DrawBack(RECT& r, char* c, int cx, int cy, int nc) // 菜单
{
int x=r.left,y=r.top,w=r.right,h=r.bottom;
m_pMainSuf->DrawRect(x,y,x+w,y+h, RGBto16bit565(165,81,0));
m_pMainSuf->DrawRect(x+1,y+1,x+w-1,y+h-1, RGBto16bit565(165,81,0));
if (nc)
m_pMainSuf->DrawRect(x+2,y+2,x+w-2,y+h-2, RGBto16bit565(255,180,0), 1);
else
m_pMainSuf->DrawRect(x+2,y+2,x+w-2,y+h-2, RGBto16bit565(231,113,0), 1);
m_pMainSuf->DrawText(c, x+cx, y+cy, PGE_WHITE);
}
void CBSFYApp::OnDraw()
{
char buf[50];
RECT rDis, rSrc;
if (m_iStat == menu)
{
m_pMainSuf->Clean();
sprintf(buf, "******是男人就挺20秒******", (float)m_dwLiveTimer/1000.f);
m_pMainSuf->DrawText(buf, 35, 70, PGE_YELLOW);
rDis = RECT(110, 120, 80, 20);
DrawBack(rDis, "开始", 25, 3, m_iMenu == 0);
rDis = RECT(110, 143, 80, 20);
sprintf(buf, "速度:%d", m_iSpeed);
DrawBack(rDis, buf, 13, 3, m_iMenu == 1);
rDis = RECT(110, 166, 80, 20);
sprintf(buf, "音乐:%s", m_bSound ? "开": "关");
DrawBack(rDis, buf, 13, 3, m_iMenu == 2);
rDis = RECT(110, 189, 80, 20);
DrawBack(rDis, "退出", 25, 3, m_iMenu == 3);
GetDevice()->Flip();
return;
}
if(bDrawStar)
{
m_pMainSuf->Blt(m_psufStarB, NULL, NULL);
m_pMainSuf->Blt(m_psufStarF, NULL, NULL, PGE_BLT_NORMAL | PGE_BLT_MASK);
}
bDrawStar = !bDrawStar;
m_pMainSuf->Blt(m_pPic, &m_rPlanePic, &m_rPlanePos, PGE_BLT_NORMAL | PGE_BLT_MASK);
for (int i=0; i<m_iMaxBullet; i++)
{
if (m_Bullet[i].stat == Bullet::show)
{
rDis = RECT(m_Bullet[i].pos.x, m_Bullet[i].pos.y,
m_Bullet[i].pos.x+4, m_Bullet[i].pos.y+4);
rDis = rDis & RECT(0,0,320,240);
m_pMainSuf->Blt(m_pPic, &rPicBullet, &rDis, PGE_BLT_NORMAL | PGE_BLT_MASK);
}
}
if (m_iStat == winer)
{
if(m_dwLiveTimer<20000)
m_pMainSuf->DrawText("不 及 格", 100, 60, PGE_GREEN);
else if(m_dwLiveTimer>20000 && m_dwLiveTimer<40000)
m_pMainSuf->DrawText("马 马 虎 虎", 100, 60, PGE_LIGHTBLUE);
else if(m_dwLiveTimer>40000 && m_dwLiveTimer<80000)
m_pMainSuf->DrawText("牛 人", 100, 60, PGE_PURPLE);
else if(m_dwLiveTimer>80000 && m_dwLiveTimer<120000)
m_pMainSuf->DrawText("大 牛", 100, 60, PGE_YELLOW);
else if(m_dwLiveTimer>120000 )
m_pMainSuf->DrawText("神 牛", 100, 60, PGE_RED);
sprintf(buf, "生存时间%.3f秒", (float)m_dwLiveTimer/1000.f);
m_pMainSuf->DrawText(buf, 100, 100, PGE_WHITE);
sprintf(buf, "活动时间%.3f秒", (float)m_dwActiveTimer/1000.f);
m_pMainSuf->DrawText(buf, 100, 120, PGE_WHITE);
sprintf(buf, "子弹%d发", m_iMaxBullet);
m_pMainSuf->DrawText(buf, 122, 140, PGE_WHITE);
sprintf(buf, "操作 %s %%%d", m_isroKeybord>m_isroMouse ? "键盘" : "触屏",
(int)((m_isroKeybord>m_isroMouse ? m_isroKeybord : m_isroMouse)*100 / (float)(m_isroKeybord+m_isroMouse)));
m_pMainSuf->DrawText(buf, 102, 160, PGE_WHITE);
sprintf(buf, "速度%d", m_iSpeed);
m_pMainSuf->DrawText(buf, 136, 180, PGE_WHITE);
if (m_iNiceTimes)
{
sprintf(buf, "绝妙度%%%d", m_iNiceTimes);
m_pMainSuf->DrawText(buf, 121, 200, PGE_WHITE);
}
DrawBack(RECT(278,218,40,20), "保存", 5, 3, 1);
if (m_caTitle[0])
{
m_pMainSuf->DrawText(m_caTitle, 2, 2, PGE_RED);
}
if ((m_iMsgTimer -= timer.GetDalyTimes())<0)
{
m_caTitle[0] = 0;
}
}
static int iNice = 0;
static int shownice = 0;
if (iNice < m_iNiceTimes)
{
iNice = m_iNiceTimes;
shownice = 500;
}
else if (iNice > m_iNiceTimes) iNice = 0;
shownice -= timer.GetDalyTimes();
if (shownice>0)
{
sprintf(buf, "绝妙", m_iNiceTimes);
m_pMainSuf->DrawText(buf, 0, 0, PGE_WHITE);
}
m_iDummyTimer -= timer.GetDalyTimes();
if (m_iDummyTimer > 0)
{
sprintf(buf, "诱导弹已投放", m_iNiceTimes);
m_pMainSuf->DrawText(buf, 220, 0, PGE_WHITE);
}
else m_iDummyTimer = 0;
//sprintf(buf, "fps:%.2f", GetFrmCount()/((float)timer.GetAllTimes()/1000.f));
//m_pMainSuf->DrawText(buf, 0, 20, PGE_WHITE);
GetDevice()->Flip();
}
PGE_RESULT CBSFYApp::OnWindowProc(HWND hWnd, UINT message
, WPARAM wParam, LPARAM lParam)
{
SRESULT;
if (message == WM_KEYDOWN)
{
if ((int)wParam == 'Q')
{
PostQuitMessage(0);
}
else if((int)wParam == sKeys->vkA)
{
if (m_iStat == normal)
{
m_bPause = !m_bPause;
}
}
else if ((int)wParam == sKeys->vkB || (int)wParam == VK_SPACE)
{
if (m_iStat == winer)
{
m_iStat = menu;
}
else if (m_iStat == menu)
{
if (!m_iMenu)
{
m_iStat = normal;
m_iMaxBullet = 50;
memset(m_Bullet, 0, sizeof(m_Bullet));
m_rPlanePos = RECT(155,175,155+16,175+16);
m_dwLiveTimer = 0;
m_dwActiveTimer = 0;
m_iNiceTimes = 0;
bulletTimer = 5000;
m_iDummyTimer = 0;
m_isroKeybord = 0;
m_isroMouse = 0;
m_bPause = false;
}
else if (m_iMenu == 1)
{
m_iSpeed++;
m_iSpeed = m_iSpeed > 9 ? 1 : m_iSpeed;
}
else if (m_iMenu == 2)
{
m_bSound = !m_bSound;
if (!m_bSound) SoundPlayer.pause(m_BkSnd);
}
else if (m_iMenu == 3)
{
PostQuitMessage(0);
}
}
}
else if ((int)wParam == sKeys->vkUp)
{
if (m_iStat == menu)
{
m_iMenu--;
m_iMenu = m_iMenu<0 ? 3 : m_iMenu;
}
}
else if ((int)wParam == sKeys->vkDown)
{
if (m_iStat == menu)
{
m_iMenu++;
m_iMenu = m_iMenu>3 ? 0 : m_iMenu;
}
}
}
else if (message == WM_LBUTTONDOWN)
{
if (m_iStat == winer)
{
if (PointInRect(m_MouseData.ix, m_MouseData.iy, RECT(278, 218, 320, 240)))
{
char filenm[256];
sprintf(filenm, "%s\\%.3f.bmp", GetAppPath(), (float)m_dwLiveTimer/1000.f);
SaveToBitmapFile(m_pMainSuf, filenm);
sprintf(m_caTitle, "%.3f.bmp保存完毕!", (float)m_dwLiveTimer/1000.f);
m_iMsgTimer = 2000;
}
else m_iStat = menu;
}
else if (m_iStat == menu)
{
if (PointInRect(m_MouseData.ix, m_MouseData.iy, RECT(110, 120, 190, 140)))
{
m_iMenu = 0;
m_iStat = normal;
m_iMaxBullet = 50;
memset(m_Bullet, 0, sizeof(m_Bullet));
m_rPlanePos = RECT(155,175,155+16,175+16);
m_dwLiveTimer = 0;
m_dwActiveTimer = 0;
m_iNiceTimes = 0;
bulletTimer = 5000;
m_iDummyTimer = 0;
m_isroKeybord = 0;
m_isroMouse = 0;
m_bPause = false;
}
else if (PointInRect(m_MouseData.ix, m_MouseData.iy, RECT(110, 143, 190, 163)))
{
m_iMenu = 1;
m_iSpeed++;
m_iSpeed = m_iSpeed > 9 ? 1 : m_iSpeed;
}
else if (PointInRect(m_MouseData.ix, m_MouseData.iy, RECT(110, 166, 190, 189)))
{
m_iMenu = 2;
m_bSound = !m_bSound;
if (!m_bSound) SoundPlayer.pause(m_BkSnd);
}
else if (PointInRect(m_MouseData.ix, m_MouseData.iy, RECT(110, 189, 190, 212)))
{
m_iMenu = 3;
PostQuitMessage(0);
}
}
}
OKRESULT;
RET;
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
if (PGEFAILED(g_BsfyApp.Create(hInstance, PGE_SCREEN_H))) return 0;
g_BsfyApp.Run();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -