16,501
社区成员
发帖
与我相关
我的任务
分享
void CShipDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (m_bGamePause)
return;
CMyShip* pShip = (CMyShip*)m_Objects.GetHead(); // remember that our ship is the first object in object list
//if (GetKeyState(VK_NUMPAD1) == 1){
// if (pShip->GetPos().x > 0)
// pShip->SetPos(pShip->GetPos().x - 5, pShip->GetPos().y);
//}
//else if (GetKeyState(VK_NUMPAD3) == 1) // turn right
//{
// if (pShip->GetPos().x < GAME_WIDTH - SHIP_WIDTH)
// pShip->SetPos(pShip->GetPos().x + 5, pShip->GetPos().y);
//}
if (nChar == VK_NUMPAD1) // turn left
{
if (pShip->GetPos().x > 0)
pShip->SetPos(pShip->GetPos().x - 5, pShip->GetPos().y);
}
else if (nChar == VK_NUMPAD3) // turn right
{
if (pShip->GetPos().x < GAME_WIDTH - SHIP_WIDTH)
pShip->SetPos(pShip->GetPos().x + 5, pShip->GetPos().y);
}
else
if (nChar == VK_SPACE){ //Throw a bomb
CObject* cp = m_Objects.GetHead();
//获得船的位置新建雷子并把雷子加入列表
m_BombList.AddTail(new CBomb(((CMyShip*)m_Objects.GetHead())->GetPos()));
}
//CDialogEx::OnKeyDown(nChar, nRepCnt, nFlags);
}