-
Notifications
You must be signed in to change notification settings - Fork 1
/
tilemap_objects.py
96 lines (66 loc) · 1.84 KB
/
tilemap_objects.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
import tilemap
import ghost
import pacman
import stats
import control
import not_moving_objects
player = None
objects = list()
orange_ghosts_num = 0
def init():
global orange_ghosts_num, player
player = pacman.Pacman()
for i in range(stats.blue_ghosts_num):
objects.append(ghost.BlueGhost())
for i in range(stats.red_ghosts_num):
objects.append(ghost.RedGhost())
for i in range(stats.green_ghosts_num):
objects.append(ghost.GreenGhost())
orange_ghosts_num = stats.orange_ghosts_num
not_moving_objects.start_fruit_thread()
def action():
player.action()
for o in objects:
o.action()
def add_orange_ghost(pos):
global orange_ghosts_num
if orange_ghosts_num > 0:
y_ind, x_ind = pos[0]
if tilemap.tile_map[y_ind][x_ind] != 1:
return
objects.append(ghost.OrangeGhost(x_ind, y_ind))
orange_ghosts_num -= 1
def add_fruit(fruit):
fruits.append(fruit)
def check_win_decorator(function):
def wrapper():
func = function()
if round(100 * tilemap.marked_fields / tilemap.MAP_FIELDS) > 80:
player.reset_position()
control.win()
else:
return func
return wrapper
def check_loss_decorator(function):
def wrapper():
func = function()
if stats.player_lives == 0:
control.game_over()
stats.player_lives = stats.lives
player.reset_position()
else:
return func
return wrapper
@check_loss_decorator
def kill_player():
player.reset_position()
stats.player_lives -= 1
def clear():
global player, objects, orange_ghosts_num
player = None
del objects[:]
def set_pacman_speed(speed):
player.set_speed(speed)
def set_ghost_speed(speed):
for o in objects:
o.set_speed(speed)