Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jiahan Cao
Aircraft-Battle
Commits
5b0bc9b1
Commit
5b0bc9b1
authored
Jun 07, 2019
by
CjhGm
Browse files
modify code
parent
e237c73d
Changes
4
Hide whitespace changes
Inline
Side-by-side
AircraftBattle/PlaneWar/AircraftBattleView.cpp
View file @
5b0bc9b1
...
...
@@ -158,7 +158,7 @@ int CAircraftBattleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
}
//参数初始化
myplane
=
new
CMyPlane
(
false
);
myplane
=
new
CMyPlane
();
isStarted
=
false
;
isPause
=
false
;
isOver
=
false
;
...
...
@@ -227,7 +227,7 @@ void CAircraftBattleView::OnTimer(UINT_PTR nIDEvent)
}
// 刷新显示战机
if
(
myplane
!=
NULL
)
{
myplane
->
Draw
(
&
cdc
,
FALSE
,
FALSE
);
myplane
->
Draw
(
&
cdc
,
FALSE
);
}
// 随机产生敌机和补给包
if
(
myplane
!=
NULL
&&
!
isPause
)
{
...
...
@@ -545,10 +545,9 @@ void CAircraftBattleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
void
CAircraftBattleView
::
OnMouseMove
(
UINT
nFlags
,
CPoint
point
)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if
(
myplane
!=
NULL
&&
isPause
==
0
)
{
//绘制新游戏对象
myplane
->
SetPoint
(
point
.
x
-
PLANE
1
_WIDTH
/
2
,
point
.
y
-
PLANE
1
_HEIGHT
/
2
);
myplane
->
SetPoint
(
point
.
x
-
PLANE_WIDTH
/
2
,
point
.
y
-
PLANE_HEIGHT
/
2
);
}
CView
::
OnMouseMove
(
nFlags
,
point
);
}
...
...
@@ -617,7 +616,7 @@ void CAircraftBattleView::Restart()
{
// TODO: 在此处添加游戏重新开始初始化参数
// 重新加载战机
myplane
=
new
CMyPlane
(
FALSE
);
myplane
=
new
CMyPlane
();
// 清空敌机链表
if
(
enemyList
.
GetCount
()
>
0
)
...
...
AircraftBattle/PlaneWar/GameObject.h
View file @
5b0bc9b1
#pragma once
#include "afx.h"
// 游戏对象的父类,所有游戏对象都继承自它
class
CGameObject
:
public
CObject
{
public:
...
...
AircraftBattle/PlaneWar/MyPlane.cpp
View file @
5b0bc9b1
...
...
@@ -3,75 +3,36 @@
#include "Resource.h"
#include <iostream>
//战机类实现
//静态图像链表
/* 静态图像链表 */
CImageList
CMyPlane
::
images
;
CImageList
CMyPlane
::
images1
;
CImageList
CMyPlane
::
imagespro
;
CMyPlane
::
CMyPlane
(
bool
isUpdate
)
:
CPlane
(
PLANE_HP
,
PLANE_DAMAGE
,
0
,
0
)
{
index
=
isUpdate
?
1
:
0
;
/* 构造函数 */
CMyPlane
::
CMyPlane
()
:
CPlane
(
PLANE_HP
,
PLANE_DAMAGE
,
0
,
0
)
{
mPoint
.
x
=
PLANE_X
;
mPoint
.
y
=
PLANE_Y
;
progress
=
0
;
}
CMyPlane
::~
CMyPlane
(
void
)
{}
//绘制战机
BOOL
CMyPlane
::
Draw
(
CDC
*
pDC
,
BOOL
bPause
,
BOOL
isProtect
)
{
if
(
bPause
==
0
)
{
if
(
isProtect
==
TRUE
)
{
CPoint
point
;
point
.
x
=
mPoint
.
x
-
25
;
point
.
y
=
mPoint
.
y
-
30
;
imagespro
.
Draw
(
pDC
,
0
,
point
,
ILD_TRANSPARENT
);
}
if
(
index
==
1
)
{
if
(
progress
<
14
)
{
images
.
Draw
(
pDC
,
progress
,
mPoint
,
ILD_TRANSPARENT
);
progress
++
;
}
else
{
progress
=
0
;
images
.
Draw
(
pDC
,
progress
,
mPoint
,
ILD_TRANSPARENT
);
}
}
else
{
images1
.
Draw
(
pDC
,
3
,
mPoint
,
ILD_TRANSPARENT
);
}
return
TRUE
;
}
return
FALSE
;
}
/* 绘制战机 */
BOOL
CMyPlane
::
Draw
(
CDC
*
pDC
,
BOOL
bPause
)
{
if
(
bPause
==
0
)
{
return
images
.
Draw
(
pDC
,
index
,
mPoint
,
ILD_TRANSPARENT
);
return
images
.
Draw
(
pDC
,
0
,
mPoint
,
ILD_TRANSPARENT
);
}
return
FALSE
;
}
/
/
加载战机图像
/
*
加载战机图像
*/
BOOL
CMyPlane
::
LoadImage
()
{
//加载游戏对象的图标对象
CBitmap
me
;
//升级战机图像
if
(
!
me
.
LoadBitmapW
(
IDB_BMP_ME
))
return
FALSE
;
CBitmap
me1
;
//未升级战机图像
CBitmap
me1
;
if
(
!
me1
.
LoadBitmapW
(
IDB_BMP_ME1
))
return
FALSE
;
//创建CImageList对象
if
(
!
images
.
Create
(
PLANE_WIDTH
,
PLANE_HEIGHT
,
ILC_COLOR24
|
ILC_MASK
,
14
,
0
))
//nInitial初始个数
return
FALSE
;
//cx,cy 图片的宽度
if
(
!
images1
.
Create
(
PLANE1_WIDTH
,
PLANE1_HEIGHT
,
ILC_COLOR24
|
ILC_MASK
,
4
,
0
))
//nInitial初始个数
return
FALSE
;
//cx,cy 图片的宽度
//图像链表中加入对象对应的图标对象,之后直接通过该链表访问图标对象
images
.
Add
(
&
me
,
RGB
(
0
,
0
,
0
));
images1
.
Add
(
&
me1
,
RGB
(
0
,
0
,
0
));
if
(
!
images
.
Create
(
PLANE_WIDTH
,
PLANE_HEIGHT
,
ILC_COLOR24
|
ILC_MASK
,
4
,
0
))
return
FALSE
;
images
.
Add
(
&
me1
,
RGB
(
0
,
0
,
0
));
return
TRUE
;
}
/* 获取矩形区域 */
CRect
CMyPlane
::
GetRect
()
{
return
CRect
(
mPoint
,
CPoint
(
mPoint
.
x
+
PLANE_WIDTH
,
mPoint
.
y
+
PLANE_HEIGHT
));
}
\ No newline at end of file
AircraftBattle/PlaneWar/MyPlane.h
View file @
5b0bc9b1
...
...
@@ -2,39 +2,21 @@
#include "GameObject.h"
#include "CPlane.h"
#define PLANE_WIDTH 120 // 升级战机图像宽
#define PLANE_HEIGHT 150 // 升级战机图像高
#define PLANE1_WIDTH 120 // 未升级战机图像宽
#define PLANE1_HEIGHT 90 // 未升级战机图像高
#define PLANE_PRO_WIDTH 165 // 保护罩战机图像宽
#define PLANE_PRO_HEIGHT 166 // 保护罩战机图像高
#define PLANE_X 400 // 战机初始位置X
#define PLANE_Y 300 // 战机初始位置Y
#define PLANE_SPEED 30 // 战机默认速度
#define PLANE_DAMAGE 1 // 战机默认伤害
#define PLANE_HP 10 // 战机默认生命
#define PLANE_WIDTH 120 // 未升级战机图像宽
#define PLANE_HEIGHT 90 // 未升级战机图像高
#define PLANE_X 400 // 战机初始位置X
#define PLANE_Y 300 // 战机初始位置Y
#define PLANE_SPEED 30 // 战机默认速度
#define PLANE_DAMAGE 1 // 战机默认伤害
#define PLANE_HP 10 // 战机默认生命
//战机类
class
CMyPlane
:
public
CPlane
{
public:
CMyPlane
(
bool
isUpdate
=
false
);
~
CMyPlane
(
void
);
//绘制
BOOL
Draw
(
CDC
*
pDC
,
BOOL
bPause
,
BOOL
isProtect
);
BOOL
Draw
(
CDC
*
pDC
,
BOOL
bPause
);
//加载战机图像
static
BOOL
LoadImage
();
//得到战机矩形区域
CRect
GetRect
()
{
return
CRect
(
mPoint
,
CPoint
(
mPoint
.
x
+
PLANE_WIDTH
,
mPoint
.
y
+
PLANE_HEIGHT
));
}
class
CMyPlane
:
public
CPlane
{
private:
static
CImageList
images
;
//存储升级战机图片
static
CImageList
images1
;
//存储未升级战机图片
static
CImageList
imagespro
;
//存储防护罩图片
int
index
;
//标记要显示的战机图片下标索引,和战机是否升级相关
int
progress
;
static
CImageList
images
;
public:
CMyPlane
();
// 构造函数
BOOL
Draw
(
CDC
*
pDC
,
BOOL
bPause
);
// 绘制函数
static
BOOL
LoadImage
();
// 加载图像
CRect
GetRect
();
// 重写获取矩形区域
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment