-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjetil.cpp
More file actions
73 lines (62 loc) · 1.3 KB
/
Copy pathProjetil.cpp
File metadata and controls
73 lines (62 loc) · 1.3 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
#include "Projetil.h"
using namespace entidades;
Projetil:: Projetil():Entidade(Vector2f(0.,0.), Vector2f(20.,10.), 41) {
ativo = false;
velocidade = Vector2f(0.2, 0.);
}
Projetil::~Projetil() {
}
void Projetil::setAtivo(bool estado) {
ativo = estado;
if(ativo)
body->setFillColor(Color(232, 194, 102));
else {
body->setFillColor(Color::Transparent);
posicao.x = -100;
posicao.y = -100;
}
}
bool Projetil::getAtivo() {
return ativo;
}
void Projetil::move() {
if (ativo) {
posicao.x += velocidade.x;
posicao.y += velocidade.y;
body->setPosition(posicao);
velocidade.y += 0.001f;
}
}
void Projetil::gravar() {
ofstream gravador("save/projetil.dat", ios::app);
if (!gravador)
{
return;
}
gravador << endl << ativo << ' '
<< posicao.x << ' '
<< posicao.y << ' '
<< velocidade.x << ' '
<< velocidade.y;
gravador.close();
}
Lista<Projetil>* Projetil::recuperar() {
ifstream recuperador("save/projetil.dat", ios::in);
Lista<Projetil>* l = new Lista<Projetil>;
bool a;
Vector2f p;
Vector2f v;
if (!recuperador) {
return nullptr;
}
while (!recuperador.eof()) {
recuperador >> a >> p.x >> p.y >> v.x >> v.y;
Projetil* temp = new Projetil();
temp->setAtivo(a);
temp->setPosicao(p);
temp->setVelocidade(v);
l->push(temp);
}
recuperador.close();
return l;
}