-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmovement.py
154 lines (145 loc) · 3.36 KB
/
movement.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import random
import map
import globals as g
import math
import openal as al
class vector:
def __init__(self, x=0, y=0, z=0):
self.x=x
self.y=y
self.z=z
def value(self):
return (self.x, self.y, self.z)
def get_distance(x1, y1, z1, x2, y2, z2):
x=abs(x1-x2)
y=abs(y1-y2)
z=abs(z1-z2)
return math.sqrt(x*x+y*y+z*z)
def calculate_angle(x1, y1, x2, y2, deg):
x1=int(x1)
y1=int(y1)
x2=int(x2)
y2=int(y2)
x=x2-x1
y=y1-y2
if x==0:
x+=0.0000001
if y == 0:
y+=0.0000001
rad=0
arctan=0
if x != 0 and y!= 0:
rad=math.atan(y/x)
arctan=rad/3.14*180
fdeg=0
if x >0:
fdeg=360-arctan
elif x < 0:
fdeg=180-arctan
if x ==0:
if y > 0:
fdeg = 180
elif y < 0:
fdeg=0
elif y == 0:
fdeg=0
fdeg-=deg
if fdeg < 0:
fdeg+=360
fdeg=round(fdeg, 0)
if fdeg == 360:
fdeg = 0
return fdeg
def angle_to_string(dir, angle):
angle=turnright(dir, angle)
if angle == 270:
return _("north")
elif angle == 315:
return _("northeast")
elif angle == 0:
return _("east")
elif angle== 45:
return _("southeast")
elif angle == 90:
return _("south")
elif angle == 135:
return _("southwest")
elif angle == 180:
return _("west")
elif angle == 225:
return _("northwest")
if angle > 270 and angle < 315:
return _("northnortheast")
elif angle > 315 and angle < 360:
return _("east northeast")
elif angle > 0 and angle < 45:
return _("east southeast")
elif angle > 45 and angle < 90:
return _("south southeast")
elif angle > 90 and angle < 135:
return _("south southwest")
elif angle > 135 and angle < 180:
return _("west southwest")
elif angle > 180 and angle < 225:
return _("west northwest")
elif angle > 225 and angle < 270:
return _("north northwest")
return ""
def turnleft(deg, inc):
deg-=inc
if deg < 0:
deg+=360
return deg
def turnright(deg, inc):
deg+=inc
if deg >= 360:
deg-=360
return deg
def move(theta, distance):
g.step+=1
tempa = g.me.x+(distance*math.cos((theta*3.14)/180))
tempb=g.me.y+(distance*math.sin((theta*3.14)/180))
tempa=round(tempa, 2)
tempb=round(tempb, 2)
temps=""
if "%d:%d:%d"%(tempa, tempb, g.me.z) in map.tiles:
temps=map.tiles["%d:%d:%d"%(tempa,tempb,g.me.z)]
doorfound=False
for m in map.door:
if get_distance(int(tempa),int(tempb),int(g.me.z),m.x,m.y,m.z) == 0:
if m.open==False:
doorfound=True
break
if "wall" in temps or doorfound:
if g.step >5:
g.step=0
wall=g.oalOpen("sounds/wall.wav", ".wav")
wall.set_source_relative(True)
g.sourcelist.append(wall)
wall.play()
elif "wall" not in temps and doorfound == False:
g.me.x=tempa
g.me.y=tempb
if g.step >5:
g.step=0
if map.mytile() != "":
tempsplit=temps.split("|")
stepsounds=list()
for x in tempsplit:
stepsounds.append(g.oalOpen("sounds/footsteps/"+x+"/"+str(random.randint(1, len(g.find_files("sounds/footsteps/"+x))))+".wav", ".wav"))
for stepsound in stepsounds:
stepsound.set_source_relative(True)
g.sourcelist.append(stepsound)
stepsound.play()
if map.myroom()!="" and map.myroom() != g.currentroom:
g.currentroom=map.myroom()
if g.roomsound.get_state()==al.AL_PLAYING:
g.roomsound.stop()
g.roomsound=g.oalOpen(map.myroom(), ".wav")
g.roomsound.set_looping(True)
# g.sourcelist.append(g.roomsound)
g.roomsound.play()
def getpointer():
tempa = 0+(1*math.cos((g.direction*3.14)/180))
tempb=0+(1*math.sin((g.direction*3.14)/180))
return (tempa, tempb)