-
Notifications
You must be signed in to change notification settings - Fork 0
/
AESprite.cpp
236 lines (191 loc) · 4.37 KB
/
AESprite.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include "AESprite.h"
using namespace std;
using namespace boost;
namespace AE
{
Type Spr::Sprite = 0;
Type Spr::OneImageSprite = 1;
Type Spr::AnimatedSprite = 2;
/* ---------------- */
/* Classe Spr */
/* ---------------- */
Spr::Spr(Rect<Decimal> initial_position ) : m_position(initial_position), m_last_mouvement(0)
{
m_type.push_back(Spr::Sprite);
}
Spr::~Spr()
{
}
/*bool Spr::isType(Type type_of_spr)
{
vector<Type>::iterator i = m_type.begin();
for(; i != m_type.end(); i++)
{
if(*i == type_of_spr)
return true;
}
return false;
}
bool Spr::operator==(Type type_of_spr)
{
vector<Type>::iterator i = m_type.begin();
for(; i != m_type.end(); i++)
{
if(*i == type_of_spr)
return true;
}
return false;
}
bool Spr::operator!=(Type type_of_spr)
{
vector<Type>::iterator i = m_type.begin();
for(; i != m_type.end(); i++)
{
if(*i == type_of_spr)
return false;
}
return true;
}*/
void Spr::avancer(DVector2D &v)
{
if(m_brain == NULL) // Si ce sprite n'a pas de "cerveau", il peut avancer. Mais s'il en a, c'est le cerveau qui doit faire avancer le sprite.
{
m_position.x += v.x;
m_position.y += v.y;
m_vitesse = v;
m_last_mouvement = SDL_GetTicks();
}
// std::vector< shared_ptr<Object> >::iterator object = m_objects.begin();
// while(object != m_objects.end() )
// {
// (*object)->setPos(m_position); // On déplace aussi les objets connectés au sprite ils sont "connectés" à lui !
// object++;
// }
}
/* void Spr::connect(ObjectPtr object)
{
m_objects.push_back(object);
object->connected_with = SprPtr( this );
object->setPos(m_position);
}*/
void Spr::connect(shared_ptr<SpriteBrain> & brain)
{
if(m_brain != NULL)
m_brain->disconnect();
m_brain = brain;
}
/*void Spr::disconnect( ObjectPtr object)
{
for(int i = 0; i < m_objects.size(); i++)
{
if(m_objects[i] == object)
{
m_objects[i]->connected_with.reset( (Spr*)NULL );
m_objects.erase( m_objects.begin() + i);
}
}
}*/
void Spr::disconnect()
{
if(m_brain != NULL)
m_brain->disconnect();
}
SpriteBrainPtr &Spr::connectedWith()
{
return m_brain;
}
/* void Spr::thereIsCollision(boost::shared_ptr<Object> object, DRect recul)
{
m_position.x += recul.x;
m_position.y += recul.y;
}*/
DVector2D &Spr::getPos()
{
return m_position;
}
void Spr::setPosition(DVector2D &new_pos)
{
m_vitesse = DRect(new_pos.x - m_position.x, new_pos.x - m_position.x);
m_position = new_pos;
}
void Spr::setPosition(DVector2D new_pos)
{
m_vitesse = DRect(new_pos.x - m_position.x, new_pos.x - m_position.x);
m_position = new_pos;
}
int Spr::width()
{
}
int Spr::height()
{
}
void Spr::draw(Surface ou_dessiner)
{
currentImage().apply(ou_dessiner, Rect<Decimal>(), m_position);
}
Surface Spr::currentImage()
{
return Surface();
}
/* ---------------- */
/* Classe Sprite */
/* ---------------- */
Sprite::Sprite(std::string img_to_load, Rect<Decimal> initial_position) : Spr::Spr(initial_position)
, m_image( SurfacePtr( new Surface(img_to_load), SurfaceDeleter() ) )
{
m_type.push_back(Spr::OneImageSprite);
}
Sprite::Sprite(const Sprite &sprite)
{
m_type = sprite.m_type;
m_image = sprite.m_image;
}
Sprite::Sprite(SDL_Surface *img, Rect<Decimal> initial_position) : Spr::Spr(initial_position)
, m_image( SurfacePtr( new Surface(img), SurfaceDeleter() ) )
{
m_type.push_back(Spr::OneImageSprite);
}
Sprite::~Sprite()
{
m_image.reset();
}
int Sprite::width()
{
if(m_image != NULL)
return m_image->width();
}
int Sprite::height()
{
if(m_image != NULL)
return m_image->height();
}
void Sprite::draw(Surface ou_dessiner)
{
if(m_image != NULL)
{
m_image->apply(ou_dessiner, Rect<Decimal>(), m_position);
}
}
void Sprite::free()
{
m_image.reset();
}
void Sprite::load(string chemin)
{
m_image.reset( new Surface(chemin) );
}
void Sprite::load(SDL_Surface *img)
{
free();
m_image.reset( new Surface(img) );
}
Surface Sprite::currentImage()
{
if(m_image != NULL)
{
return *m_image;
}
else
return Surface();
}
}