forked from thundee/python-simple-collision-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.py
41 lines (29 loc) · 961 Bytes
/
sample.py
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
import collider
import math
#Declare sides(Note, that lines are relative to [0, 0])
rect_sides = [
collider.create_line(-2, 2, 2, 2),
collider.create_line(2, 2, 2, -2),
collider.create_line(2, -2, -2, -2),
collider.create_line(-2, -2, -2, 2)
]
#Create polygon at [5, 0]
rectangle = collider.Polygon(rect_sides, 5, 0)
#Rotate polygon
rectangle.rotate(math.radians(45))
#Move 10 points along X axis and 5 along y axis
#End position is [15, 5]
rectangle.move(10, 5)
#Create new polygon...
triangle_sides = [
collider.create_line(-2, 0, 0, 2),
collider.create_line(0, 2, 2, 0),
collider.create_line(2, 0, -2, 0)
]
#Placing new polygon nearly the recrangle
triangle = collider.Polygon(triangle_sides, 12, 5)
print('Is collision detected: ' + str(triangle.check_collision(rectangle)))
print('Moving triangle...')
triangle.move(-8, 0)
print('Is collisition detected: ' + str(triangle.check_collision(rectangle)))
print('Done!')