-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunitterrain.pas
69 lines (53 loc) · 1.31 KB
/
unitterrain.pas
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
unit unitTerrain;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, fgl, unitCollidebleImage, raylib;
type TMyList = specialize TFPGList<CollidebleImage>;
type
{ Terrain }
Terrain = class
private
listSolidObjects: TMyList;
public
constructor Create();
procedure Add(image: CollidebleImage);
function IsCollidingWith(other: CollidebleImage): Boolean;
function IsCollidingWithPoint(point: TVector2): Boolean;
procedure Draw();
end;
implementation
constructor Terrain.Create();
begin
listSolidObjects := TMyList.Create;
end;
procedure Terrain.Add(image: CollidebleImage);
begin
listSolidObjects.Add(image);
end;
function Terrain.IsCollidingWith(other: CollidebleImage): Boolean;
var i: integer;
begin
for i := 0 to listSolidObjects.Count-1 do begin
if (other.IsCollidingWithOther(listSolidObjects.Items[i])) then
Exit(true);
end;
Exit(false);
end;
function Terrain.IsCollidingWithPoint(point: TVector2): Boolean;
var i: integer;
begin
for i := 0 to listSolidObjects.Count-1 do begin
if (listSolidObjects.Items[i].IsPointColliding(point)) then
Exit(true);
end;
Exit(false);
end;
procedure Terrain.Draw();
var i: integer;
begin
for i := 0 to listSolidObjects.Count-1 do begin
listSolidObjects.Items[i].Draw()
end;
end;
end.