def relaxlever(storage, obj, m):
    storage._go()
    if not storage._getData('library_relaxlever_pressed')\
    and storage._playerInDistance(m.getPlayer().position, obj.rect):
        ad = GlobalServices.getAudioDevice()
        ad.play(SOUND, 'pull_switch', VOLUME_SOUND)
        # Change graphics
        downswitch = os.path.join(PATH_GRAPHICS_TILES,'switch_down.png')
        obj.changeImage(downswitch)
        shelf = m.getObjectByName('shelf')
        ad.play(SOUND, 'shelf', VOLUME_SOUND)
        # Re-position the shelf
        m.removeObject(shelf, True)
        
        add_to_map(get_savegame(), OBJECT, 'libraryupstairs', 'shelf',\
                   pygame.Rect(conv_tile_pixel((47,10), m), conv_tile_pixel((4,6), m)),\
                   'libraryupstairs_shelf', 'bigshelf_four.png', True)
        
        # Add the next lever (that was behind the moved shelf)
        add_to_map(get_savegame(), OBJECT, 'libraryupstairs', 'officelever',\
                   pygame.Rect(conv_tile_pixel((45,11), m), conv_tile_pixel((1,2), m)),\
                   'libraryupstairs_officelever', 'switch_up.png', True)
        
        storage._accessData()
        storage._setData('library_relaxlever_pressed', True)
    storage._halt()
Ejemplo n.º 2
0
 def initMapLoading(self, name):
     # Check if there are MapProperties for this map by looking into the
     # savegame dict object.
     shelf = get_savegame()
     try:
         # Dictionary of saved map properties
         saveds = shelf['saved_maps']
         # Properties of this particular map
         properties = saveds[name]
     except KeyError:
         # No properties found
         properties = None
     # If this map hasn't been loaded yet, do so and place it inside the map dict
     if not MapFactory.mapAlreadyLoaded(name):
         # Map is loading. Change game state and notify other controllers
         # that a loading process is going on right now
         self.state = STATE_GAME_MAP_LOADING
         self.evManager.post(GameStateChangedEvent(self.state))
         
         MapFactory.loadMap(name, properties)
     else:
         # If it has already been loaded, change the map on your own
         # (no need for a 1-frame loading screen, amirite?)
         m = MapFactory.getMap(name)
         if properties is not None:
             m.setInteractives(properties.scripts, properties.objects)
         method = m.init_method
         self.changeMap(m, method)
 def teleport(self, source, obj, target, destination):
     self._go()
     
     if self._playerInDistance(source.getPlayer().position, obj.rect):
         # Play the sound of this TeleportClickable object
         # (if there is one; could be a door squeaking etc)
         if hasattr(obj, 'sound'):
             GlobalServices.getAudioDevice().play(SOUND, obj.sound, 0.8)
         
         self.teleport_in_progress = True
         set_property(PLAYER_MOVEMENT_ENABLED, False)
         
         # Save the state of the current map's properties to the persistent shelf
         # before teleporting to the new map
         update_persistent_map_properties(source, get_savegame())
         
         dur = 1000
         fadeout = OverlayFactory.create_animated_color((0,0,0), dur, 0, True, 0, 255)
         source.addOverlay(fadeout)
         self._wait(dur)
         source.rendering_enabled = False
         GlobalServices.getEventManager().post(MapChangeRequestEvent((target, destination)))
         
         source.removeOverlay(fadeout)
         source.flushOverlayQueue()
         set_property(PLAYER_MOVEMENT_ENABLED, True)
         self.teleport_in_progress = False
         
     self._halt()
Ejemplo n.º 4
0
 def save(self, disp=False):                
     # Get the savegame data
     temp = get_savegame()
     # Open the "real" shelf (the one the player can load up again)!
     save = shelve.open(CURRENT_SHELF_FILENAME[0])
     
     # Save persistent data that needs to be stored in order to retrieve the game state.
     # All data that is used to do that is actually the player's current position,
     # the current map where this position applies, and the currently playing background
     # music.
     # Pre-defined keys for the dict
     save['player_position'] = self.player.position
     save['current_map'] = self.currentmap.properties['key_name']
     save['player_inventory'] = self.player.inventory
     save['current_sounds'] = GlobalServices.getAudioDevice().getPlayingSounds()
     
     temp['global_overlays'] = get_global_overlays()
     
     # Update the persistent map properties for the current map
     update_persistent_map_properties(self.currentmap, temp)
     # Copy the rest of the shelf data to the "correct" save file
     copy_to_shelve(temp, save)
     
     # Close the shelves again; that's it!
     save.close()
     
     if disp:
         # Display the optional success message using the TextRenderer module
         tr = GlobalServices.getTextRenderer()
         tr.write("Game saved.", 3)
def officelever(storage, obj, m):
    storage._go()
    if storage._playerInDistance(m.getPlayer().position, obj.rect):
        if not storage._getData('library_officelever_pressed'):
            storage._toggleCutscene(True)
            ad = GlobalServices.getAudioDevice()
            ad.play(SOUND, 'pull_switch', VOLUME_SOUND)
            
            # Change graphics for this lever
            downswitch = os.path.join(PATH_GRAPHICS_TILES,'switch_down.png')
            obj.changeImage(downswitch)
            
            # Grab the shelf in atrium.tmx and delete it
            remove_object_from_map_properties(get_savegame(), 'atrium',\
                                              OBJECT, 'mastershelf', True)
            
            # Add the TeleportClickable to that map
            from src.model.Clickable import TeleportClickable, Clickable
            tele = TeleportClickable('tpmasterroom',\
                                     pygame.Rect(conv_tile_pixel((24, 4), m),\
                                            conv_tile_pixel( (2, 3), m)),\
                                     None, 'atrium_tpmasterroom', 'doormove6',\
                                     'masterroom', 32*16, 35*16)
            add_object_to_map_properties(get_savegame(), 'atrium',\
                                         TELEPORTOBJECT, tele)
            
            # Add vandalized painting image
            painting = get_object_from_map_properties(get_savegame(), 'librarydownstairs','painting')
            vandalized = os.path.join(PATH_GRAPHICS_TILES, 'vandalizedpainting.png')
            painting.changeImage(vandalized)
            update_object_in_map_properties(get_savegame(), 'librarydownstairs', painting)
            
            # Add new wall texts on this map and librarydownstairs.tmx
            add_to_map(get_savegame(), OBJECT, 'libraryupstairs', 'message',\
               pygame.Rect(conv_tile_pixel((43,36), m), conv_tile_pixel((14,5), m)),\
               'libraryupstairs_message', 'message_3.png', True)
            
            # Add the scare script
            add_to_map(get_savegame(), SCRIPT, 'libraryupstairs', 'scare',\
                   pygame.Rect(conv_tile_pixel((38,14), m), conv_tile_pixel((1,6), m)),\
                   'libraryupstairs_scare')
            
            message4path = os.path.join(PATH_GRAPHICS_TILES, 'message_4.png')
            message4 = pygame.image.load(message4path).convert_alpha()
            othermsg = Clickable('message', pygame.Rect(conv_tile_pixel((22,18), m),\
                                 conv_tile_pixel((6,6), m)),\
                                 'librarydownstairs_message', None,
                                 message4, message4path)
            add_object_to_map_properties(get_savegame(), 'librarydownstairs',\
                                         OBJECT, othermsg)                                 
            
            # Toggle this event as "happened"
            storage._setData('library_officelever_pressed', True)
            
            storage._toggleCutscene(False)
        
    storage._halt()
def librarykey(storage, obj, m):
    storage._go()
    if storage._playerInDistance(m.getPlayer().position, obj.rect):
        tr = GlobalServices.getTextRenderer()
        ad = GlobalServices.getAudioDevice()
        ad.play(SOUND, 'pick_key', VOLUME_SOUND)
        tr.write("Got 'Library Key'", 3, COLOR_GOT_ITEM)
        m.getPlayer().inventory.add(ItemFactory.create(INVENTORY_ITEM_LIBRARY_KEY, 1))
        remove_from_map(get_savegame(), OBJECT, 'mirrorhall', 'librarykey')
        storage._setData('librarykey_obtained', True)
    storage._halt()
 def newgame(self, name):
     # Delete the current shelf (if any)
     self.gh.deleteSavegame(name)
     # Create a shelf file handle using the given name
     set_shelf(name)
     # Initialize an empty dictionary for the saved map properties
     shelf = get_savegame()
     shelf['saved_maps'] = {}
     # Fadeout music
     GlobalServices.getAudioDevice().stop(AudioDevice.MUSIC, FADEOUT_TIME)
     # Set the player's start position
     self.gh.player.setPosition((240, 208))
     # Initialize the map loading of the first map
     self.gh.initMapLoading("bedroom")
def ceilingdoor(storage, obj, m):
    storage._go()
    if storage._playerInDistance(m.getPlayer().position, obj.rect, 180):
        GlobalServices.getEventManager().post(ObjectHighlightedEvent(None))
        inv = m.getPlayer().inventory
        tr = GlobalServices.getTextRenderer()
        ad = GlobalServices.getAudioDevice()
        storage._toggleCutscene(True)
        if inv.containsName(INVENTORY_ITEM_LADDER):
            m.getPlayer().setPosition(conv_tile_pixel((9,15), m))
            # Add ladder to this map
            ad.play(SOUND, '05_attach_ladder', VOLUME_SOUND)
            from src.model.Clickable import TeleportClickable
            ladderpath = os.path.join(PATH_GRAPHICS_TILES, 'ladder_vertical.png')
            laddersurf = pygame.image.load(ladderpath).convert_alpha()            
            
            ladder = TeleportClickable('tpattic',\
                                     pygame.Rect(conv_tile_pixel((9, 7), m),\
                                            conv_tile_pixel( (2, 7), m)),\
                                     m, None, 'ladder_climb',\
                                     'attic', 8*16, 17*16, laddersurf,\
                                     ladderpath, True)
            add_object_to_map_properties(get_savegame(), 'masterroom',\
                                         TELEPORTOBJECT, ladder)
            remove_from_map(get_savegame(), OBJECT, 'masterroom', 'ceilingdoor')
            # Reset player blah
            inv.remove(inv.get(INVENTORY_ITEM_LADDER))
        else:
            tr.write("There is a loft hatch on the ceiling.", 3)
            storage._wait(3000)
            tr.write("I need something to get up there.", 3)
            if not storage._getData('masterroom_ladder_needed'):
                storage._wait(3000)
                ad.play(MUSIC, 'bgm_3', VOLUME_MUSIC, -1)
            storage._setData('masterroom_ladder_needed', True)
        storage._toggleCutscene(False)
    storage._halt()
def ladder(storage, obj, m):
    storage._go()
    if storage._playerInDistance(m.getPlayer().position, obj.rect):
        tr = GlobalServices.getTextRenderer()
        ad = GlobalServices.getAudioDevice()
        if storage._getData('masterroom_ladder_needed'):
            storage._toggleCutscene(True)
            tr.write("This ladder should get me up through that loft hatch.", 3)
            storage._wait(3000)
            inv = m.getPlayer().inventory
            inv.add(ItemFactory.create(INVENTORY_ITEM_LADDER, 1))
            remove_from_map(get_savegame(), OBJECT, 'rightwing', 'ladder')
            ad.play(SOUND, 'pick_item', VOLUME_SOUND)
            tr.write("Got 'Ladder'", 3, COLOR_GOT_ITEM)
            storage._toggleCutscene(False)
            GlobalServices.getEventManager().post(ObjectHighlightedEvent(None))
        else:
            tr.write("There is a ladder on the ground. I have no purpose for that right now.", 3)
    storage._halt()
def leftroomopening(storage, obj, m):
    storage._go()
    tr = GlobalServices.getTextRenderer()
    ad = GlobalServices.getAudioDevice()
    if storage._getData('flashlight_obtained'):
        m.getPlayer().stopMoving()
        storage._toggleCutscene(True)
        
        ad.play(SOUND, 'doorclose', VOLUME_SOUND_AMBIENT)
        
        storage._wait(1000)
        
        tr.write("That noise came from across the hallway. Was it a door opening?", 3)
        
        storage._wait(1500)
        
        remove_from_map(get_savegame(), SCRIPT, 'righthallway', 'righthallway_leftroomopening')
        
        storage._toggleCutscene(False)
    storage._halt()
 def teleport(self, source, target, destination):
     self._go()
     self.teleport_in_progress = True
     set_property(PLAYER_MOVEMENT_ENABLED, False)
     
     # Save the state of the current map's properties to the persistent shelf
     # before teleporting to the new map
     update_persistent_map_properties(source, get_savegame())
     
     dur = 1000
     fadeout = OverlayFactory.create_animated_color((0,0,0), dur, 0, True, 0, 255)
     source.addOverlay(fadeout)
     self._wait(dur)
     source.rendering_enabled = False
     GlobalServices.getEventManager().post(MapChangeRequestEvent((target, destination)))
     
     set_property(PLAYER_MOVEMENT_ENABLED, True)
     source.removeOverlay(fadeout)
     
     self.teleport_in_progress = False
     self._halt()
def flashlight(storage, obj, m):
    storage._go()
    
    tr = GlobalServices.getTextRenderer()
    ad = GlobalServices.getAudioDevice()
    
    storage._faceObject(m.getPlayer(), obj)
    
    if not storage._playerInDistance(m.getPlayer().position, obj.rect):
        tr.write("I can't reach that from here.", 3)
    else:
        # Bed scare sequence done
        if storage._getData('bedroom_bedscare_done'):
            # Add the flashlight to the inventory
            m.getPlayer().inventory.add(\
                          ItemFactory.create(INVENTORY_ITEM_FLASHLIGHT, 1))
            ad.play(SOUND, 'pick_item', VOLUME_SOUND)
            tr.write("Got 'Flashlight'", 3, COLOR_GOT_ITEM)
            # Delete the note from the map
            m.removeObject(obj)
            remove_from_map(get_savegame(), OBJECT, 'bedroom', 'bedroom_flashlight')
            # Set a flag that this script was executed
            storage._setData('flashlight_obtained', True)        
            # Add the global flashlight overlay, deleting the others
            flashlight = OverlayFactory.create_flashlight()
            set_global_overlays([flashlight])
            # Add the overlay to this map, too
            m.clearOverlays()
            m.addOverlay(flashlight)
            ad.play(SOUND, 'flashlight_toggle', VOLUME_SOUND)
            ad.stop(SOUND, 1500, 'insanity_bug3')
        else:
            storage._toggleCutscene(True)
            tr.write("Sometimes I need my flashlight when the power tends to get all freaky.", 3)
            storage._wait(3000)
            tr.write("I don't know if that's because the mansion is just old or haunted, though.", 3)
            storage._toggleCutscene(False)
    
    storage._halt()
 def load(self, name):
     # Point the shelf to be used to the additional argument
     set_shelf(name)
     # Open the save game shelf
     s = shelve.open(CURRENT_SHELF_FILENAME[0], "w")
     # Open the savegame dict
     s2 = get_savegame()
     # Set global overlays
     set_global_overlays(s['global_overlays'])
     # Copy shelf data to temp dict: exclude persistent stuff
     # that does not refer to "what the player has done gameplay-wise"
     copy_to_dict(s, s2, SHELF_PERSISTENT_KEYS)
     # Fadeout the (menu) music
     GlobalServices.getAudioDevice().stop(AudioDevice.MUSIC, FADEOUT_TIME)
     # Set persistently stored information like position and inventory
     self.gh.player.setPosition(s['player_position'])
     self.gh.player.setInventory(s['player_inventory'])
     # Re-play the saved ambient sounds and music
     GlobalServices.getAudioDevice().playList(s['current_sounds'])
     # Load the last map
     # Initialize the loading of testmap (for now)
     self.gh.initMapLoading(s['current_map'])
     # Finally, close the shelf again.
     s.close()
def powercutshort(storage, obj, m):
    storage._go()
    ad = GlobalServices.getAudioDevice()
    tr = GlobalServices.getTextRenderer()
    
    if storage._getData('entrancenote_obtained')\
    and not storage._getData('rightwing_powershortage'):
        storage._toggleCutscene(True)
        p = m.getPlayer()
        p.stopMoving()
        storage._setData('rightwing_powershortage', True)
        
        ad.play(SOUND, 'drone', VOLUME_SOUND)
        ad.play(SOUND, 'elec', VOLUME_SOUND)
        
        black = OverlayFactory.create_by_color((0,0,0), 0, 255)
        m.addOverlay(black)
        storage._wait(1000)
        
        m.removeOverlay(black)
        ad.play(SOUND, '27_spark1', VOLUME_SOUND)
        storage._wait(100)
        m.addOverlay(black)
        storage._wait(1500)
        
        m.removeOverlay(black)
        ad.play(SOUND, '27_spark2', VOLUME_SOUND)
        storage._wait(50)
        m.addOverlay(black)
        storage._wait(20)
        m.removeOverlay(black)
        ad.play(SOUND, '27_spark4', VOLUME_SOUND)
        storage._wait(30)
        m.addOverlay(black)
        storage._wait(50)
        ad.play(SOUND, '27_spark3', VOLUME_SOUND)
        m.removeOverlay(black)
        storage._wait(400)
        m.addOverlay(black)
        storage._wait(20)
        m.removeOverlay(black)
        ad.play(SOUND, '27_spark4', VOLUME_SOUND)
        storage._wait(30)
        m.addOverlay(black)
        ad.play(SOUND, '27_spark3', VOLUME_SOUND)
        storage._wait(50)
        fadein = OverlayFactory.create_animated_color((0,0,0), 3000, 0, True, 255, 155)
        storage._wait(600)
        m.removeOverlay(black)
        m.addOverlay(fadein)
        
        storage._wait(3000)
        
        tr.write("What was that? A... power shortage?", 3)
        storage._wait(500)
        p.setDirection([1,0])
        storage._wait(500)
        p.setDirection([1,1])
        storage._wait(500)
        p.setDirection([-1,0])
        storage._wait(500)
        p.setDirection([1,0])
        storage._wait(500)
        p.setDirection([0,-1])
        storage._wait(500)
        tr.write("Keep going, Clyde... it's nothing.", 3)
        remove_from_map(get_savegame(), SCRIPT, 'rightwing', 'rightwing_powercutshort')
        add_global_overlay(OverlayFactory.create_by_color((0,0,0), 0, 155))
        storage._toggleCutscene(False)
        
    storage._halt()
Ejemplo n.º 15
0
def ending(storage, m):
    storage._go()
    GlobalServices.getEventManager().post(ObjectHighlightedEvent(None))
    storage._toggleCutscene(True)
    storage._wait(3000)
    white = OverlayFactory.create("noise.png", pygame.BLEND_MULT)
    def static(ms):
        m.addOverlay(white)
        ad.play(SOUND, 'noise', VOLUME_SOUND + 0.1, -1)
        storage._wait(ms)
        m.removeOverlay(white)
        ad.stop(SOUND, 0, 'noise')
    tr = GlobalServices.getTextRenderer()
    ad = GlobalServices.getAudioDevice()
    tr.write("W-w-what am I supposed to do now?", 3)
    storage._wait(1400)
    static(340)
    storage._wait(1600)
    tr.write("I lose track of the sharp edges around me...", 3)
    storage._wait(2000)
    towhite = OverlayFactory.create_animated_color((255,255,255),\
              1000, 0, True, 0, 255)
    m.addOverlay(towhite)
    storage._wait(1500)
    player = m.getPlayer()
    player.setPosition(conv_tile_pixel((8,9), m))
    player.setAnimation("kneel")
    storage._wait(400)
    fadeout = OverlayFactory.create_animated_color((255,255,255),\
              1000, 0, True, 255, 0)
    m.addOverlay(fadeout)
    m.removeOverlay(towhite)
    storage._wait(3000)
    tr.write("Did I...", 3)
    player.setAnimation("walk")
    storage._wait(800)
    static(200)
    storage._wait(600)
    static(40)
    storage._wait(600)
    static(1000)
    storage._wait(2500)
    player.setDirection([0,-1])
    storage._wait(500)
    tr.write("It was... me..?", 3)
    storage._wait(1000)
    static(500)
    storage._wait(3000)
    static(100)
    storage._wait(1000)
    ad.play(SOUND, 'pick_item', VOLUME_SOUND)
    remove_from_map(get_savegame(), OBJECT, 'attic', 'gun')
    tr.write("I should...", 3)
    storage._wait(3000)
    toblack = OverlayFactory.create_animated_color((0,0,0), 2500, 0, True, 0, 255)
    m.addOverlay(toblack)
    ad.stop(SOUND, 2750, 'insanity_ear_ring')
    ad.stop(MUSIC, 2750)
    storage._wait(3500)
    ad.play(SOUND, 'gun_cock', VOLUME_SOUND)
    storage._wait(3500)
    storage._halt()
    rollCredits(storage, m)
 def _accessData(self):
     self.s = get_savegame()
     self.shelfopen = True
Ejemplo n.º 17
0
def scare(storage, obj, m):
    storage._go()
    
    ad = GlobalServices.getAudioDevice()
    tr = GlobalServices.getTextRenderer()
    
    storage._toggleCutscene(True)
    
    # Force the flashlight to point to the right
    player = m.getPlayer()
    player.stopMoving()
    
    fl = m.getOverlay("_flashlight")
    # Helper function for looking in a direction
    def face(direction):
        fl.point(direction)
        player.setDirection(string_to_direction(direction))
        
    face("right")
    
    # Overlay creation
    red = OverlayFactory.create_by_color((170, 0, 0), 0, 50)
    black = OverlayFactory.create_by_color((0, 0, 0), 0, 210)
        
    # Show the figure
    ad.play(SOUND, 'scare_wood_creak_walk2', VOLUME_SOUND)
    ad.play(SOUND, '24_amb_noise', VOLUME_SOUND_AMBIENT, -1)
    shadow = m.getShadow()
    shadow.setPosition(conv_tile_pixel((43, 8), m))
    m.addOverlay(red)
    shadow.setVisible(True)
    shadow.moveBy((0, 100), 5000)
    
    storage._wait(1000)
    
    ad.stop(SOUND, 0, '24_amb_noise')
    ad.play(SOUND, '27_spark3', VOLUME_SOUND)
    ad.play(SOUND, 'scare_tingeling', VOLUME_SOUND, 0, 1000)
    m.addOverlay(black)
    m.removeOverlay(red)
    shadow.setVisible(False)
    shadow.setPosition(conv_tile_pixel((43, 14), m))
    
    storage._wait(2000)
    
    ad.play(SOUND, 'scare_wood_creak_walk3', VOLUME_SOUND)
    ad.play(SOUND, 'insanity_baby_cry2', VOLUME_SOUND)
    ad.play(SOUND, '27_orb_implode', VOLUME_SOUND)
    ad.play(SOUND, '24_amb_noise', VOLUME_SOUND_AMBIENT, -1)
    m.addOverlay(red)
    m.removeOverlay(black)
    shadow.setVisible(True)
    shadow.moveBy((-75, 0), 7500)
    
    storage._wait(2500)
    
    ad.stop(SOUND, 1750, '24_amb_noise')
    ad.play(SOUND, '27_spark4', VOLUME_SOUND)
    ad.play(SOUND, 'scare_male_terrified5', VOLUME_SOUND)
    m.addOverlay(black)
    m.removeOverlay(red)
    shadow.setVisible(False)
    
    add_to_map(get_savegame(), OBJECT, 'atrium', 'message',\
               pygame.Rect(conv_tile_pixel((29,7), m), conv_tile_pixel((8,4), m)),\
               'atrium_message', 'message_1.png', True)
    
    storage._wait(1000)
    
    m.removeOverlay(black)
    tr.write("What in the world was that thing?!", 2)
    face("left")
    storage._wait(250)
    face("up-right")
    storage._wait(250)
    face("right")
    storage._wait(100)
    face("right-down")
    storage._wait(250)
    face("right")
    storage._wait(1150)
    tr.write("Where did it go?", 2)
    storage._wait(2000)
    face("up")
    tr.write("Did it write... this?", 3)
    storage._wait(3000)
    face("right")
    
    m.removeObject(obj)
    storage._toggleCutscene(False)
    
    remove_from_map(get_savegame(), OBJECT, 'atrium', 'blockingshelf')
    storage._setData('atrium_scaredone', True)
    add_to_map(get_savegame(), OBJECT, 'atrium', 'blockingshelf',\
               pygame.Rect(conv_tile_pixel((11,25), m), conv_tile_pixel((2,8), m)),\
               'atrium_blockingshelf', 'bigshelf_right.png', True)
    
    storage._halt()