~facundo/enjuewemela/trunk

« back to all changes in this revision

Viewing changes to enjuewemela/cocos/samples/tetrico/HUD.py

  • Committer: facundo at com
  • Date: 2010-11-20 01:42:31 UTC
  • mfrom: (62.1.3 lint-issues)
  • Revision ID: facundo@taniquetil.com.ar-20101120014231-b2tkyc3mwr84ggcc
Project reorder and lint issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This code is so you can run the samples without installing the package
2
 
import sys
3
 
import os
4
 
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..'))
5
 
 
6
 
from cocos.layer import *
7
 
from cocos.text import *
8
 
from cocos.actions import *
9
 
 
10
 
import pyglet
11
 
from pyglet.gl import *
12
 
 
13
 
from status import status
14
 
 
15
 
class BackgroundLayer( Layer ):
16
 
    def __init__(self):
17
 
        super( BackgroundLayer, self ).__init__()
18
 
        self.img = pyglet.resource.image('background.png')
19
 
 
20
 
    def draw( self ):
21
 
        glPushMatrix()
22
 
        self.transform()
23
 
        self.img.blit(0,0)
24
 
        glPopMatrix()
25
 
 
26
 
class ScoreLayer( Layer ): 
27
 
    def __init__(self):
28
 
        w,h = director.get_window_size()
29
 
        super( ScoreLayer, self).__init__()
30
 
 
31
 
        # transparent layer
32
 
        self.add( ColorLayer(32,32,32,32, width=w, height=48),z=-1 )
33
 
 
34
 
        self.position = (0,h-48)
35
 
 
36
 
        self.score=  Label('Score:', font_size=36,
37
 
                font_name='Edit Undo Line BRK',
38
 
                color=(255,255,255,255),
39
 
                anchor_x='left',
40
 
                anchor_y='bottom')
41
 
        self.score.position=(0,0)
42
 
        self.add( self.score)
43
 
 
44
 
        self.lines=  Label('Lines:', font_size=36,
45
 
                font_name='Edit Undo Line BRK',
46
 
                color=(255,255,255,255),
47
 
                anchor_x='left',
48
 
                anchor_y='bottom')
49
 
        self.lines.position=(235,0)
50
 
        self.add( self.lines)
51
 
 
52
 
        self.lvl=  Label('Lvl:', font_size=36,
53
 
                font_name='Edit Undo Line BRK',
54
 
                color=(255,255,255,255),
55
 
                anchor_x='left',
56
 
                anchor_y='bottom')
57
 
 
58
 
        self.lvl.position=(450,0)
59
 
        self.add( self.lvl)
60
 
 
61
 
    def draw(self):
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))
65
 
 
66
 
        lvl = status.level_idx or 0
67
 
        self.lvl.element.text = 'Lvl:%d' % lvl
68
 
        
69
 
        if status.next_piece:
70
 
            status.next_piece.draw()
71
 
 
72
 
class MessageLayer( Layer ):
73
 
    def show_message( self, msg, callback=None ):
74
 
 
75
 
        w,h = director.get_window_size()
76
 
 
77
 
        self.msg = Label( msg,
78
 
            font_size=52,
79
 
            font_name='Edit Undo Line BRK',
80
 
            anchor_y='center',
81
 
            anchor_x='center' )
82
 
        self.msg.position=(w/2.0, h)
83
 
 
84
 
        self.add( self.msg )
85
 
 
86
 
        actions = Accelerate(MoveBy( (0,-h/2.0), duration=0.5)) + \
87
 
                    Delay(1) +  \
88
 
                    Accelerate(MoveBy( (0,-h/2.0), duration=0.5)) + \
89
 
                    Hide()
90
 
 
91
 
        if callback:
92
 
            actions += CallFunc( callback )
93
 
 
94
 
        self.msg.do( actions )
95
 
 
96
 
class HUD( Layer ):
97
 
    def __init__( self ):
98
 
        super( HUD, self).__init__()
99
 
        self.add( ScoreLayer() )
100
 
        self.add( MessageLayer(), name='msg' )
101
 
 
102
 
    def show_message( self, msg, callback = None ):
103
 
        self.get('msg').show_message( msg, callback )