Commit 80e75d8d authored by CjhGm's avatar CjhGm
Browse files

Add gameover

parent c1fa510f
......@@ -22,6 +22,7 @@
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include <cassert>
// CAircraftBattleView
......@@ -152,16 +153,16 @@ int CAircraftBattleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
startIMG.Add(&startbmp, RGB(0, 0, 0));
//场景初始化失败
if (!scene.InitScene())
{
if (!scene.InitScene()) {
AfxMessageBox(L"图片资源加载失败");
exit(0);
}
//参数初始化
myplane = new CMyPlane(FALSE);
myplane = new CMyPlane(false);
isStarted = false;
isPause = false;
isOver = false;
SetTimer(4, 40, NULL);//背景滚动定时器
SetMyTimer();
......@@ -193,7 +194,7 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
//替换cdc原本的缓冲区为缓冲位图,这样cdc输出的内容就写到了缓冲位图中
CBitmap* pOldBit = cdc.SelectObject(cacheBitmap);
if (isStarted == FALSE) {
if (!isStarted && !isOver) {
//欢迎界面
scene.StickScene(&cdc, -1, rect);
startIMG.Draw(&cdc, 0, CPoint(rect.right / 2 - 173, 100), ILD_TRANSPARENT);
......@@ -220,18 +221,8 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
cdc.TextOutW(rect.right / 2 - off, 210 + 12 * space, _T("魔法值随着游戏进程增加,可通过使用魔法值使用防护罩、战机升级、战机大招的使用。"));
cdc.TextOutW(rect.right / 2 - off, 210 + 13 * space, _T("游戏过程中会有一定程度的血包出现以恢复生命值。"));
cdc.TextOutW(rect.right / 2 - off, 210 + 14 * space, _T("随着关卡增多,敌机、炮弹速度和数量均增加,通过10关即可通关!"));
//将二级缓冲cdc中的数据推送到一级级缓冲pDC中,即输出到屏幕中
pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &cdc, 0, 0, SRCCOPY);
//释放二级cdc
cdc.DeleteDC();
//释放缓冲位图
cacheBitmap->DeleteObject();
//释放一级pDC
ReleaseDC(pDC);
CView::OnTimer(nIDEvent);
return;
}
else {
else if (isStarted && !isOver) {
// 游戏界面
scene.StickScene(&cdc, 1, rect);
if (nIDEvent == 4) {
......@@ -320,13 +311,78 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
CRect tmpRect;
if (tmpRect.IntersectRect(&(myplane->GetRect()), &(enemy->GetRect()))) {
// 战机和敌机区域有重合,即战机撞到敌机
myplane->decreaseHp(10 * enemy->getDamage());
myplane->decreaseHp(2 * enemy->getDamage());
enemyList.RemoveAt(tmpEnemyPos);
delete enemy;
enemy = NULL;
break;
}
}
//游戏界面输出该游戏当前信息
if (myplane != NULL)
{
HFONT font;
font = CreateFont(15, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 10, 0);
cdc.SelectObject(font);
CString str;
cdc.SetTextColor(RGB(255, 0, 0));
//设置透明背景
cdc.SetBkMode(TRANSPARENT);
/*str.Format(_T("当前关卡:%d"), passNum);
cdc.TextOutW(10, 0, str);
str.Format(_T("当前命数:%d"), lifeNum);
cdc.TextOutW(110, 0, str);
str.Format(_T("当前得分:%d"), passScore);
cdc.TextOutW(10, 15, str);
if (test == TRUE) {
cdc.TextOutW(10, 200, _T("无敌模式!!!"));
}*/
HFONT font1;
font1 = CreateFont(8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 10, 0);
cdc.SelectObject(font);
cdc.SetTextColor(RGB(255, 0, 0));
cdc.TextOutW(rect.right - 12 * PLANE_HP - 45, 0, _T("血量:"));
//输出血条
CBrush brush;
brush.CreateSolidBrush(RGB(255, 0, 0));
CBrush* oldBrush = cdc.SelectObject(&brush);
int leftPos, topPos = 0, rightPos, buttomPos = 12;
leftPos = rect.right - 12 * PLANE_HP;
rightPos = leftPos + 12 * myplane->getHp();
cdc.Rectangle(leftPos, topPos, rightPos, buttomPos);
brush.DeleteObject();
//输出血条中的详细血值
HFONT textFont;
textFont = CreateFont(12, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 10, 0);
cdc.SelectObject(textFont);
cdc.SetTextColor(RGB(255, 255, 255));
str.Format(_T("%d/%d"), myplane->getHp(), PLANE_HP);
cdc.TextOutW(rect.right - 12 * PLANE_HP + 12 * 4, 0, str);
}
if (myplane != NULL && !myplane->isAlive()) {
gameOver(pDC, cdc, cacheBitmap);
isOver = true;
}
}
else if (isOver) {
// 游戏结束
HFONT textFont;
textFont = CreateFont(18, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 10, 0);
cdc.SelectObject(textFont);
//设置透明背景
cdc.SetBkMode(TRANSPARENT);
cdc.SetTextColor(RGB(255, 255, 255));
//显示最后结果
CString str;
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2 - 30, _T("GAME OVER!"));
//str.Format(_T("您的得分为:%d"), myScore);
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2 - 10, str);
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2 + 10, _T("不要灰心!再来一次!"));
cdc.TextOutW(rect.right / 2 - 100, rect.bottom / 2 + 40, _T("是否重新开始?Y/N"));
}
//将二级缓冲cdc中的数据推送到一级级缓冲pDC中,即输出到屏幕中
......@@ -344,18 +400,29 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
void CAircraftBattleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
//按空格进入游戏
if (isStarted == false) {
if (!isStarted) {
if (GetKeyState(VK_SPACE) < 0) {
isStarted = true;
}
}
else {
else if (!isOver){
if (myplane != NULL && GetKeyState(VK_SPACE) < 0) {
// 按空格键发射子弹
CBullet* bullet = new CBullet(myplane->GetPoint().x + PLANE_WIDTH / 2 - BULLET_WIDTH / 2, myplane->GetPoint().y, myplane->getDamage());
bulletList.AddTail(bullet);
}
}
else {
assert(isOver);
if (GetKeyState('Y') < 0) {
isOver = false;
Restart();
}
else if (GetKeyState('N') < 0) {
MyDialog dlg;
dlg.DoModal();
}
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
......@@ -462,7 +529,6 @@ void CAircraftBattleView::gameOver(CDC* pDC, CDC& cdc, CBitmap* cacheBitmap)
KillTimer(3);
//KillTimer(4);
KillTimer(5);
//计算最后得分
//播放游戏结束音乐
PlaySound((LPCTSTR)IDR_WAV_GAMEOVER, AfxGetInstanceHandle(), SND_RESOURCE | SND_ASYNC);
//清屏
......
......@@ -51,14 +51,11 @@ public:
bool isStarted; // 标记欢迎界面是否加载完成
bool isPause; // 是否暂停
bool isOver; // 是否游戏结束
CImageList startIMG;
// 操作
public:
//获取战机速度
int GetSpeed();
//设置战机速度
void SetSpeed(int speed);
//游戏暂停
void Pause();
//游戏重新开始
......
......@@ -73,49 +73,86 @@ END
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON "res\\PlaneWar.ico"
IDR_AircraftBattleTYPE ICON "res\\PlaneWarDoc.ico"
IDR_AircraftBattleTYPE ICON "res\\PlaneWarDoc.ico"
IDI_FILE_VIEW ICON "res\\file_view.ico"
IDI_FILE_VIEW_HC ICON "res\\file_view_hc.ico"
IDI_CLASS_VIEW ICON "res\\class_view.ico"
IDI_CLASS_VIEW_HC ICON "res\\class_view_hc.ico"
IDI_OUTPUT_WND ICON "res\\output_wnd.ico"
IDI_OUTPUT_WND_HC ICON "res\\output_wnd_hc.ico"
IDI_PROPERTIES_WND ICON "res\\properties_wnd.ico"
IDI_PROPERTIES_WND_HC ICON "res\\properties_wnd_hc.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDR_MAINFRAME BITMAP "res\\Toolbar.bmp"
IDR_MAINFRAME_256 BITMAP "res\\Toolbar256.bmp"
IDR_SORT BITMAP "res\\sort.bmp"
IDB_SORT_24 BITMAP "res\\sort_hc.bmp"
IDB_FILE_VIEW BITMAP "res\\fileview.bmp"
IDB_FILE_VIEW_24 BITMAP "res\\fileview_hc.bmp"
IDB_CLASS_VIEW BITMAP "res\\classview.bmp"
IDB_CLASS_VIEW_24 BITMAP "res\\classview_hc.bmp"
IDR_EXPLORER BITMAP "res\\explorer.bmp"
IDB_EXPLORER_24 BITMAP "res\\explorer_hc.bmp"
IDR_MENU_IMAGES BITMAP "res\\menuimages.bmp"
IDB_MENU_IMAGES_24 BITMAP "res\\menuimages_hc.bmp"
IDR_PROPERTIES BITMAP "res\\properties.bmp"
IDB_PROPERTIES_HC BITMAP "res\\properties_hc.bmp"
IDB_BMP_EXPLOSION BITMAP "image\\explosion.BMP"
IDB_BMP_BLOOD BITMAP "image\\blood.bmp"
IDB_BMP_ME1 BITMAP "image\\me1.bmp"
IDB_BMP_BOMB BITMAP "image\\bomb.bmp"
IDB_BMP_ME BITMAP "image\\me.bmp"
IDB_BMP_BALLDOWN BITMAP "image\\balldown.bmp"
IDB_BMP_BALLUP BITMAP "image\\ballup.bmp"
IDB_BMP_PROTECT BITMAP "image\\protect.bmp"
IDB_BMP_BOSS BITMAP "image\\boss.bmp"
IDB_BMP_BOMB1 BITMAP "image\\bomb1.bmp"
IDB_BMP_ENEMYDOWN BITMAP "image\\enemyDown.bmp"
IDB_BMP_ENEMYUP BITMAP "image\\enemyUp.bmp"
IDB_BMP_TITLE BITMAP "image\\title.bmp"
/////////////////////////////////////////////////////////////////////////////
//
// Toolbar
......@@ -238,7 +275,7 @@ BEGIN
END
POPUP "帮助(&H)"
BEGIN
MENUITEM "关于 AircraftBattle(&A)...", ID_APP_ABOUT
MENUITEM "关于 AircraftBattle(&A)...", ID_APP_ABOUT
END
END
......@@ -293,7 +330,7 @@ END
IDR_HELP_MENU MENU
BEGIN
MENUITEM "关于 AircraftBattle(&A)...", ID_APP_ABOUT
MENUITEM "关于 AircraftBattle(&A)...", ID_APP_ABOUT
END
IDR_THEME_MENU MENU
......@@ -341,12 +378,10 @@ CAPTION "谢谢使
FONT 9, "MS Shell Dlg", 0, 0, 0x1
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,14,14,20,20
LTEXT "AircraftBattle,1.2 版",IDC_STATIC,42,12,114,8,SS_NOPREFIX
LTEXT "Copyright (C) 2015",IDC_STATIC,42,24,114,8
LTEXT "Aircraft Battle 飞机大战",IDC_STATIC,42,12,114,8,SS_NOPREFIX
LTEXT "Copyright (C) 2019",IDC_STATIC,42,24,114,8
DEFPUSHBUTTON "退出",IDOK,153,68,50,14,WS_GROUP
LTEXT "学院:信息科学与工程学院",IDC_STATIC,42,36,114,8
LTEXT "作者:林宇强",IDC_STATIC,42,59,114,8
LTEXT "班级:计算机科学与技术2013-4班",IDC_STATIC,43,48,114,8
LTEXT "感谢使用!",IDC_STATIC,42,36,114,8
END
IDD_DIALOG1 DIALOGEX 0, 0, 309, 176
......@@ -450,15 +485,24 @@ END
//
IDR_WAV_BACKGROUND WAVE "sound\\background.wav"
IDR_WAV_BOMB WAVE "sound\\bomb.wav"
IDR_WAV_EXPLOSION WAVE "sound\\explosion.wav"
IDR_WAV_DAZHAO WAVE "sound\\dazhao.wav"
IDR_WAV_GAMEOVER WAVE "sound\\game_over.wav"
IDR_WAV_PROTECT WAVE "sound\\protect.wav"
IDR_WAV_UPDATE WAVE "sound\\update.wav"
IDR_WAV_BLOOD WAVE "sound\\blood.wav"
IDR_WAV_BALL WAVE "sound\\ball.wav"
/////////////////////////////////////////////////////////////////////////////
//
// AFX_DIALOG_LAYOUT
......
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 AircraftBattle.rc 使用
// 供 PlaneWar.rc 使用
//
#define IDR_WAV_BLOOD 4
#define IDD_ABOUTBOX 100
......@@ -15,7 +15,7 @@
#define ID_VIEW_CUSTOMIZE 126
#define IDR_MAINFRAME 128
#define IDR_MAINFRAME_256 129
#define IDR_AircraftBattleTYPE 130
#define IDR_AircraftBattleTYPE 130
#define ID_WINDOW_MANAGER 131
#define ID_VIEW_FILEVIEW 133
#define ID_VIEW_CLASSVIEW 134
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment