/
block.h
114 lines (103 loc) · 2.65 KB
/
block.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
#ifndef __BLOCK_H__
#define __BLOCK_H__
#include "Sprite.h"
#include "CollisionPair.h"
#include <algorithm>
#include <map>
#include "upgrade.h"
#include <stdlib.h>
class Bomb;
class Hero;
class Explosion;
class Enemy;
#define NUM_BLOCK_FILES 7
static const char * block_file_names[NUM_BLOCK_FILES + 1] = {
"img/blocks/tiles_1.bmp",
"img/blocks/tiles_2.bmp",
"img/blocks/tiles_3.bmp",
"img/blocks/tiles_4.bmp",
"img/blocks/tiles_5.bmp",
"img/blocks/tiles_6.bmp",
"img/blocks/tiles_7.bmp",
NULL
};
class Block : public Sprite{
private:
bool solid;
bool isDestroyed;
int upgradeType;
int frame;
public:
Block(int x, int y, bool ifSolid, int rand){
Sprite::setVisible(true);
if (ifSolid)
Sprite::initSprite("img/blocks/tiles_0.bmp");
else
initSprite(NUM_BLOCK_FILES, block_file_names);
frame = 0;
isDestroyed = false;
Sprite::setCoords(x,y);
solid = ifSolid;
if(rand==0)
upgradeType=1;
else if(rand==1)
upgradeType=2;
else if(rand==2)
upgradeType=3;
else if(rand==3)
upgradeType=4;
else
upgradeType=0;
}
~Block() {
}
void update(vector<CollisionPair * > &colList, map<int, Hero*> &heroGroup, vector<Explosion *> &explosionGroup, vector<Upgrade *> &upgradeGroup) {
if (isDestroyed) {
frame ++;
setAnimFrame(frame);
if (frame > 6) {
setVisible(false);
if (upgradeType>0) {
enum colType t;
switch (upgradeType) {
case 1:
t = HeroUpgrade;
break;
case 2:
t = HeroLife;
break;
case 3:
t = HeroSpeed;
break;
case 4:
t = HeroBomb;
break;
default:
break;
}
Upgrade * up = new Upgrade(getX(), getY(), t);
upgradeGroup.push_back(up);
for(map<int, Hero* >::iterator it=heroGroup.begin(); it!=heroGroup.end(); ++it) {
CollisionPair * cp = new CollisionPair(it->second, up, up->getUpType());
colList.push_back(cp);
}
upgradeType = 0;
}
}
}
}
void inCollision(enum colType t){
int tmp;
switch (t) {
case BlockExplosion:
isDestroyed = true;
break;
default:
break;
}
}
bool getSolid(){
return solid;
}
};
#endif