~facundo/enjuewemela/trunk

« back to all changes in this revision

Viewing changes to enjuewemela/cocos/samples/tetrico/gameover.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
 
# pyglet realted
7
 
from pyglet.window import key
8
 
 
9
 
# cocos2d related
10
 
from cocos.layer import Layer, ColorLayer
11
 
from cocos.director import director
12
 
from cocos.text import Label
13
 
from cocos.actions import *
14
 
 
15
 
# tetrico related
16
 
import soundex
17
 
import hiscore
18
 
import status
19
 
 
20
 
 
21
 
class GameOver( ColorLayer ):
22
 
    is_event_handler = True #: enable pyglet's events
23
 
 
24
 
    def __init__( self, win = False):
25
 
        super(GameOver,self).__init__( 32,32,32,64)
26
 
 
27
 
        w,h = director.get_window_size()
28
 
 
29
 
        if win:
30
 
            soundex.play('oh_yeah.mp3')
31
 
            msg = 'YOU WIN'
32
 
        else:
33
 
            soundex.play('no.mp3')
34
 
            msg = 'GAME OVER'
35
 
 
36
 
        label = Label(msg,
37
 
                    font_name='Edit Undo Line BRK',
38
 
                    font_size=54,
39
 
                    anchor_y='center',
40
 
                    anchor_x='center' )
41
 
        label.position =  ( w/2.0, h/2.0 )
42
 
 
43
 
        self.add( label )
44
 
 
45
 
        angle = 5
46
 
        duration = 0.05
47
 
        accel = 2
48
 
        rot = Accelerate(Rotate( angle, duration//2 ), accel)
49
 
        rot2 = Accelerate(Rotate( -angle*2, duration), accel)
50
 
        effect = rot + (rot2 + Reverse(rot2)) * 4 + Reverse(rot)
51
 
        
52
 
        label.do( Repeat( Delay(5) + effect ) )
53
 
 
54
 
        if hiscore.hiscore.is_in( status.status.score ):
55
 
            self.hi_score = True
56
 
 
57
 
            label = Label('Enter your name:',
58
 
                        font_name='Edit Undo Line BRK',
59
 
                        font_size=36,
60
 
                        anchor_y='center',
61
 
                        anchor_x='center',
62
 
                        color=(32,32,32,255),
63
 
                        )
64
 
            label.position =  ( w/2.0, h/2.0 )
65
 
            label.position = (w//2, 300)
66
 
            self.add( label )
67
 
 
68
 
            self.name= Label('',
69
 
                        font_name='Edit Undo Line BRK',
70
 
                        font_size=36,
71
 
                        anchor_y='center',
72
 
                        anchor_x='center',
73
 
                        color=(32,32,32,255),
74
 
                        )
75
 
            self.name.position=(w//2,250)
76
 
            self.add(self.name)
77
 
        else:
78
 
            self.hi_score = False
79
 
 
80
 
    def on_key_press( self, k, m ):
81
 
        if not self.hi_score and (k == key.ENTER or k == key.ESCAPE):
82
 
            director.pop()
83
 
            return True
84
 
 
85
 
        if self.hi_score:
86
 
            if k == key.BACKSPACE:
87
 
                self.name.element.text = self.name.element.text[0:-1]
88
 
                return True
89
 
            elif k == key.ENTER:
90
 
                hiscore.hiscore.add( status.status.score,self.name.element.text,status.status.level_idx )
91
 
                director.pop()
92
 
                return True
93
 
        return False
94
 
 
95
 
    def on_text( self, t ):
96
 
        if not self.hi_score:
97
 
            return False
98
 
 
99
 
        if t=='\r':
100
 
            return True
101
 
 
102
 
        self.name.element.text += t