Exemplo n.º 1
0
def main():


    # in a compiled exe this can be called.
    if "analyse_play.py" in sys.argv:
        import analyse_play
        analyse_play.main()
        return


    data.where_to = ""


    #print "Hello from your game's main()"
    #print data.load('sample.txt').read()
    
    #pygame.mixer.pre_init(44100,-16,2, 1024* 4)
    #pygame.mixer.pre_init(44100,-16,2, 1024* 4) 

    pygame.init()
    pygame.fastevent.init()

    pygame.threads.init(4)



    analyse_thread.init()



    # start playing intro track, before the screen comes up.
    if 1:
        if 1:
            intro_track = os.path.join("data", "intro.ogg")
            intro_sound_big = pygame.mixer.Sound(open(intro_track, "rb"))
            intro_sound_big.play(-1)
        else:
            try:
                intro_track = os.path.join("data", "intro.ogg")
                pygame.mixer.music.load(intro_track)
                pygame.mixer.music.play(-1)
            except:
                print "failed playing music track: '%s'" % intro_track


    else:
        

        print "1 asdf"

        
        intro_track = os.path.join("data", "intro.ogg")
        print "2 asdf"

        intro_sound = pygame.mixer.Sound(open(intro_track, "rb"))
        
        print "3 asdf"
        
        intro_array = _array_samples(intro_sound, 1)[:705600/2]

        print "4 asdf"
        
        # assert len(intro_array) == 705600

        for i in range(1):  # 4 x longer
            intro_array = numpy.append(intro_array, intro_array, 0)

        print "5 asdf"

        intro_sound_big = pygame.sndarray.make_sound(intro_array)

        print "6 asdf"

        
        pygame.time.set_timer(constants.INTRO_FADEOUT, 31000)
        intro_sound_big.play()

        print "7 asdf"
        

    screen = pygame.display.set_mode(constants.SCREEN_SIZE)
    

    top = Top(name = "Eye stabs.  Do you?")
    top.set_main()

    # Add the intro as a child Game to the top Game.
    intro = Intro(name ="eye stab intro")
    
    intro.loop_ogg = intro_sound_big


    top.video_intro = VideoPlayer()
    intro.games.append(top.video_intro)

    top.gig_select = GigSelect(screen.copy())
    top.games.append(top.gig_select)
    top.gig_select.stop()
    #intro = top.gig_select


    # store the player object.
    #player.player = player.Player()


    top.eyefix = EyeFixResult()
    top.games.append(top.eyefix)
    top.eyefix.stop()
    #intro = top.eyefix

    top.doctors_surgery = DoctorsSurgery(screen.copy())
    top.games.append(top.doctors_surgery)
    top.doctors_surgery.stop()



    top.games.append(intro)
    top.intro = intro

    





    note_guess = NoteGuess(name="Eye stabs.    Note Guess")

    # stop the note_guess part, because we are not ready yet.
    note_guess.stop()
    top.games.append(note_guess)
    top.note_guess = note_guess
    


    import urdpyg.sounds
    data.sounds = urdpyg.sounds.SoundManager()
    data.sounds.Load(urdpyg.sounds.SOUND_LIST, os.path.join("data", "sounds"))






    clock = pygame.time.Clock()
    clock.tick()
    
    while top.going:
        elapsed_time = clock.get_time()
        if elapsed_time:
            elapsed_time = elapsed_time / 1000.


        # speed up time...
        #elapsed_time *= 4

        events = pygame.fastevent.get()

        if [e for e in events if e.type == constants.INTRO_FADEOUT]:
            intro_sound_big.fadeout(1000)
            # intro_sound_big.stop()

        # we pass in the events so all of them can get the events.
        top.handle_events(events)

        # each part that uses time, for animation or otherwise
        #   gets the same amount of elapsed time.  This also reduces the
        #   number of system calls (gettimeofday) to one per frame.
        top.update(elapsed_time)
        
        data.sounds.Update(elapsed_time)



        # the draw method retunrns a list of rects, 
        #   for where the screen needs to be updated.
        rects = top.draw(screen)

        # remove empty rects.
        rects = filter(lambda x: x != [], rects)
        #rects = filter(lambda x: type(x) not in map(type, [pygame.Rect, [], tuple([1,2])]) , rects)
        rects = filter(lambda x: type(x) not in map(type, [1]) , rects)

        # if not empty, then update the display.
        if rects != []:
            #print rects
            pygame.display.update(rects)
        #pygame.display.update(rects)
        
        # we ask the clock to try and stay at a FPS rate( eg 30fps).
        #  It won't get exactly this, but it tries to get close.
        clock.tick(constants.FPS)
        #print clock.get_fps()


    # we try and clean up explicitly, and more nicely... 
    #    rather than hoping python will clean up correctly for us.
    pygame.quit()

    
    pygame.threads.quit()

    analyse_thread.quit()
Exemplo n.º 2
0
"""
Game main module.
"""


import analyse_thread
import sys

if "analyse_play.py" in sys.argv:
    import analyse_play
    analyse_play.main()
    sys.exit(0)


import os,sys
import data
import pygame
from pygame.locals import *


import numpy
pygame.sndarray.use_arraytype("numpy")



import constants

# Game is an interface for different sections of the game.
#    Similar to a Movie in flash.
# Each section of the game will have a separate object controlling it.
#    For sections like the 'intro' and the 'end sequence' will have