-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeavyTank.h
133 lines (127 loc) · 2.37 KB
/
HeavyTank.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef GUARD_HEAVY_TANK
#define GUARD_HEAVY_TANK
#include "Enemy.h"
#include "ShooterObject.h"
#include "Bullet.h"
class HeavyTank:public Enemy
{
public:
~HeavyTank(){
ShooterObject::~ShooterObject();
}
HeavyTank(int health = 1):
Enemy(){
m_width = 32;
m_height = 32;
m_health = 2*health;
m_startRow = m_currentRow = 6;
m_startFrame = 4;
m_currentFrame = m_startFrame + ((m_health + 1)/2 - 1)*4;
m_bulletPerShot = 1;
m_bulletSpeed = 6;
m_moveSpeed = 1;
m_textureID = "graphics";
m_position.setX(0);
m_position.setY(0);
m_direction = DOWN;
m_velocity.setY(m_moveSpeed);
}
virtual void 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)/2 - 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;
}
}
}
}
}
virtual void draw()
{
Enemy::draw();
}
virtual void collision()
{
Enemy::collision();
}
virtual void move()
{
Enemy::move();
}
virtual void shot()
{
static int timeBetweenShot = 150;
static int waitForNewShot = 40 + rand()%timeBetweenShot;
static int count = 0;
count++;
if (checkShotPosible() && count > waitForNewShot)
{
Bullet* pBullet = new EnemyBullet(this);
m_bullets.push_back(pBullet);
waitForNewShot = rand()%timeBetweenShot;
count = 0;
}
}
private:
virtual void changeDirection()
{
m_velocity.setX(0);
m_velocity.setY(0);
switch (rand()%4)
{
case UP:
m_direction = UP;
m_velocity.setY(-m_moveSpeed);
break;
case RIGHT:
m_direction = RIGHT;
m_velocity.setX(m_moveSpeed);
break;
case DOWN:
m_direction = DOWN;
m_velocity.setY(m_moveSpeed);
break;
case LEFT:
m_direction = LEFT;
m_velocity.setX(-m_moveSpeed);
break;
default:
break;
}
}
};
#endif