Ejemplo n.º 1
0
    def mainLoop(self, level_filename, new_score, percent_played):
        raw_level_name = level_filename[:len(level_filename)-10]
        high_score_file = "../data/" + raw_level_name + "-high_scores.txt"
        high_scores = open(high_score_file, 'r')
#        scores = [("MSH", "500"), ("MSH", "400"), ("MSH", "300"),
#                  ("MSH", "200"), ("MSH", "100")]
        scores = []
        new_high_score = False
        for line in high_scores:
            if line != "":
                scores.append(tuple(line.split('\t')))
        high_scores.close()
        for name, score in scores:
            if new_score > int(score):
                new_high_score = True
        
        if new_high_score:
            m = HighScoreScreen(self.screen)
            m.mainLoop()
            new_name = m.name
            new_scores = []
            high_scores = open(high_score_file, 'w')
            added = False
            for i in range(0, 4):
                if not added and new_score > int(scores[i][1]):
                    high_scores.writelines(new_name + "\t" + str(new_score) + "\n")
                    new_scores.append((new_name, str(new_score)))
                    added = True
                high_scores.writelines(scores[i][0] + "\t" + scores[i][1])
                new_scores.append(scores[i])
            if new_score < int(scores[3][1]):
                high_scores.writelines(new_name + "\t" + str(new_score))
                new_scores.append((new_name, str(new_score)))
                added = True
            high_scores.close()
            scores = new_scores
        
                
            
        screen = self.screen
        """Joystick"""
        self.joy=pygame.joystick.Joystick(0)
        self.joy.init()
        #self.numbutton = self.joy.get_numbuttons()
        
        if sys.platform == "darwin":
            self.buttonMap = {11 : HAL.GREEN, 12 : HAL.RED, 13 : HAL.BLUE, 14 : HAL.YELLOW, 8 : HAL.ORANGE, 5 : HAL.BACK, 4 : HAL.START, 1 : HAL.STRUM_DOWN, 0 : HAL.STRUM_UP}
        
            self.axisMap = {4 : HAL.WHAMMY, 1 : HAL.EFFECT, 5 : HAL.TILT, 2 : HAL.NOTHING, 3 : HAL.NOTHING}
            
            self.hatMap = {0 : {} }
            
            self.axisDefault = {4 : -1.0}
            self.hatDefault = {}
            
        elif sys.platform == "win32":
            self.buttonMap = {0 : HAL.GREEN, 1 : HAL.RED, 2 : HAL.BLUE, 3 : HAL.YELLOW, 4 : HAL.ORANGE, 6 : HAL.BACK, 7 : HAL.START}
            self.axisMap = {4 : HAL.WHAMMY, 2 : HAL.EFFECT, 3 : HAL.TILT}
            
            self.hatMap = {0 : { (0, -1) : HAL.STRUM_DOWN, (0, 1) : HAL.STRUM_UP} }
            
            self.axisDefault = {4 : -1.0}
            self.hatDefault = {}
            
        self.hal = HAL(self.buttonMap, self.axisMap, self.hatMap, self.axisDefault, self.hatDefault)
        
        '''Sounds!'''
        self.clashingSwords = load_sound("swords_1Clash.ogg")
        
        """Create the Screen"""
        #screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
        #self.mainScreenBackground, self.mainScreenBackgroundRect = load_image("SamuraiJam_MainScreen.jpg")
        #mainScreenBackground = pygame.image.load("../../data/SamuraiJam_MainScreen.jpg")
        #mainScreenBackgroundRect = mainScreenBackground.get_rect()
        #blit once first to avoid graphics conflicts with the menu
        #screen.blit(mainScreenBackground, mainScreenBackgroundRect)
        #screen.fill((255,255,255))
        #mainScreenBackground,mainScreenBackgroundRect = load_image("samuraiFlute.jpg")
        #mainScreenBackgroundRect = mainScreenBackground.get_rect()
        #blit once first to avoid graphics conflicts with the menu
        #screen.blit(mainScreenBackground, (700,0))
        
        #create a translucent overlay
        self.winSurface = pygame.Surface((screen.get_width(),screen.get_height()))  # the size of your rect
        self.winSurface.set_alpha(255)                # alpha level
        self.winSurface.fill((255,255,255))           # this fills the entire surface
        screen.blit(self.winSurface, (0,0))    # (0,0) are the top-left coordinates
        
        
        font = Font(None, 60)
        text = font.render("Your Score: " + str(new_score), 1, (0,0,0))
        screen.blit(text, (375,50))
        text = font.render("Your Progress: " + str(percent_played) + "%", 1, (0,0,0))
        screen.blit(text, (325, 100))
        font = Font(None, 100)
        text = font.render("High Scores:", 1, (0,0,0))
        screen.blit(text, (300,150))
        t = 0
        font = Font(None, 40)
        for name, score in scores:
            text = font.render(name + "     " + score.rstrip(), 1, (0,0,0))
            screen.blit(text, (425,250+40*t))
            t = t+1
        
        '''Create the menu'''
        # Create 3 diffrent menus.  One of them is only text, another one is only
        # images, and a third is -gasp- a mix of images and text buttons!  To
        # understand the input factors, see the menu file
        menu = cMenu(50, 50, 20, 5, 'vertical', 100, screen,
               [('Continue', 1, None)])
        #set the unselected color for menu items
        menu.set_unselected_color(BLACK)
        
        # Center the menu on the draw_surface (the entire screen here)
        menu.set_center(False, False)

        # Center the menu on the draw_surface (the entire screen here)
        #menu.set_alignment('center', 'center')
        menu.set_position(800,200)
        
        # Create the state variables (make them different so that the user event is
        # triggered at the start of the "while 1" loop so that the initial display
        # does not wait for user input)
        state = 0
        prev_state = 1
        
        # rect_list is the list of pygame.Rect's that will tell pygame where to
        # update the screen (there is no point in updating the entire screen if only
        # a small portion of it changed!)
        rect_list = []
        
        # Ignore mouse motion (greatly reduces resources when not needed)
        pygame.event.set_blocked(pygame.MOUSEMOTION)

        stillPaused = True
        # The main while loop
        while stillPaused:
            
            # Check if the state has changed, if it has, then post a user event to
            # the queue to force the menu to be shown at least once
            if prev_state != state:
                pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key = 0))
                prev_state = state
            
            # Get the next event
            e = pygame.event.wait()
                        
            if sys.platform == "win32":
                if e.type == pygame.JOYHATMOTION:
                    g_state = self.hal.parseAll(self.joy)
                    if (HAL.STRUM_DOWN in g_state and g_state[HAL.STRUM_DOWN] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_DOWN)
                    elif (HAL.STRUM_UP in g_state and g_state[HAL.STRUM_UP] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_UP)
                elif e.type == pygame.JOYBUTTONDOWN:
                    g_state = self.hal.parseButton(self.joy)
                    if (HAL.GREEN in g_state) and (g_state[HAL.GREEN] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_RETURN)
                        
            elif sys.platform == "darwin":
                if e.type == pygame.JOYBUTTONDOWN:
                    g_state = self.hal.parseButton(self.joy)
                    if (HAL.STRUM_DOWN in g_state and g_state[HAL.STRUM_DOWN] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_DOWN)
                    elif (HAL.STRUM_UP in g_state and g_state[HAL.STRUM_UP] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_UP)
                    elif (HAL.GREEN in g_state) and (g_state[HAL.GREEN] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_RETURN)
            
            # Update the menu, based on which "state" we are in - When using the menu
            # in a more complex program, definitely make the states global variables
            # so that you can refer to them by a name
            if e.type == pygame.KEYDOWN or e.type == EVENT_CHANGE_STATE:
                print "Current State: {0}".format(state)
                if state == 0:
                    rect_list, state = menu.update(e, state)
                elif state == 1:
                    print 'Main Menu'
                    self.clashingSwords.play()
                    stillPaused = False
                    Constants.fluteMusic.stop()
                elif state == 2:
                    print 'Replay'
                    self.clashingSwords.play()
                    Constants.fluteMusic.stop()
                    song_name = '.../data/songs/' + raw_level_name + '.txt'
                    m = MainGame(song_name, screen)
                    m.game_loop()
                    #Constants.sexyMusic.stop()
                    #m = MainGame(screen)
                    #m.game_loop()
                    #screen.fill((255,255,255))
                    #Constants.sexyMusic.stop()
                    #pygame.mixer.music.stop();
                    #Constants.fluteMusic.play()
                    stillPaused = False
                    
                #update the screen
                pygame.display.update(rect_list)
        pygame.display.flip()
Ejemplo n.º 2
0
 def mainLoop(self):
                 
     screen = self.screen
     """Joystick"""
     self.joy=pygame.joystick.Joystick(0)
     self.joy.init()
     #self.numbutton = self.joy.get_numbuttons()
     
     if sys.platform == "darwin":
         self.buttonMap = {11 : HAL.GREEN, 12 : HAL.RED, 13 : HAL.BLUE, 14 : HAL.YELLOW, 8 : HAL.ORANGE, 5 : HAL.BACK, 4 : HAL.START, 1 : HAL.STRUM_DOWN, 0 : HAL.STRUM_UP}
     
         self.axisMap = {4 : HAL.WHAMMY, 1 : HAL.EFFECT, 5 : HAL.TILT, 2 : HAL.NOTHING, 3 : HAL.NOTHING}
         
         self.hatMap = {0 : {} }
         
         self.axisDefault = {4 : -1.0}
         self.hatDefault = {}
         
     elif sys.platform == "win32":
         self.buttonMap = {0 : HAL.GREEN, 1 : HAL.RED, 2 : HAL.BLUE, 3 : HAL.YELLOW, 4 : HAL.ORANGE, 6 : HAL.BACK, 7 : HAL.START}
         self.axisMap = {4 : HAL.WHAMMY, 2 : HAL.EFFECT, 3 : HAL.TILT}
         
         self.hatMap = {0 : { (0, -1) : HAL.STRUM_DOWN, (0, 1) : HAL.STRUM_UP} }
         
         self.axisDefault = {4 : -1.0}
         self.hatDefault = {}
         
     self.hal = HAL(self.buttonMap, self.axisMap, self.hatMap, self.axisDefault, self.hatDefault)
     
     '''Sounds!'''
     self.clashingSwords = load_sound("swords_1Clash.ogg")
     
     pygame.event.set_blocked(pygame.MOUSEMOTION)
     
     """Create the Screen"""
     #screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
     #self.mainScreenBackground, self.mainScreenBackgroundRect = load_image("SamuraiJam_MainScreen.jpg")
     #mainScreenBackground = pygame.image.load("../../data/SamuraiJam_MainScreen.jpg")
     #mainScreenBackgroundRect = mainScreenBackground.get_rect()
     #blit once first to avoid graphics conflicts with the menu
     #screen.blit(mainScreenBackground, mainScreenBackgroundRect)
     #screen.fill((255,255,255))
     #mainScreenBackground,mainScreenBackgroundRect = load_image("samuraiFlute.jpg")
     #mainScreenBackgroundRect = mainScreenBackground.get_rect()
     #blit once first to avoid graphics conflicts with the menu
     #screen.blit(mainScreenBackground, (700,0))
     
     #create a translucent overlay
     self.winSurface = pygame.Surface((screen.get_width(),screen.get_height()))  # the size of your rect
     self.winSurface.set_alpha(255)                # alpha level
     self.winSurface.fill((255,255,255))           # this fills the entire surface
     screen.blit(self.winSurface, (0,0))    # (0,0) are the top-left coordinates
     
     
     font = Font(None, 60)
     text = font.render("NEW HIGH SCORE!!!", 1, (0,0,0))
     screen.blit(text, (350,50))
     text = font.render("Enter your initials:", 1, (0,0,0))
     screen.blit(text, (345, 100))
     
     font = Font(None, 40)
     for i in range(0, 3):
         letter = 'A'
         done = False
         while not done:
             text = font.render(letter, 1, (0,0,0), (255,255,255))
             screen.blit(text, (400 + 25*i, 150))
             e = pygame.event.wait()
                     
             if sys.platform == "win32":
                 if e.type == pygame.JOYHATMOTION:
                     g_state = self.hal.parseAll(self.joy)
                     if (HAL.STRUM_DOWN in g_state and g_state[HAL.STRUM_DOWN] == True):
                         e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_DOWN)
                     elif (HAL.STRUM_UP in g_state and g_state[HAL.STRUM_UP] == True):
                         e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_UP)
                 elif e.type == pygame.JOYBUTTONDOWN:
                     g_state = self.hal.parseButton(self.joy)
                     if (HAL.GREEN in g_state) and (g_state[HAL.GREEN] == True):
                         e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_RETURN)
                         
             elif sys.platform == "darwin":
                 if e.type == pygame.JOYBUTTONDOWN:
                     g_state = self.hal.parseButton(self.joy)
                     if (HAL.STRUM_DOWN in g_state and g_state[HAL.STRUM_DOWN] == True):
                         e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_DOWN)
                     elif (HAL.STRUM_UP in g_state and g_state[HAL.STRUM_UP] == True):
                         e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_UP)
                     elif (HAL.GREEN in g_state) and (g_state[HAL.GREEN] == True):
                         e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_RETURN)
             
             if e.type == pygame.KEYDOWN:
                 if e.key == pygame.K_DOWN:
                     dec = ord(letter) + 1
                     if dec > 90:
                         dec = dec - 26
                     letter = chr(dec)
                 elif e.key == pygame.K_UP:
                     dec = ord(letter) - 1
                     if dec < 65:
                         dec = dec +26
                     letter = chr(dec)
                 elif e.key == pygame.K_RETURN:
                     done = True
                     
             pygame.display.flip()
         self.name = self.name + letter       
     pygame.display.flip()
Ejemplo n.º 3
0
    def mainLoop(self):
                    
        screen = self.screen
        """Joystick"""
        self.joy=pygame.joystick.Joystick(0)
        self.joy.init()
        #self.numbutton = self.joy.get_numbuttons()
        
        if sys.platform == "darwin":
            self.buttonMap = {11 : HAL.GREEN, 12 : HAL.RED, 13 : HAL.BLUE, 14 : HAL.YELLOW, 8 : HAL.ORANGE, 5 : HAL.BACK, 4 : HAL.START, 1 : HAL.STRUM_DOWN, 0 : HAL.STRUM_UP}
        
            self.axisMap = {4 : HAL.WHAMMY, 1 : HAL.EFFECT, 5 : HAL.TILT, 2 : HAL.NOTHING, 3 : HAL.NOTHING}
            
            self.hatMap = {0 : {} }
            
            self.axisDefault = {4 : -1.0}
            self.hatDefault = {}
            
        elif sys.platform == "win32":
            self.buttonMap = {0 : HAL.GREEN, 1 : HAL.RED, 2 : HAL.BLUE, 3 : HAL.YELLOW, 4 : HAL.ORANGE, 6 : HAL.BACK, 7 : HAL.START}
            self.axisMap = {4 : HAL.WHAMMY, 2 : HAL.EFFECT, 3 : HAL.TILT}
            
            self.hatMap = {0 : { (0, -1) : HAL.STRUM_DOWN, (0, 1) : HAL.STRUM_UP} }
            
            self.axisDefault = {4 : -1.0}
            self.hatDefault = {}
            
        self.hal = HAL(self.buttonMap, self.axisMap, self.hatMap, self.axisDefault, self.hatDefault)
        
        '''Sounds!'''
        self.clashingSwords = load_sound("swords_1Clash.ogg")
        
        pygame.event.set_blocked(pygame.MOUSEMOTION)
        
        """Create the Screen"""
        #screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
        #self.mainScreenBackground, self.mainScreenBackgroundRect = load_image("SamuraiJam_MainScreen.jpg")
        #mainScreenBackground = pygame.image.load("../../data/SamuraiJam_MainScreen.jpg")
        #mainScreenBackgroundRect = mainScreenBackground.get_rect()
        #blit once first to avoid graphics conflicts with the menu
        #screen.blit(mainScreenBackground, mainScreenBackgroundRect)
        #screen.fill((255,255,255))
        #mainScreenBackground,mainScreenBackgroundRect = load_image("samuraiFlute.jpg")
        #mainScreenBackgroundRect = mainScreenBackground.get_rect()
        #blit once first to avoid graphics conflicts with the menu
        #screen.blit(mainScreenBackground, (700,0))
        
        #create a translucent overlay
        self.winSurface = pygame.Surface((screen.get_width(),screen.get_height()))  # the size of your rect
        self.winSurface.set_alpha(255)                # alpha level
        self.winSurface.fill((0,0,0))           # this fills the entire surface
        screen.blit(self.winSurface, (0,0))    # (0,0) are the top-left coordinates
        
        
        state = 0
        prev_state = 1
        
        done = False
        while not done:
            
            if prev_state != state:
                pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key = 0))
                prev_state = state

            e = pygame.event.wait()
            
            if e.type == pygame.JOYBUTTONDOWN:
                g_state = self.hal.parseButton(self.joy)
                if (HAL.GREEN in g_state and g_state[HAL.GREEN] == True):
                    e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_RIGHT)
                elif (HAL.RED in g_state and g_state[HAL.RED] == True):
                    e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_LEFT)
            
            if e.type == pygame.KEYDOWN or e.type == EVENT_CHANGE_STATE:
                if e.key == pygame.K_RIGHT:
                    state = state + 1
                elif e.key == pygame.K_LEFT:
                    state = state - 1
                        
                screen.fill((0,0,0))
                font = Font(None, 60)
                text = font.render("How to Play:", 1, (255,255,255))
                screen.blit(text, (400,50))
                font = Font(None, 40)
                text = font.render("Press GREEN to continue or RED to go back", 1, (255,255,255))
                screen.blit(text, (250, 120))
                    
                if state == 0:
                    text = font.render("This is a path that you can move on:", 1, (255,255,255))
                    screen.blit(text, (50,200))
                    image = load_image("dirtPathPanel.jpg")[0]
                    screen.blit(image, (600,200))
                    text = font.render("This is Sam:", 1, (255,255,255))
                    screen.blit(text, (50,250))
                    image = load_image("samurai_sprites/chr06164.png", -1)[0]
                    screen.blit(image, (250,250))
                    text = font.render("This is a bridge:", 1, (255,255,255))
                    screen.blit(text, (50,300))
                    image = load_image("bridges/blue_bridge.png", -1)[0]
                    screen.blit(image, (350, 270))
                    text = font.render("To cross a bridge, STRUM the guitar controller while", 1, (255,255,255))
                    screen.blit(text, (50, 350))
                    text = font.render("holding down the corresponding colored button", 1, (255,255,255))
                    screen.blit(text, (50,380))
                    text = font.render("This is a mine", 1, (255,255,255))
                    screen.blit(text, (50,430))
                    image = load_image("mine_blink/mine_1.png", -1)[0]
                    screen.blit(image, (250,430))
                    text = font.render("You want to avoid all mines.", 1, (255,255,255))
                    screen.blit(text, (50,460))
                    prev_state = 0
                elif state == 1:
                    text = font.render("ENEMIES:", 1, (255,255,255))
                    screen.blit(text, (400,170))
                    text = font.render("This is a groupie:", 1, (255,255,255))
                    screen.blit(text, (50,210))
                    image = load_image_from_folder('groupieNEW', 'groupie_1.png', -1)[0]
                    screen.blit(image, (350,185))
                    text = font.render("They hate being clean and are destroyed by your water attack", 1, (255,255,255))
                    screen.blit(text, (50,240))
                    text = font.render("To do your water attack: STRUM the guitar controller", 1, (255,255,255))
                    screen.blit(text, (50,270))
                    text = font.render("while holding the GREEN and BLUE buttons", 1, (255,255,255))
                    screen.blit(text, (50,300))
                    text = font.render("This is a bodyguard:", 1, (255,255,255))
                    screen.blit(text, (50,340))
                    image = load_image("guard/guard.png", -1)[0]
                    screen.blit(image, (450,315))
                    text = font.render("They are strong and need to be defeated by your fiery sword", 1, (255,255,255))
                    screen.blit(text, (50,370))
                    text = font.render("To do your fire sword attack: STRUM the guitar controller", 1, (255,255,255))
                    screen.blit(text, (50,400))
                    text = font.render("while holding the RED and YELLOW buttons", 1, (255,255,255))
                    screen.blit(text, (50,430))
                    text = font.render("This is a lawyer:", 1, (255,255,255))
                    screen.blit(text, (50,470))
                    image = load_image("lawyer/lawyer_ZZZ30.png", -1)[0]
                    screen.blit(image, (300,445))
                    text = font.render("They are very stiff and need to be mellowed by a face melting solo", 1, (255,255,255))
                    screen.blit(text, (50,500))
                    text = font.render("To do a face melting solo: STRUM the guitar controller", 1, (255,255,255))
                    screen.blit(text, (50,530))
                    text = font.render("while holding the GREEN and YELLOW buttons", 1, (255,255,255))
                    screen.blit(text, (50,560))
                    prev_state = 1
                elif state == 2:
                    text = font.render("KI:", 1, (255,255,255))
                    screen.blit(text, (400,200))
                    text = font.render("Ki is ancient spiritual energy that a Jamurai can harvest.", 1, (255,255,255))
                    screen.blit(text, (50,250))
                    text = font.render("Your Ki level is tracked in the status bar above next to your health.", 1, (255,255,255))
                    screen.blit(text, (50,290))
                    text = font.render("Using your special attacks costs Ki, but killing enemies replenishes it.", 1, (255,255,255))
                    screen.blit(text, (50,330))
                    text = font.render("Using the correct attack on an enemy will take one hit to defeat them", 1, (255,255,255))
                    screen.blit(text, (50,370))
                    text = font.render("and have no net loss of Ki. The wrong attack will still hurt enemies,", 1, (255,255,255))
                    screen.blit(text, (50,410))
                    text = font.render("but will take multiple hits to work and therefore cost Ki. You may also use", 1, (255,255,255))
                    screen.blit(text, (50,450))
                    text = font.render("your basic attack on enemies, although it is even weaker than the wrong attack.", 1, (255,255,255))
                    screen.blit(text, (50,490))
                    text = font.render("To do your basic slash attack: STRUM the guitar controller", 1, (255,255,255))
                    screen.blit(text, (50,530))
                    text = font.render("while holding the GREEN and RED buttons", 1, (255,255,255))
                    screen.blit(text, (50,570))
                    prev_state = 2
                elif state == 3:
                    text = font.render("POWERUPS:", 1, (255,255,255))
                    screen.blit(text, (400,200))
                    text = font.render("You may pick up powerups along your journey.", 1, (255,255,255))
                    screen.blit(text, (50,250))
                    text = font.render("This is a health pack:", 1, (255,255,255))
                    screen.blit(text, (50,300))
                    image = load_image("powerups/health_pack.png", -1)[0]
                    screen.blit(image, (450,300))
                    text = font.render("It increases your health as seen in the status bar.", 1, (255,255,255))
                    screen.blit(text, (50,330))
                    text = font.render("This is a Ki booster:", 1, (255,255,255))
                    screen.blit(text, (50,380))
                    image = load_image("powerups/ki_pickup.png", -1)[0]
                    screen.blit(image, (450,380))
                    text = font.render("It increases your Ki level as seen in the status bar.", 1, (255,255,255))
                    screen.blit(text, (50,410))
                    text = font.render("This is a shield:", 1, (255,255,255))
                    screen.blit(text, (50,460))
                    image = load_image("powerups/shield_pickup.png", -1)[0]
                    screen.blit(image, (450,460))
                    text = font.render("It protects you from enemies for a period of time.", 1, (255,255,255))
                    screen.blit(text, (50,490))
                    text = font.render("This is a special sword:", 1, (255,255,255))
                    screen.blit(text, (50,540))
                    image = load_image("powerups/sword_pickup.png", -1)[0]
                    screen.blit(image, (450,540))
                    text = font.render("It makes your basic slash more powerful for a period of time.", 1, (255,255,255))
                    screen.blit(text, (50,570))
                    prev_state = 3
                else:
                    done = True
                pygame.display.flip() 
Ejemplo n.º 4
0
    def mainLoop(self):
        screen = self.screen
        """Joystick"""
        self.joy=pygame.joystick.Joystick(0)
        self.joy.init()
        #self.numbutton = self.joy.get_numbuttons()
        
        if sys.platform == "darwin":
            self.buttonMap = {11 : HAL.GREEN, 12 : HAL.RED, 13 : HAL.BLUE, 14 : HAL.YELLOW, 8 : HAL.ORANGE, 5 : HAL.BACK, 4 : HAL.START, 1 : HAL.STRUM_DOWN, 0 : HAL.STRUM_UP}
        
            self.axisMap = {4 : HAL.WHAMMY, 1 : HAL.EFFECT, 5 : HAL.TILT, 2 : HAL.NOTHING, 3 : HAL.NOTHING}
            
            self.hatMap = {0 : {} }
            
            self.axisDefault = {4 : -1.0}
            self.hatDefault = {}
            
        elif sys.platform == "win32":
            self.buttonMap = {0 : HAL.GREEN, 1 : HAL.RED, 2 : HAL.BLUE, 3 : HAL.YELLOW, 4 : HAL.ORANGE, 6 : HAL.BACK, 7 : HAL.START}
            self.axisMap = {4 : HAL.WHAMMY, 2 : HAL.EFFECT, 3 : HAL.TILT}
            
            self.hatMap = {0 : { (0, -1) : HAL.STRUM_DOWN, (0, 1) : HAL.STRUM_UP} }
            
            self.axisDefault = {4 : -1.0}
            self.hatDefault = {}
            
        self.hal = HAL(self.buttonMap, self.axisMap, self.hatMap, self.axisDefault, self.hatDefault)
        
        '''Sounds!'''
        self.clashingSwords = load_sound("swords_1Clash.ogg")
        
        """Create the Screen"""
        #screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
        #self.mainScreenBackground, self.mainScreenBackgroundRect = load_image("SamuraiJam_MainScreen.jpg")
        #mainScreenBackground = pygame.image.load("../../data/SamuraiJam_MainScreen.jpg")
        #mainScreenBackgroundRect = mainScreenBackground.get_rect()
        #blit once first to avoid graphics conflicts with the menu
        #screen.blit(mainScreenBackground, mainScreenBackgroundRect)
        #screen.fill((255,255,255))
        #mainScreenBackground,mainScreenBackgroundRect = load_image("samuraiFlute.jpg")
        #mainScreenBackgroundRect = mainScreenBackground.get_rect()
        #blit once first to avoid graphics conflicts with the menu
        #screen.blit(mainScreenBackground, (700,0))
        
        #create a translucent overlay
        self.pauseSurface = pygame.Surface((screen.get_width(),screen.get_height()))  # the size of your rect
        self.pauseSurface.set_alpha(128)                # alpha level
        self.pauseSurface.fill((0,0,0))           # this fills the entire surface
        screen.blit(self.pauseSurface, (0,0))    # (0,0) are the top-left coordinates
        
        
        
        
        '''Create the menu'''
        # Create 3 diffrent menus.  One of them is only text, another one is only
        # images, and a third is -gasp- a mix of images and text buttons!  To
        # understand the input factors, see the menu file
        menu = cMenu(50, 50, 20, 5, 'vertical', 100, screen,
               [('Resume', 1, None)])
        #set the unselected color for menu items
        menu.set_unselected_color(BLACK)
        
        # Center the menu on the draw_surface (the entire screen here)
        menu.set_center(False, False)

        # Center the menu on the draw_surface (the entire screen here)
        #menu.set_alignment('center', 'center')
        menu.set_position(50,50)
        
        # Create the state variables (make them different so that the user event is
        # triggered at the start of the "while 1" loop so that the initial display
        # does not wait for user input)
        state = 0
        prev_state = 1
        
        # rect_list is the list of pygame.Rect's that will tell pygame where to
        # update the screen (there is no point in updating the entire screen if only
        # a small portion of it changed!)
        rect_list = []
        
        # Ignore mouse motion (greatly reduces resources when not needed)
        pygame.event.set_blocked(pygame.MOUSEMOTION)

        stillPaused = True
        self.globalPauseSignal = True
        # The main while loop
        while stillPaused:
            
            # Check if the state has changed, if it has, then post a user event to
            # the queue to force the menu to be shown at least once
            if prev_state != state:
                pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key = 0))
                prev_state = state
            
            # Get the next event
            e = pygame.event.wait()
                        
            if sys.platform == "win32":
                if e.type == pygame.JOYHATMOTION:
                    g_state = self.hal.parseAll(self.joy)
                    if (HAL.STRUM_DOWN in g_state and g_state[HAL.STRUM_DOWN] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_DOWN)
                    elif (HAL.STRUM_UP in g_state and g_state[HAL.STRUM_UP] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_UP)
                elif e.type == pygame.JOYBUTTONDOWN:
                    g_state = self.hal.parseButton(self.joy)
                    if (HAL.GREEN in g_state) and (g_state[HAL.GREEN] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_RETURN)
                        
            elif sys.platform == "darwin":
                if e.type == pygame.JOYBUTTONDOWN:
                    g_state = self.hal.parseButton(self.joy)
                    if (HAL.STRUM_DOWN in g_state and g_state[HAL.STRUM_DOWN] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_DOWN)
                    elif (HAL.STRUM_UP in g_state and g_state[HAL.STRUM_UP] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_UP)
                    elif (HAL.GREEN in g_state) and (g_state[HAL.GREEN] == True):
                        e = pygame.event.Event(pygame.KEYDOWN, key = pygame.K_RETURN)
            
            # Update the menu, based on which "state" we are in - When using the menu
            # in a more complex program, definitely make the states global variables
            # so that you can refer to them by a name
            if e.type == pygame.KEYDOWN or e.type == EVENT_CHANGE_STATE:
                print "Current State: {0}".format(state)
                if state == 0:
                    rect_list, state = menu.update(e, state)
                elif state == 1:
                    print 'Resume'
                    self.clashingSwords.play()
                    stillPaused = False
                elif state == 2:
                    print 'Quit'
                    self.clashingSwords.play()
                    #Constants.sexyMusic.stop()
                    #m = MainGame(screen)
                    #m.game_loop()
                    #screen.fill((255,255,255))
                    #Constants.sexyMusic.stop()
                    #pygame.mixer.music.stop();
                    #Constants.fluteMusic.play()
                    stillPaused = False
                    self.globalPauseSignal = False
                    
                #update the screen
                pygame.display.update(rect_list)