-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemyplane.cpp
More file actions
53 lines (45 loc) · 928 Bytes
/
enemyplane.cpp
File metadata and controls
53 lines (45 loc) · 928 Bytes
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
#include "enemyplane.h"
EnemyPlane::EnemyPlane()
{
m_enemy.load(ENEMY_PATH);
m_X = 2 * WINDOW_W;
m_Y = 0;
m_Free = true;
m_Speed = ENEMY_SPEED;
m_Rect.setWidth(m_enemy.width());
m_Rect.setHeight(m_enemy.height());
m_Rect.moveTo(m_X,m_Y);
m_recorder = 0;
}
void EnemyPlane::updatePosition()
{
if(m_Free)
{
return;
}
m_Y += m_Speed;
m_Rect.moveTo(m_X,m_Y);
if(m_Y >= WINDOW_H + m_Rect.height())
{
m_Free = true;
}
}
void EnemyPlane::shoot()
{
m_recorder++;
if(m_recorder < ENEMY_BULLET_INTERVAL || m_Free)
{
return;
}
m_recorder = 0;
for(int i = 0 ; i < ENEMY_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;
}
}
}