-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirection.py
59 lines (42 loc) · 1.35 KB
/
direction.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import math
#returns theta and distance in tuple, finds angle between player and object, x/y is player, x2/y2 is object
def direction(x, y, x2, y2):
#Flip y-axis of objects for accurate grid and direction
dist = 0
#Switch y values in case of different y grids
if (y > 560) and (y2 < 560) or (y < 560) and (y2 > 560):
#switch y-vals
t = y
y = y2
y2 = t
#calculate theta
xf = x-x2
yf = y-y2
#1st quad 0-90, 2nd quad 90-180, 3rd quad -180 - -90, 4th quad -90-0
theta = math.degrees(math.atan2(yf, xf))
r = math.sqrt((xf ** 2) + (yf ** 2))
return theta, r
if y > 560:
dist = 1120 - y
y = 560 + dist
if y2 > 560:
dist = 1120 - y2
y2 = 560 + dist
if y < 560:
dist = (560) - y
y += (2 * dist)
if y2 < 560:
dist = (560) - y2
y2 += (2 * dist)
xf = x-x2
yf = y-y2
#1st quad 0-90, 2nd quad 90-180, 3rd quad -180 - -90, 4th quad -90-0
theta = math.degrees(math.atan2(yf, xf))
r = math.sqrt((xf ** 2) + (yf ** 2))
return theta, r
#m1 = player, m2 = blackHole
def gravity(distance, m1, m2, gravity):
#finds force based on distance then finds accel of m1
force = gravity * (m1*m2) / (math.sqrt(distance))
accel = force/m1
return accel