-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonster_functions.py
46 lines (39 loc) · 1.2 KB
/
monster_functions.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
from random import randint
from config import FPS, MONSTER_SPEED
def CatchOrRandom(around, state):
if state % (FPS//MONSTER_SPEED[0]) != 0:
return [0, 0]
for i, row in enumerate(around):
if 'P' in row:
return [row.index('P')-1 , i-1]
return [randint(-1, 1), randint(-1, 1)]
def CatchOrStay(around, state):
if state % (FPS//MONSTER_SPEED[0]) != 0:
return [0, 0]
for i, row in enumerate(around):
if 'P' in row:
return [row.index('P')-1 , i-1]
return [0, 0]
def Horizontal(around, state):
if state % (FPS//MONSTER_SPEED[0]) == 0:
if state // (FPS//MONSTER_SPEED[0]) % 4 >=2:
return [1, 0]
else:
return [-1, 0]
return [0, 0]
def Vertical(around, state):
if state % (FPS//MONSTER_SPEED[0]) == 0:
if state // (FPS//MONSTER_SPEED[0]) % 4 >=2:
return [0, -1]
else:
return [0, 1]
return [0, 0]
MONSTERS = {'M': CatchOrRandom, 'S': CatchOrStay, 'H': Horizontal, 'V': Vertical}
if __name__ == '__main__':
around = [
[' ', ' ', 'P'],
[' ', 'M', ' '],
[' ', ' ', ' ']
]
state = 1
print(CatchOrRandom(around, state))