Back to index

freevial  1.2
roda.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002  
00003 #
00004 # Freevial
00005 # Category selection
00006 #
00007 # Copyright (C) 2007, 2008 The Freevial Team
00008 #
00009 # By Carles Oriol i Margarit <carles@kumbaworld.com>
00010 # By Siegfried-Angel Gevatter Pujals <siggi.gevatter@gmail.com>
00011 # By Nil Oriol <nil@kumbaworld.com>
00012 #
00013 # This program is free software: you can redistribute it and/or modify
00014 # it under the terms of the GNU General Public License as published by
00015 # the Free Software Foundation, either version 3 of the License, or
00016 # (at your option) any later version.
00017 #
00018 # This program is distributed in the hope that it will be useful,
00019 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 # GNU General Public License for more details.
00022 #
00023 # You should have received a copy of the GNU General Public License
00024 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025 #
00026 
00027 import sys
00028 import time
00029 import pygame
00030 
00031 from common.freevialglob import *
00032 from common.events import EventHandle
00033 from common.events import waitForMouseRelease
00034 from questions import get_databases
00035 
00036 
00037 ##################################################
00038 #
00039 # Empaquetat en una classe del selector
00040 #
00041 
00042 class Roda:
00043        
00044        def __init__( self, game ):
00045               
00046               self.game = game
00047               
00048               game.skin.set_domain( 'wheel' )
00049               
00050               self.fons = game.skin.configGet( 'wheel_background' )
00051               self.front = game.skin.configGet( 'wheel_front' )
00052 
00053               self.categories = []
00054               self.categoriesagafades = []
00055               self.maxim_equips = game.skin.configGetInt( 'max_teams', 'game' )
00056               
00057               self.roda_so_dot = game.skin.configGet( 'sound_wheel_dot')
00058               self.roda_so_dot_vol = game.skin.configGet( 'sound_wheel_dot_vol')
00059               self.roda_so_evil = game.skin.configGet( 'sound_wheel_evil')
00060               self.roda_so_evil_vol = game.skin.configGet( 'sound_wheel_evil_vol')
00061               self.roda_so_sub = game.skin.configGet( 'sound_wheel_sub')
00062               self.roda_so_sub_vol = game.skin.configGet( 'sound_wheel_sub_vol')
00063               self.tipografia = game.skin.configGet( 'wheel_tipografia')
00064               
00065               self.score_figureta_visible = game.skin.configGetBool( 'figureta_visible') 
00066               
00067               if self.score_figureta_visible:
00068                      self.figureta = game.skin.LoadImageRange( 'figureta_mask', 64, 2)
00069                      
00070               self.fons = game.skin.LoadImage( 'wheel_background' )
00071               self.front = game.skin.LoadImage( 'wheel_front' )
00072               self.paper = game.skin.LoadImage( 'wheel_paper')
00073               self.so_dot = game.skin.LoadSound( 'sound_wheel_dot', 'sound_wheel_dot_vol')
00074               self.so_evil = game.skin.LoadSound( 'sound_wheel_evil', 'sound_wheel_evil_vol')
00075               self.so_sub = game.skin.LoadSound( 'sound_wheel_sub', 'sound_wheel_sub_vol')
00076               self.so_cat = range(0, 6)
00077 
00078               self.so_de_pas = game.skin.configGetInt( 'so_de_pas' )
00079 
00080               self.tipografia_mida = game.skin.configGetInt( 'wheel_tipografia_mida')
00081               self.paper_text_width = game.skin.configGetInt( 'paper_text_width' )
00082               self.paper_text_offsetX = game.skin.configGetInt( 'paper_text_offsetX' )
00083               self.paper_offsetX = game.skin.configGetInt( 'paper_offsetX' )
00084 
00085               for num in range(0, 6):
00086                      self.so_cat[num] = loadSound(get_databases(num).sound, volume = 1.0)
00087               self.canviacat()                   
00088               self.help_overlay = createHelpScreen( 'roda' )          
00089               
00090               self.help_on_screen = helpOnScreen( HOS_RODA_ATURA  )
00091               self.help_on_screen.sec_timeout = 10
00092        
00093        def canviacat( self ):
00094               
00095               self.categoriesagafades = []
00096               for num in range (0, 6):
00097                      self.categoriesagafades += (get_databases(num).name)
00098                      
00099               if self.categoriesagafades != self.categories:
00100                      self.categories = self.categoriesagafades
00101 
00102                      self.paper = self.game.skin.LoadImage( 'wheel_paper' )
00103                      for num in range(0, 6):
00104                             sfc = self.game.skin.render_text( get_databases(num).name, (0,0,0), self.tipografia_mida, 1, self.tipografia, self.paper_text_width );
00105                             self.paper.blit( sfc, (self.paper_text_offsetX+2, 2+(num * 200) + 100 - sfc.get_height() / 2 ))
00106                             sfc = self.game.skin.render_text( get_databases(num).name, colorsCategories()[num], self.tipografia_mida, 1, self.tipografia, self.paper_text_width );
00107                             self.paper.blit( sfc, (self.paper_text_offsetX, (num * 200) + 100 - sfc.get_height() / 2 ))
00108        
00109        def juguem( self ):
00110               
00111               self.game.skin.set_domain( 'wheel' )
00112 
00113               self.canviacat()
00114 
00115               self.frate = frameRate( Global.fps_limit )
00116                             
00117               self.so_evil.stop()
00118               self.so_dot.play(100)
00119               
00120               velocitat = self.game.skin.configGetInt( 'wheel_speed' )
00121               deceleracio = 0
00122 
00123               waitForMouseRelease( )
00124                      
00125               pos = pos_fons = atura = frenant = time_fi = mostra_ajuda = mostra_credits = 0
00126               rodant = 1
00127               resultat = -1
00128               
00129               self.game.screen.blit( self.fons, (0,0) )
00130 
00131               self.nom_equip_sfc = self.game.skin.render_text( self.game.teams[self.game.current_team].nom, self.game.skin.configGetRGB( "team_name_color" ), 30, 1 )
00132               self.nom_equip_sfc = pygame.transform.rotate ( self.nom_equip_sfc, 90 )
00133 
00134               while 1:
00135 
00136                      for event in pygame.event.get():
00137 
00138                             eventhandle = EventHandle(event)
00139                             if eventhandle.handled: continue
00140                             
00141                             #self.help_on_screen.activitat(event)
00142                             
00143                             if eventhandle.keyUp('ESCAPE', 'q') and not Global.LOCKED_MODE:
00144                                    if not mostra_ajuda and not mostra_credits:
00145                                           if not (Global.MUSIC_MUTE or Global.SOUND_MUTE):
00146                                                  pygame.mixer.fadeout(500)
00147                                           return -1
00148                                    else:
00149                                           mostra_ajuda = mostra_credits = 0
00150                             
00151                             if eventhandle.keyUp('F1', 'h'):
00152                                    mostra_ajuda ^= 1    
00153                                    mostra_credits = 0                 
00154 
00155                             if eventhandle.keyUp('F2'):
00156                                    mostra_credits ^= 1
00157                                    mostra_ajuda = 0
00158                             
00159                             if  eventhandle.isRelease('primary') or eventhandle.keyUp('RETURN', 'SPACE', 'KP_ENTER') and rodant == 1:
00160                                    if resultat == -1:   
00161                                           atura = 1
00162                                    else:
00163                                           return resultat
00164                      
00165                      if atura == 1:
00166                             atura = 0
00167                             pas = 3
00168                             deceleracio = self.game.skin.configGetInt( 'wheel_deccel' )
00169                             time_fi = time.time()
00170                             
00171                             if not frenant:
00172                                    frenant = 1
00173                                    self.so_sub.play()
00174 
00175                      if time_fi != 0 and time.time() - time_fi > 2.5:
00176                             return resultat
00177 
00178                      # decelerem
00179                      velocitat -= deceleracio
00180                      if velocitat < 0: velocitat = 0
00181                      
00182                      # Si ja hem acabat de rodar afinem la selecció
00183                      # a l'element més proper
00184                      rpos = pos + 100
00185                      if velocitat == 0 and rodant != 0:
00186                             offset = int(rpos) % 200
00187                             if offset != 0: 
00188                                    if offset > 100:
00189                                           pos += deceleracio if ( offset < (200 - deceleracio) ) else 1
00190                                    
00191                                    elif offset <= 100:
00192                                           pos -= deceleracio if ( offset > deceleracio ) else 1
00193                                    
00194                                           if pos <= -1200: pos += 1200
00195                             
00196                             else:
00197                                    resultat = int( ( ( - ( pos - 1550 ) / 200 ) ) % 6 )
00198                                    self.so_dot.stop()
00199                                    self.so_cat[ resultat].play()
00200                                    if self.so_de_pas == 1:
00201                                           self.so_evil.play()
00202                                    if self.so_de_pas == 2:
00203                                           if not  self.game.teams[self.game.current_team].teCategoria( resultat ) :
00204                                                  self.so_evil.play()
00205                                    rodant = 0
00206                             
00207                      if rodant == 1:
00208                             pos_fons += velocitat * 2
00209                             if pos_fons >= 768:  pos_fons -= 768
00210                             
00211                             pos -= velocitat
00212                             if pos <= -1200: pos += 1200
00213                             
00214 
00215                      #pintem el paper freevial
00216                      self.game.screen.blit( self.fons, ( 0, pos_fons ) )
00217                      self.game.screen.blit( self.fons, ( 0, - 768 + pos_fons ) )
00218                      
00219                      #pintem el paper d'impressora
00220                      self.game.screen.blit( self.paper, ( self.paper_offsetX, pos ) )
00221                      self.game.screen.blit( self.paper, ( self.paper_offsetX, pos + 1200 ) )
00222                      
00223                      #pintem els marges vermells i degradats
00224                      self.game.screen.blit( self.front, (0,0) )       
00225                      
00226                      self.game.screen.blit( self.nom_equip_sfc, (20, 748 - self.nom_equip_sfc.get_height()))
00227                      
00228                      if( self.score_figureta_visible ):
00229                             self.game.screen.blit( self.figureta[self.game.teams[self.game.current_team].figureta], (70, 630) )
00230                                           
00231                      if mostra_ajuda: self.game.screen.blit( self.help_overlay, (0,0))
00232                      if mostra_credits: self.game.screen.blit( self.game.sfc_credits, (0,0))
00233 
00234                      self.help_on_screen.draw( self.game.screen, (350, 740) )
00235                      
00236                      self.frate.next( self.game.screen )
00237                      
00238                      # Exchange self.game.screen buffers
00239 
00240                      pygame.display.flip()