1
# This code is so you can run the samples without installing the package
4
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..'))
6
from cocos.layer import *
7
from cocos.text import *
8
from cocos.actions import *
11
from pyglet.gl import *
13
from status import status
15
class BackgroundLayer( Layer ):
17
super( BackgroundLayer, self ).__init__()
18
self.img = pyglet.resource.image('background.png')
26
class ScoreLayer( Layer ):
28
w,h = director.get_window_size()
29
super( ScoreLayer, self).__init__()
32
self.add( ColorLayer(32,32,32,32, width=w, height=48),z=-1 )
34
self.position = (0,h-48)
36
self.score= Label('Score:', font_size=36,
37
font_name='Edit Undo Line BRK',
38
color=(255,255,255,255),
41
self.score.position=(0,0)
44
self.lines= Label('Lines:', font_size=36,
45
font_name='Edit Undo Line BRK',
46
color=(255,255,255,255),
49
self.lines.position=(235,0)
52
self.lvl= Label('Lvl:', font_size=36,
53
font_name='Edit Undo Line BRK',
54
color=(255,255,255,255),
58
self.lvl.position=(450,0)
62
super( ScoreLayer, self).draw()
63
self.score.element.text = 'Score:%d' % status.score
64
self.lines.element.text = 'Lines:%d' % max(0, (status.level.lines - status.lines))
66
lvl = status.level_idx or 0
67
self.lvl.element.text = 'Lvl:%d' % lvl
70
status.next_piece.draw()
72
class MessageLayer( Layer ):
73
def show_message( self, msg, callback=None ):
75
w,h = director.get_window_size()
77
self.msg = Label( msg,
79
font_name='Edit Undo Line BRK',
82
self.msg.position=(w/2.0, h)
86
actions = Accelerate(MoveBy( (0,-h/2.0), duration=0.5)) + \
88
Accelerate(MoveBy( (0,-h/2.0), duration=0.5)) + \
92
actions += CallFunc( callback )
94
self.msg.do( actions )
98
super( HUD, self).__init__()
99
self.add( ScoreLayer() )
100
self.add( MessageLayer(), name='msg' )
102
def show_message( self, msg, callback = None ):
103
self.get('msg').show_message( msg, callback )