-
Notifications
You must be signed in to change notification settings - Fork 0
/
mob.py
31 lines (29 loc) · 829 Bytes
/
mob.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
from random import randint
next_id = 1
class Mob:
def __init__(self, x, y, type):
global next_id
self.x = x
self.y = y
self.type = type
self.id = next_id
next_id += 1
def tick(self, server, map):
dir = randint(1,4)
nx = self.x
ny = self.y
if dir == 1:
ny = self.y - 1
elif dir == 2:
nx = self.x + 1
elif dir == 3:
ny = self.y + 1
else:
nx = self.x - 1
if map.is_passable(nx,ny,self):
self.x = nx
self.y = ny
server.broadcast({'mobupdate': {'id': self.id,
'type': 2, # HACK FIXME
'x': self.x,
'y': self.y}})