-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawable.py
49 lines (40 loc) · 1.4 KB
/
drawable.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
import os, time
from config import Config
from graphics import Image, Point, GraphWin, Text
class Drawable(object):
_window = None
@staticmethod
def recreateWindow():
if Drawable._window:
Drawable._window.close()
Drawable._window = GraphWin("LodeRunner", Config.WINDOW_WIDTH+20, Config.WINDOW_HEIGHT+20)
Drawable._window.setBackground('white')
@staticmethod
def lost():
t = Text(Point(Config.WINDOW_WIDTH/2+10, Config.WINDOW_HEIGHT/2+10), 'YOU LOST!')
t.setSize(36)
t.setTextColor('red')
t.draw(Drawable._window)
Drawable._window.getKey()
exit(0)
@staticmethod
def won():
t = Text(Point(Config.WINDOW_WIDTH/2+10, Config.WINDOW_HEIGHT/2+10), 'YOU WON!')
t.setSize(36)
t.setTextColor('red')
t.draw(Drawable._window)
time.sleep(2)
def __init__(self, coords, img_path=None):
if img_path:
self._img = Image(Point((coords[0]+1)*Config.CELL_SIZE-1, (coords[1]+1)*Config.CELL_SIZE-1), os.path.join('graphics', img_path))
else:
self._img = None
def draw(self):
if self._img:
self._img.draw(Drawable._window)
def move_img(self, dx, dy):
if self._img:
self._img.move(dx * Config.CELL_SIZE, dy * Config.CELL_SIZE)
def undraw(self):
if self._img:
self._img.undraw()