def switch(storage, obj, m, index):
    # (Extra "index" parameter depicts the # of the switch that was triggered
    # from 1 (far left) to 5 (far right))
    storage._go()
    if not storage._getData('lefthallway_puzzle_solved'):
        if storage._playerInDistance(m.getPlayer().position, obj.rect):
            ad = GlobalServices.getAudioDevice()
            # Initialize the persistent representation of this puzzle if it doesn't exist yet
            states = storage._getData('lefthallway_switches')
            if states is None:
                # -1: down, 0: middle, 1: up
                states = [0, 0, 0, 0, 0]
                
            # Change the state of the switch that was passed in
            # (subtract 1 from the index b/c computer scientists love to start at 0!)
            state = states[index-1]
            state += 1
            if state > 1:
                state = -1
            states[index-1] = state
            
            storage._setData('lefthallway_switches', states)
            
            # Change graphic for that switch
            if state == -1:
                image = 'switch_down.png'
            elif state == 0:
                image = 'switch_mid.png'
            else:
                image = 'switch_up.png'
            gfx = os.path.join(PATH_GRAPHICS_TILES, image)
            ad.play(SOUND, 'pull_switch', VOLUME_SOUND)
            obj.changeImage(gfx)
                
            # Solution to the switch puzzle (from left to right):
            # up down down up up
            # (The gender of the five people on the portrait
            # are mapped to the positioning of the switches.
            # The encoding of gender is hinted at in the abandoned chamber.)
            solution = [1, -1, -1, 1, 1]
            if states == solution:
                # Puzzle solved
                storage._toggleCutscene(True)
                ad.play(SOUND, 'doorstop3', VOLUME_SOUND)
                lastdir = m.getPlayer().getDirection()
                m.getPlayer().setDirection(string_to_direction("up-right"))
                storage._wait(250)
                ad.play(SOUND, '07_pick_lock', VOLUME_SOUND)
                storage._wait(500)
                tr = GlobalServices.getTextRenderer()
                tr.write("Something has happened. I think this is the correct combination.", 3)
                m.getPlayer().setDirection(string_to_direction(lastdir))
                storage._setData('lefthallway_puzzle_solved', True)
                storage._toggleCutscene(False)
    
    storage._halt()
 def face(direction):
     fl.point(direction)
     player.setDirection(string_to_direction(direction))
 def face(direction):
     fl = m.getOverlay("_flashlight")
     fl.point(direction)
     player.setDirection(string_to_direction(direction))
 def _faceObject(self, player, obj):
     directionstring = get_direction_from_point_to_point(\
                       player.currentsprite.rect.center, obj.rect.center)
     direction = string_to_direction(directionstring)
     player.setDirection(direction)