-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.cpp
97 lines (91 loc) · 1.47 KB
/
Enemy.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "Enemy.h"
#include "Bullet.h"
#include <SDL_rect.h>
#include "Collision.h"
Enemy::~Enemy()
{
ShooterObject::~ShooterObject();
}
Enemy::Enemy():
ShooterObject()
{
m_appearTime = 120;
}
void Enemy::update()
{
if (m_bAppearing)
{
doAppearAnimation();
}
else
{
if (m_bDying)
{
doDyingAnimation();
}
else
{
shot();
move();
if (m_velocity.getX() != 0 || m_velocity.getY() != 0)
{
// move animation
m_currentRow = m_currentRow == m_startRow ? m_currentRow + 1 : m_startRow;
// new from shooter object
m_currentFrame = m_startFrame + m_direction + (m_health - 1)*4;
//-----------------------------------------------
}
}
// update bullets
if (!m_bullets.empty())
{
for (std::vector<Bullet*>::iterator it= m_bullets.begin(); it != m_bullets.end();)
{
if ((*it)->dead())
{
delete (*it);
it = m_bullets.erase(it);
}
else
{
(*it)->update();
++it;
}
}
}
}
}
void Enemy::draw()
{
ShooterObject::draw();
}
void Enemy::collision()
{
ShooterObject::collision();
// handle enemy contains bonus
}
void Enemy::move()
{
// check for move capacity
m_canMove = true;
checkMovePosible();
checkObjectsCollision();
checkMapCollision();
//---------------------------------
if (m_canMove)
{
m_position += m_velocity;
// random change direction
if (rand()%100 == 0) // 1%
{
changeDirection();
}
}
else
{
changeDirection();
}
}
void Enemy::shot()
{
}