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
a9486dba
Commit
a9486dba
authored
Jun 03, 2019
by
CjhGm
Browse files
Add different bullet
parent
23d8f9b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
AircraftBattle/PlaneWar/AircraftBattleView.cpp
View file @
a9486dba
...
...
@@ -402,7 +402,26 @@ void CAircraftBattleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
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
());
CBullet
*
bullet1
,
*
bullet2
,
*
bullet3
;
bullet1
=
bullet2
=
bullet3
=
nullptr
;
switch
(
myScore
/
100
)
{
case
0
:
bullet1
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
(),
0
,
30
,
true
);
bulletList
.
AddTail
(
bullet1
);
break
;
case
1
:
bullet1
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
-
10
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
(),
0
,
30
,
true
);
bullet2
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
+
10
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
(),
0
,
30
,
true
);
bulletList
.
AddTail
(
bullet1
);
bulletList
.
AddTail
(
bullet2
);
break
;
default:
bullet1
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
(),
0
,
30
,
true
);
bullet2
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
-
5
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
(),
10
,
30
,
true
);
bullet3
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
+
5
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
(),
-
10
,
30
,
true
);
bulletList
.
AddTail
(
bullet1
);
bulletList
.
AddTail
(
bullet2
);
bulletList
.
AddTail
(
bullet3
);
break
;
}
CBullet
*
bullet
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
(),
0
,
30
,
true
);
bulletList
.
AddTail
(
bullet
);
}
}
...
...
@@ -442,7 +461,7 @@ void CAircraftBattleView::OnLButtonDown(UINT nFlags, CPoint point)
}
else
if
(
myplane
!=
NULL
)
{
// 按鼠标左键发射子弹
CBullet
*
bullet
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
());
CBullet
*
bullet
=
new
CBullet
(
myplane
->
GetPoint
().
x
+
PLANE_WIDTH
/
2
-
BULLET_WIDTH
/
2
,
myplane
->
GetPoint
().
y
,
myplane
->
getDamage
()
,
0
,
30
,
true
);
bulletList
.
AddTail
(
bullet
);
}
...
...
AircraftBattle/PlaneWar/CBullet.cpp
View file @
a9486dba
...
...
@@ -4,15 +4,21 @@
CImageList
CBullet
::
bulletImages
;
// 子弹图像
CBullet
::
CBullet
(
int
x
,
int
y
,
int
_damage
,
int
_speed
)
{
CBullet
::
CBullet
(
int
x
,
int
y
,
int
_damage
,
int
_speed
X
,
int
_speedY
,
bool
_fromMe
)
{
mPoint
.
x
=
x
;
mPoint
.
y
=
y
;
speed
=
_speed
;
speedX
=
_speedX
;
speedY
=
_speedY
;
damage
=
_damage
;
fromMe
=
_fromMe
;
}
int
CBullet
::
getSpeed
()
const
{
return
speed
;
int
CBullet
::
getSpeedX
()
const
{
return
speedX
;
}
int
CBullet
::
getSpeedY
()
const
{
return
speedY
;
}
int
CBullet
::
getDamage
()
const
{
...
...
@@ -26,7 +32,8 @@ CRect CBullet::GetRect() {
//绘制
BOOL
CBullet
::
Draw
(
CDC
*
pDC
,
BOOL
bPause
)
{
if
(
bPause
==
0
)
{
mPoint
.
y
-=
speed
;
mPoint
.
y
-=
speedY
;
mPoint
.
x
-=
speedX
;
//int index = rand() % 15;
return
bulletImages
.
Draw
(
pDC
,
2
,
mPoint
,
ILD_TRANSPARENT
);
}
...
...
AircraftBattle/PlaneWar/CBullet.h
View file @
a9486dba
...
...
@@ -8,15 +8,18 @@
class
CBullet
:
public
CGameObject
{
private:
int
speed
;
bool
fromMe
;
int
speedX
;
int
speedY
;
int
damage
;
protected:
static
CImageList
bulletImages
;
// 子弹图像
public:
CBullet
(
int
x
,
int
y
,
int
_damage
,
int
_speed
=
BULLET_SPEED
);
int
getSpeed
()
const
;
CBullet
(
int
x
,
int
y
,
int
_damage
,
int
_speed
,
int
_speedY
,
bool
_fromMe
);
int
getSpeedX
()
const
;
int
getSpeedY
()
const
;
int
getDamage
()
const
;
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