-
Notifications
You must be signed in to change notification settings - Fork 0
/
special.py
45 lines (22 loc) · 1.05 KB
/
special.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
# A Special is a Simulton; it updates by removing
# any Hunter whose center is contained within its radius
# (returning a set of all eaten simultons), and
# displays as a black PacMan with a radius of 40
# Calling get_dimension for the width/height (for
# containment and displaying) will facilitate
import simulton
import hunter
from PIL.ImageTk import PhotoImage
class Special(simulton.Simulton):
def __init__(self, x, y):
self._image = PhotoImage(file = 'pac.jpg')
simulton.Simulton.__init__(self, x, y, 40, 40)
def update(self, model):
eaten_set = model.find(lambda s : isinstance(s, hunter.Hunter) and self.contains(s.get_location()))
for s in eaten_set:
model.remove(s)
return eaten_set
def contains(self, r):
return self.distance(r) <= self.get_dimension()[1]/2
def display(self, root_canvas):
root_canvas.create_image(self._x, self._y, image = self._image)