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
| #include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Window/Event.hpp>
using namespace sf;
struct Cercle
{
int x;
int y;
int R;
};
bool collision(int,int,Cercle);
int main()
{
Cercle C;
C.x=100;
C.y=100;
C.R=10;
bool Couleur=false;
RenderWindow win(VideoMode(800, 800), "SFML Test");
/// Creation du projectile
CircleShape shape(C.R);
shape.setPosition(C.x,C.y);
while (win.isOpen())
{
Event event;
while (win.pollEvent(event))
{
if (event.type == Event::Closed)
{
win.close();
}
bool Couleur=collision(Mouse::getPosition().x,Mouse::getPosition().y,C);
if (Couleur=true)
{
shape.setFillColor(Color::Green);
}
else
{
shape.setFillColor(Color::Red);
}
}
win.clear();
win.draw(shape);
win.display();
}
return 0;
}
bool collision(int x,int y,Cercle C)
{
int d2 = (x-C.x)*(x-C.x) + (y-C.y)*(y-C.y);
if (d2>C.R*C.R)
return false;
else
return true;
} |