-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcollidebleimage.pas
60 lines (47 loc) · 1.24 KB
/
collidebleimage.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
unit unitCollidebleImage;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, raylib;
type CollidebleImage = class
private
image: TImage;
texture: TTexture2D;
position: TVector2;
left, right, top, bottom: Single;
public
constructor Create(_position: TVector2; _image: TImage);
function IsPointColliding(point: TVector2): boolean;
procedure Draw();
end;
implementation
constructor CollidebleImage.Create(_position: TVector2; _image: PImage);
begin
image := _image;
position := _position;
texture := LoadTextureFromImage(image);
left := 0;
right := 256;
top := 0;
bottom := 256;
//left := position.x - image.width / 2;
//right := position.y + image.width / 2;
//top := position.y - image.height / 2;
//bottom := position.y + image.height / 2;
end;
function CollidebleImage.IsPointColliding(point: TVector2): boolean;
var x, y: Single;
begin
if (point.x < left || point.x > right ||
point.y < top || point.y > bottom)
then
return false;
x := point.x - left;
y := point.y - top;
return GetImageColor(image, x, y) != BLANK;
end;
procedure CollidebleImage.Draw();
begin
//DrawTextureV(texture, Vector2Create(left, top), WHITE);
end;
end.