-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cs
108 lines (81 loc) · 2.68 KB
/
Game.cs
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
using Raylib_cs;
using System.Numerics;
using System;
using QuadtreeImplementation;
class QuadtreeImp
{
public static void GetUserInput(Point user)
{
int moveSpeed = 5;
if (Raylib.IsKeyDown(KeyboardKey.Up))
{
user.Y -= moveSpeed;
}
if (Raylib.IsKeyDown(KeyboardKey.Down))
{
user.Y += moveSpeed;
}
if (Raylib.IsKeyDown(KeyboardKey.Right))
{
user.X += moveSpeed;
}
if (Raylib.IsKeyDown(KeyboardKey.Left))
{
user.X -= moveSpeed;
}
}
public static Rectangle[] CreateBorder()
{
Rectangle[] border =
[
new(350, 50, new(600, 15)),
new(350, 600, new(600, 15)),
new(350, 50, new(15, 550)),
new(950, 50, new(15, 565)),
];
return border;
}
public static void Main()
{
Raylib.InitWindow(1920, 1080, "Quadtree");
int randomRVal = new Random().Next(0, 256);
int randomGVal = new Random().Next(0, 256);
int randomBVal = new Random().Next(0, 256);
QuadTree qTree = new (new Rectangle( 0, 0, new Vector2( Raylib.GetScreenWidth(), Raylib.GetScreenHeight())), new(randomRVal, randomGVal, randomBVal, 255));
Raylib.SetTargetFPS(60);
List<Point> points = new List<Point>();
//Point user = new Point(10, Color.Black, Raylib.GetScreenWidth()/2, Raylib.GetScreenHeight()/2);
//points.Add(user);
foreach (Point p in points)
qTree.Insert(p);
int prevPointsCount = points.Count;
while (!Raylib.WindowShouldClose())
{
//GetUserInput(user);
if (Raylib.IsMouseButtonPressed(MouseButton.Left))
{
Point p = new Point(5, Color.Black, Raylib.GetMouseX(), Raylib.GetMouseY());
points.Add(p);
}
int currPointsCount = points.Count;
if (prevPointsCount != currPointsCount)
{
foreach (Point p in points)
{
if (!qTree.Points.Contains(p))
qTree.Insert(p);
}
}
prevPointsCount = currPointsCount;
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.RayWhite);
qTree.Draw();
foreach (Point p in points)
{
Raylib.DrawCircleV(new(p.X, p.Y), p.Radius, p.Color);
}
Raylib.DrawFPS(10, 10);
Raylib.EndDrawing();
}
}
}