-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
245 lines (203 loc) · 4.83 KB
/
util.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
import math
import config
from RoguePy.UI import Colors
from RoguePy.libtcod import libtcod
from math import pi, atan2
rand = libtcod.random_get_instance()
def randint(mx, mn=0):
return libtcod.random_get_int(rand, mn, mx)
def randfloat(mx, mn=0):
return libtcod.random_get_float(rand, mn, mx)
degToRad = pi / 180
radToDeg = 180 / pi
halfPi = pi / 2
twoPi = pi * 2
def dist(x1, y1, x2, y2):
dist = math.sqrt((1.0*x2 - x1)**2 + (y2 - y1)**2)
return dist
def bearing(ax, ay, bx, by):
theta = -1 * (atan2(bx - ax, ay - by) - halfPi)
if theta < 0.0:
theta += twoPi
return radToDeg * theta
colors = [
Colors.dark_green,
Colors.dark_yellow,
Colors.dark_orange,
Colors.dark_red
]
indexes = [0, 33, 66, 100]
colorMap = libtcod.color_gen_map(colors, indexes)
# Returns a red -> green gradient color for values 0 - 100
def getColor(val):
return colorMap[val]
def getPirateName():
first = [
"Captain",
"Fluffbucket",
"Dirty",
"Squidlips",
"Bowman",
"Buccaneer",
"Two Toes",
"Sharkbait",
"Ol'",
"Peg Leg",
"Scallywag",
"Bucko",
"Dead man",
"Matey",
"Jolly",
"Stinky",
"Bloody",
"Miss",
"Mad",
"Red",
"Lady",
"Bretheren",
"Rapscallion",
"Landlubber",
"Wench",
"Freebooter",
"One Eye",
"Fishy",
"Long John",
"Rogue",
"Ironhook",
"Gunpowder",
"Sassy",
"Walker"
]
middle = [
"Creeper",
"Head",
"Squiffy",
"Jim",
"Cackle",
"Gold",
"Storm",
"Patch",
"Yellow",
"John",
"Bones",
"Felony",
"George",
"Plank",
"Eddie",
"Greedy",
"Bay",
"Rat",
"Sea",
"Thomas",
"Jack",
"Mama",
"Spot",
"Legs",
"Spike",
"Lagoon",
"Stubbs",
"Slappy",
"Claw",
"Parrot",
"Hook",
"Black Jack"
]
last = [
"From the West",
"Kidd",
"Byrd",
"O'Malley",
"Jackson",
"Barnacle",
"Sparrow",
"Holystone",
"of the Coast",
"Hornswaggle",
"Jones",
"McStinky",
"Ned Head",
"Swashbuckler",
"Bart",
"Sea Wolf",
"O'Fish",
"Beard",
"Chumbucket",
"Rivers",
"Morgan",
"Tuna Breath",
"Three Gates",
"Bailey",
"of Atlantis",
"of Dark Water",
"Skurvy",
"Sea Rat",
"McGee",
"Smuggler",
"Rat Breath",
"Slag",
"of the Sea"
]
return "{} {} {}".format(
first[randint(len(first) - 1)], middle[randint(len(middle) - 1)], last[randint(len(last) - 1)])
def pathFunc(x1, y1, x2, y2, map):
c = map.getCell(x2, y2)
if not c:
return 0
if c.terrain.passable:
return 1
else:
return 0
def getPath(map):
path = libtcod.path_new_using_function(config.world['width'], config.world['height'], pathFunc, map, 0)
return path
def checkPath(map, x1, y1, x2, y2, myPath=None):
if not myPath:
path = getPath(map)
delete = True
else:
path = myPath
delete = False
c1 = map.getCell(x1, y1)
c2 = map.getCell(x2, y2)
libtcod.path_compute(path, x1, y1, x2, y2)
s = libtcod.path_size(path)
if delete:
deletePath(path)
if s:
return True
else:
return False
def pathSize(path):
return libtcod.path_size(path)
def deletePath(path):
libtcod.path_delete(path)
def pathWalk(path):
return libtcod.path_walk(path, True)
###################################################
# LEADERBOARD FUNCTIONS
import requests
import json
private = "ss6hMRk1NUWE1cQa6Nt3hggVIwqDH3RUq_mPyjM7jxHQ"
public = "58c36b3ed60245055cd31378"
host = "http://dreamlo.com/lb/"
def addScore(name, score):
url = host + private + "/add/" + name + "/" + str(score)
response = requests.get(url)
print "Response from high score server: {}".format(response)
def getScores():
url = host + private + "/json"
response = requests.get(url)
jsonData = json.loads(response.text)
scores = []
if len(jsonData['dreamlo']['leaderboard']) > 0:
entries = jsonData['dreamlo']['leaderboard']['entry']
if isinstance(entries, list):
for entry in entries:
scores.append(getScore(entry))
else:
scores.append(getScore(entries))
return scores
def getScore(entry):
parts = entry['date'].split(" ")
date = parts[0]
return entry['name'] + ":" + entry['score'] + ":" + date