Repository navigation
Expand file tree
/
Copy pathobstacle.cpp
More file actions
93 lines (57 loc) · 1.54 KB
/
Copy pathobstacle.cpp
File metadata and controls
93 lines (57 loc) · 1.54 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
#include "obstacle.h"
using namespace std;
using namespace sf;
obstacle::obstacle()
{
randpos = rand()%640; //Apparition random sur l'axe des x (de 0 à 640)
TextObs.loadFromFile("images/ob1.png");
SpriteObs.setTexture(TextObs); //Set de la texture ob1.png
SpriteObs.setOrigin(sf::Vector2f(SpriteObs.getTexture()->getSize().x/2,SpriteObs.getTexture()->getSize().y/2 ));
SpriteObs.setPosition(sf::Vector2f(randpos, 0));
music.openFromFile("images/impact.ogg");
}
void obstacle::dessiner(sf::RenderWindow *renderWindow)
{
renderWindow->draw(SpriteObs);// dessin de l'asteroide
}
void obstacle::chute()
{
SpriteObs.move(0,hauteur); //baisse de la hauteur
}
float obstacle::getx()
{
return SpriteObs.getPosition().x;
}
float obstacle::gety()
{
return SpriteObs.getPosition().y;
}
float obstacle::getlargeur()
{
return SpriteObs.getPosition().x;
}
float obstacle::gettaille()
{
return SpriteObs.getPosition().y;
}
FloatRect obstacle::getGlobalBounds()
{
return SpriteObs.getGlobalBounds();
}
void obstacle::checkColli(fusee *r1, sf::RenderWindow *renderWindow,score *life)
{
if(r1->getGlobalBounds().intersects(this->getGlobalBounds()) && this->collision != true && life->getImpact() == 0)
{
this->collision = true;
std::cout << "COLLISION" << endl;
clock3.restart();
life->setImpact();
life->retire_vie();
music.play();
}
else if(this->collision == false)
{
this->chute();
this->dessiner(renderWindow);
}
}