Back to index

freevial  1.2
endscreen.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 
00003 #
00004 # Freevial
00005 # End Screen
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 #
00012 # This program is free software: you can redistribute it and/or modify
00013 # it under the terms of the GNU General Public License as published by
00014 # the Free Software Foundation, either version 3 of the License, or
00015 # (at your option) any later version.
00016 #
00017 # This program is distributed in the hope that it will be useful,
00018 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 # GNU General Public License for more details.
00021 #
00022 # You should have received a copy of the GNU General Public License
00023 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
00024 #
00025 
00026 import sys
00027 import random
00028 import pygame
00029 import time
00030 import math
00031 
00032 from common.globals import Global
00033 from common.freevialglob import *
00034 from common.events import EventHandle
00035 
00036 
00037 class Nau:
00038               x = 1024.0 / 2.0
00039               y = 768.0 / 2.0
00040               dir = 45.0
00041               vel = 1.0
00042               img = 0
00043               spin = 0
00044 
00045               def __init__( self, angle = None ):
00046 
00047                      self.dir = angle if angle else random.randint( 0, 359 )
00048                      self.vel = random.randint( 7, 15 )
00049                      self.img = random.randint( 0, 71 )
00050                      self.spin = random.randint( 1, 3) * -1 if random.randint(0,1) else 1 
00051 
00052                      self.x += math.cos( self.dir ) * 100
00053                      self.y += math.sin( self.dir ) * 100
00054 
00055               def esFora( self ):
00056                      marge = 100
00057                      return self.x < -marge or self.x > 1024 + marge or self.y < -marge or self.y > 768 + marge
00058 
00059 
00060 class Cua:
00061 
00062        def __init__( self, punt ):
00063               self.pos = [punt[0], punt[1]]
00064               self.time = time.time()
00065               self.cau = 0
00066 
00067 
00068 def ensegments( llista_freevial, segons ):
00069        
00070        for segment in llista_freevial:
00071               if segons >= segment[0] and segons <= segment[1]:
00072                      return True
00073 
00074        return False
00075 
00076 
00077 class Visca:
00078 
00079        def __init__( self, joc ):
00080 
00081               Global.game = joc
00082        
00083               self.fons = loadImage('score_fons.png')
00084               self.fons_2 = pygame.Surface( ( 1024, 768), pygame.SRCALPHA, 32 )
00085 
00086               self.nau_sfc = []
00087               for num in range( 0, 72 ): 
00088                      self.nau_sfc.append( loadImage('ovnis/freevial_tot' + str( num ).zfill(2) + '.png') )
00089 
00090               self.sfc_llum = loadImage( 'llum.png' )
00091 
00092        def juguem( self, game, nomguanya ):
00093               
00094               Global.game = game
00095               self.frate = frameRate( Global.fps_limit )
00096               inici = time.time()
00097 
00098               self.naus = []
00099 
00100               loadSound( 'wonfv.ogg', volume = 0.8, music = 1).play( 1 )
00101               
00102               mou_fons = ypos = xpos = 0
00103 
00104               sfc_guanyadors = render_text( nomguanya, (255,255,255), 300, 1 )      
00105               text_pos = 1024 + 50
00106 
00107               sfc_freevial = render_text( "freevial", (255,0,0), 200, 0 )    
00108               sfc_freevial.set_alpha( 64 )
00109 
00110               surten = 0
00111 
00112               cues = []
00113               
00114               llums = 0
00115        
00116               while 1:
00117 
00118                      segons = time.time() - inici
00119 
00120                      for cua in cues:
00121                             if time.time() - cua.time > .4 and cua.cau == 0: 
00122                                    cues.remove( cua )
00123 
00124                             if cua.cau:
00125                                    cua.pos[1] += cua.cau
00126                                    if cua.pos[1] > 768:
00127                                           cues.remove( cua )
00128 
00129 
00130                      fes_llums = False
00131                      if (llums == 0 and segons > 45) or (llums == 1 and segons > 55) or (llums == 2 and segons > 64) or (llums == 3 and segons > 65) or (llums == 4 and segons > 66):
00132                             llums += 1
00133                             fes_llums = True
00134  
00135                      if fes_llums:
00136                             pos = 0
00137                             while pos < 1024:
00138                                    pos += random.randint(1, 10)
00139                                    cua = Cua( (pos, random.randint(0,5)) )
00140                                    cua.cau = random.randint( 5, 25 ) 
00141                                    cues.append ( cua ) 
00142 
00143                      if segons < 5.5 and int(segons) > surten:
00144                             surten = int( segons)
00145                             for compta in range( 0, 360, 10):
00146                                    nova_nau = Nau( compta )
00147                                    nova_nau.vel = surten * 2
00148                                    self.naus.append( nova_nau )
00149 
00150                      if segons > 5.5:
00151                             if segons >= 35 and segons <= 48:
00152                                    nova_nau = Nau( segons *5 )
00153                                    nova_nau.velociat = segons - 30
00154                                    self.naus.append( nova_nau )
00155                             elif not random.randint(0, 1):
00156                                           nova_nau = Nau()
00157                                           self.naus.append( nova_nau )
00158                      
00159                      for compta in range( len(self.naus) - 1, -1, -1):
00160                             nau = self.naus[compta]
00161                             if nau.esFora() :
00162                                    self.naus.remove( nau )
00163                             else:
00164                                    nau.img += nau.spin
00165                                    nau.img %= 72
00166 
00167                                    dist = math.sqrt( abs(nau.x - 1024/2) * abs(nau.x - 1024/2) + abs(nau.y - 768/2) * abs(nau.y - 768/2))
00168                                    dist /= 150
00169               
00170                                    if( segons < 48 ):                               
00171                                           nau.x += math.cos( nau.dir ) * nau.vel
00172                                           nau.y += math.sin( nau.dir ) * nau.vel
00173                                    elif (segons < 58):
00174                                           nau.x += math.cos( nau.dir + dist) * nau.vel
00175                                           nau.y += math.sin( nau.dir + dist) * nau.vel
00176                                    else :
00177                                           nau.x += math.cos( nau.dir - dist) * nau.vel
00178                                           nau.y += math.sin( nau.dir - dist) * nau.vel
00179 
00180                      for event in pygame.event.get():
00181                             
00182                             eventhandle = EventHandle(event)
00183                             if eventhandle.handled: continue
00184                             
00185                             if eventhandle.keyUp('q', 'ESCAPE') and not Global.LOCKED_MODE:
00186                                    if not Global.MUSIC_MUTE:
00187                                           pygame.mixer.music.fadeout( 1500 )
00188                                    return
00189                      
00190                      if segons >= 68: return
00191 
00192                      ypos += 1
00193                      ypos %= Global.screen_y
00194                      xpos += 1
00195                      xpos %= Global.screen_x
00196 
00197                      mou_fons += 10
00198 
00199                      if segons > 5.5:
00200 
00201                             Global.game.screen.blit( self.fons, (0,0))
00202 
00203                             for num in range(0, 768):
00204                                    Global.game.screen.blit( self.fons, (math.cos((float(mou_fons +num)) / 100.0) * 20, num), (0, (ypos + num) % 768, 1024, 1) )
00205        
00206                             llista_freevial = [ [8.7, 12], [12.7, 17], [20, 23.5], [27.5, 31], [33, 35.5], [49.5, 52.5], [55.5, 57.5], [60.9, 63.5] ]
00207 
00208                             if ensegments( llista_freevial, segons ):
00209                                    for compta in range( 0, 5):
00210                                           Global.game.screen.blit( sfc_freevial, (random.randint( -sfc_freevial.get_width(), 1024), random.randint(-sfc_freevial.get_height(), 768 )) )      
00211 
00212                                    if segons >= 20 and segons <=34:
00213                                           for nau in self.naus:
00214                                                  cues.append ( Cua( (nau.x + 32 - 8, nau.y + 32 - 4) ) )
00215 
00216                      else:
00217                             Global.game.screen.fill( (0,0,0) )
00218 
00219                      for cua in cues:
00220                             dist = int((time.time() - cua.time) * 40) if cua.cau == 0 else 0
00221                             Global.game.screen.blit( self.sfc_llum, ( cua.pos[0] + random.randint(-dist,dist), cua.pos[1] + random.randint(-dist,dist)) )
00222 
00223                      for nau in self.naus:
00224                             Global.game.screen.blit( self.nau_sfc[nau.img], (nau.x, nau.y ) )
00225                      
00226                      if segons > 5.5:
00227                             text_pos -= 20
00228                             if text_pos < -(sfc_guanyadors.get_width() + 50):
00229                                    text_pos = 1024 + 50
00230 
00231                             Global.game.screen.blit( sfc_guanyadors, (text_pos, 150 + math.cos((float(mou_fons +num)) / 100.0) * 200) )
00232                      
00233                      self.frate.next( Global.game.screen )
00234 
00235                      pygame.display.flip()