-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.py
53 lines (42 loc) · 1.73 KB
/
screen.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
from pygame import mouse, Rect
from pygame.locals import *
from details import CreatureDetails
from info import InfoView
from playfield import Playfield
class GameScreen(object):
dt = 0.05
def __init__(self, game, player, font, zoom, push, pop):
self._game = game
self._playfield = Playfield(self._game, player, font, zoom,
self._ignoremotion)
self._info = InfoView(self._playfield, font, zoom, push, pop)
self._ignore = None
self.scale(font)
def scale(self, font):
self._font = font
self._playfield.scale(self._font)
self._info.scale(self._font)
def resize(self, size):
self._fieldwidth = max(0, size[0] - self._info.width)
self._playfield.resize((self._fieldwidth, size[1]))
self._info.resize((size[0] - self._fieldwidth, size[1]))
def _ignoremotion(self, rel):
self._ignore = rel
def handle(self, e):
if e.type == MOUSEMOTION and e.rel != self._ignore:
mouse.set_visible(True)
self._ignore = None
if self._playfield.handle(e):
return True
if 'pos' in e.dict:
e.dict['pos'] = (e.pos[0] - self._fieldwidth, e.pos[1])
return self._info.handle(e)
def _playinfosurfaces(self, surface):
size = surface.get_size()
return (surface.subsurface(Rect((0,0),(self._fieldwidth,size[1]))),
surface.subsurface(Rect((self._fieldwidth,0),
(size[0]-self._fieldwidth, size[1]))))
def draw(self, surface):
play, info = self._playinfosurfaces(surface)
self._playfield.draw(play)
self._info.draw(info)