-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspriteStruct.h
More file actions
136 lines (109 loc) · 3.56 KB
/
spriteStruct.h
File metadata and controls
136 lines (109 loc) · 3.56 KB
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
134
135
136
#include "player.h"
#include "explodingSprite.h"
#include "smartSprite.h"
struct SpriteStruct : public Drawable {
SpriteStruct(const std::string& name)
:
Drawable(name,
Vector2f(Gamedata::getInstance().getXmlInt(name+"/Loc/X"),
Gamedata::getInstance().getXmlInt(name+"/Loc/Y")),
Vector2f(Gamedata::getInstance().getXmlInt(name+"/SpeedX"),
Gamedata::getInstance().getXmlInt(name+"/SpeedY")),
0,0,
Gamedata::getInstance().getXmlInt(name+"/Depth")
)
,sprite(new Sprite(name))
, explodingSprite(new ExplodingSprite(*sprite))
, theSprite(sprite)
, exploded(false)
{ }
SpriteStruct(const string& name, const Vector2f& pos, const Vector2f& vel)
: Drawable(name,
Vector2f(Gamedata::getInstance().getXmlInt(name+"/Loc/X"),
Gamedata::getInstance().getXmlInt(name+"/Loc/Y")),
Vector2f(Gamedata::getInstance().getXmlInt(name+"/SpeedX"),
Gamedata::getInstance().getXmlInt(name+"/SpeedY")),
0,0,
Gamedata::getInstance().getXmlInt(name+"/Depth")
)
,sprite(new Sprite(name,pos,vel))
, explodingSprite(new ExplodingSprite(*sprite))
, theSprite(sprite)
, exploded(false)
{ }
SpriteStruct(const string& name, const Vector2f& pos, const Vector2f& vel, Player* enemy)
: Drawable(name,
Vector2f(Gamedata::getInstance().getXmlInt(name+"/Loc/X"),
Gamedata::getInstance().getXmlInt(name+"/Loc/Y")),
Vector2f(Gamedata::getInstance().getXmlInt(name+"/SpeedX"),
Gamedata::getInstance().getXmlInt(name+"/SpeedY")),
0,0,
Gamedata::getInstance().getXmlInt(name+"/Depth")
)
,sprite(new SmartSprite(name,pos,vel, enemy))
, explodingSprite(new ExplodingSprite(*sprite))
, theSprite(sprite)
, exploded(false)
{ }
SpriteStruct(const SpriteStruct& s):
Drawable(s),
sprite(new Sprite(s.getName())),
explodingSprite(new ExplodingSprite(*sprite)),
theSprite(sprite),
exploded(false) {
}
SpriteStruct& operator=(const SpriteStruct& s){
if (this == &s) return *this;
Drawable::operator=(s);
delete sprite;
delete explodingSprite;
delete theSprite;
sprite = new Sprite(s.getName());
explodingSprite =new ExplodingSprite(*sprite);
theSprite = sprite;
exploded = false;
return *this;
}
~SpriteStruct(){
delete sprite;
delete explodingSprite;
//delete theSprite;
}
void reset(){
exploded=false;
X(Gamedata::getInstance().getXmlInt(getName()+"/Loc/X"));
Y(Gamedata::getInstance().getXmlInt(getName()+"/Loc/Y"));
theSprite=sprite;
static_cast<ExplodingSprite*>(explodingSprite)->reset(getPosition());
}
const Frame* getFrame() const { return theSprite->getFrame(); }
void draw() const {
theSprite->draw();
}
void update(Uint32 ticks) {
theSprite->update(ticks);
}
// This function will check to see if the player collided with theSprite
// only if theSprite did not explode yet
bool hit(const Player* player) {
// check if exploded
if (!exploded) {
if ( player->newcollideWith((Drawable*)(theSprite) )){
//std::cout << "I collided with " << theSprite->getName() << std::endl;
exploded = true;
Vector2f position(theSprite->getPosition());
// std::cout << "Ops" <<theSprite->getName() << std::endl;
static_cast<ExplodingSprite*>(explodingSprite)->
reset(position);
theSprite = explodingSprite;
// std::cout <<theSprite->getName() << std::endl;
return true;
}
}
return false;
}
Sprite* sprite;
Sprite* explodingSprite;
Sprite* theSprite;
bool exploded;
};