-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathitems.py
69 lines (44 loc) · 1.35 KB
/
items.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
from player import add_inv
from uuid import uuid4
import data
item_ttl = 10
def new_item(x, y, blocks, t, ttl=item_ttl):
return {
str(uuid4()): {
'x': x,
'y': y,
'blocks': blocks,
't0': t,
'ttl': ttl
}
}
def despawn_items(items, last_tick):
removed_items = []
for id_, item in items.items():
if item['t0'] + item['ttl'] <= last_tick:
removed_items.append(id_)
for id_ in removed_items:
del items[id_]
return removed_items
def pickup_items(items, players):
picked_up_items = []
for id_, item in items.items():
ix, iy = item['x'], item['y']
for player in players.values():
px, py = player['x'], player['y']
if ix == px and iy in [py, py-1]:
picked_up_items.append(id_)
for block in item['blocks']:
add_inv(player['inv'], block['block'], n=block['num'])
break
for id_ in picked_up_items:
del items[id_]
return picked_up_items
def items_to_render_objects(items, x, offset):
objects = []
for item in items.values():
object_ = data.render_objects['items'].copy()
object_['x'] = item['x'] - x + offset
object_['y'] = item['y']
objects.append(object_)
return objects