-
Notifications
You must be signed in to change notification settings - Fork 0
/
heroplane.cpp
58 lines (46 loc) · 1.16 KB
/
heroplane.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "heroplane.h"
#include "config.h"
HeroPlane::HeroPlane()
{
//初始化加载飞机图片资源
m_Plane.load(HERO_PATH);
//初始化飞机坐标
m_X = (GAME_WIDTH - m_Plane.width())*0.5;
m_Y = GAME_HEIGHT - m_Plane.height()-20;
//初始化矩形边框
m_Rect.setWidth(m_Plane.width());
m_Rect.setHeight(m_Plane.height());
m_Rect.moveTo(m_X,m_Y);
}
void HeroPlane::shoot()
{
//累加时间间隔记录变量
m_recorder++;
//如果记录的数字,未达到发射子弹时间间隔,直接return不发射子弹
if(m_recorder < BULLET_INTERVAL)
{
return;
}
//达到发射时间
m_recorder=0;
//发射子弹
for(int i = 0;i<BULLET_NUM;i++)
{
//如果是空闲的子弹,进行发射
if(m_bullets[i].m_Free)
{
//将空闲状态改为假
m_bullets[i].m_Free=false;
//设置子弹坐标
m_bullets[i].m_X=m_X + m_Rect.width()*0.5 -10;
m_bullets[i].m_Y=m_Y-25;
break;
}
}
}
void HeroPlane::setPosition(int x, int y)
{
m_X = x;
m_Y = y;
m_Rect.moveTo(m_X,m_Y);
}