-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckcollisionpointpolyexample.lpr
60 lines (47 loc) · 1.86 KB
/
checkcollisionpointpolyexample.lpr
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
program checkcollisionpointpolyexample;
uses
raylib, // Bibliothèque raylib
raymath; // Bibliothèque raymath pour utiliser Vector2
const
ScreenWidth = 800;
ScreenHeight = 600;
PolygonPointsCount = 6; // Nombre de points dans le polygone
var
Polygon: array[0..PolygonPointsCount-1] of TVector2; // Sommets du polygone
i: Integer;
MousePosition: TVector2;
InsidePolygon: Boolean;
begin
// Initialisation de la fenêtre
InitWindow(ScreenWidth, ScreenHeight, 'CheckCollisionPointPoly Example');
SetTargetFPS(60);
// Définition des sommets du polygone (hexagone, par exemple)
Polygon[0] := Vector2Create(400, 200);
Polygon[1] := Vector2Create(450, 250);
Polygon[2] := Vector2Create(450, 320);
Polygon[3] := Vector2Create(400, 370);
Polygon[4] := Vector2Create(350, 320);
Polygon[5] := Vector2Create(350, 250);
while not WindowShouldClose() do
begin
// Position de la souris
MousePosition := GetMousePosition();
// Vérification de la collision entre le point et le polygone
InsidePolygon := CheckCollisionPointPoly(MousePosition, @Polygon[0], PolygonPointsCount);
BeginDrawing();
ClearBackground(RAYWHITE);
// Affichage du polygone (change de couleur si la souris est dedans)
if InsidePolygon then
DrawPoly(Vector2Create(400, 285), PolygonPointsCount, 80, 0, GREEN) // Polygone vert si collision
else
DrawPoly(Vector2Create(400, 285), PolygonPointsCount, 80, 0, RED); // Polygone rouge sinon
// Affichage des informations sur la souris
DrawText('Placez la souris à l''intérieur du polygone', 10, 10, 20, DARKGRAY);
if InsidePolygon then
DrawText('Souris à l''intérieur du polygone', 10, 40, 20, GREEN)
else
DrawText('Souris en dehors du polygone', 10, 40, 20, RED);
EndDrawing();
end;
CloseWindow();
end.