-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastTank.h
92 lines (88 loc) · 1.6 KB
/
FastTank.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
#ifndef GUARD_FASTTANK_H
#define GUARD_FASTTANK_H
#include "Enemy.h"
#include "ShooterObject.h"
#include "Bullet.h"
class FastTank:public Enemy
{
public:
~FastTank(){
ShooterObject::~ShooterObject();
}
FastTank(int health = 1):
Enemy(){
// stupid tank specified
m_width = 32;
m_height = 32;
m_health = health;
m_startRow = m_currentRow = 2;
m_startFrame = 4;
m_currentFrame = m_startFrame + (m_health - 1)*4;
m_bulletPerShot = 1;
m_bulletSpeed = 6;
m_moveSpeed = 4;
m_textureID = "graphics";
m_position.setX(0);
m_position.setY(0);
m_direction = DOWN;
m_velocity.setY(m_moveSpeed);
}
virtual void update()
{
Enemy::update();
}
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