当前位置: 首页>>代码示例>>Python>>正文


Python GameState.getObjectById方法代码示例

本文整理汇总了Python中gamestate.GameState.getObjectById方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.getObjectById方法的具体用法?Python GameState.getObjectById怎么用?Python GameState.getObjectById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gamestate.GameState的用法示例。


在下文中一共展示了GameState.getObjectById方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: data

# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getObjectById [as 别名]

#.........这里部分代码省略.........
        

    def addPC(self, layer, pc, instance):
        """Add the PC to the map
           @type layer: fife.Layer
           @param layer: FIFE layer object exists in
           @type pc: PlayerCharacter
           @param pc: PlayerCharacter object
           @type instance: fife.Instance
           @param instance: FIFE instance of PC
           @return: None
        """
        # For now we copy the PC, in the future we will need to copy
        # PC specifics between the different PC's
        self.game_state.PC = pc
        self.game_state.PC.setup()
        
        # The PC has an inventory, and also some filling of the ready slots 
        # in the HUD. At this point we sync the contents of the ready slots 
        # with the contents of the inventory.
        self.view.hud.initializeInventory()

    def addObject(self, layer, obj, instance):
        """Adds an object to the map.
           @type layer: fife.Layer
           @param layer: FIFE layer object exists in
           @type obj: GameObject
           @param obj: corresponding object class
           @type instance: fife.Instance
           @param instance: FIFE instance of object
           @return: None
        """

        ref = self.game_state.getObjectById(obj.ID, \
                                            self.game_state.current_map_name) 
        if ref is None:
            # no, add it to the game state
            self.game_state.objects[self.game_state.current_map_name][obj.ID] \
                                                                          = obj
        else:
            # yes, use the current game state data
            obj.X = ref.X
            obj.Y = ref.Y
            obj.gfx = ref.gfx  
             
        if obj.trueAttr("NPC"):
            # create the agent
            obj.setup()
            
            # create the PC agent
            obj.start()

    def objectActive(self, ident):
        """Given the objects ID, pass back the object if it is active,
           False if it doesn't exist or not displayed
           @type ident: string
           @param ident: ID of object
           @rtype: boolean
           @return: Status of result (True/False)"""
        for i in \
           self.game_state.getObjectsFromMap(self.game_state.current_map_name):
            if (i.ID == ident):
                # we found a match
                return i
        # no match
        return False
开发者ID:m64,项目名称:PEG,代码行数:70,代码来源:engine.py

示例2: data

# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getObjectById [as 别名]

#.........这里部分代码省略.........
            self.addObject( layer, obj, instance)

        

    def addPC(self, layer, pc, instance):
        """Add the PC to the map
            Inputs:
                layer = FIFE layer object exists in
                pc = PlayerCharacter object
                instance = FIFE instance of PC
            Returns:
                Nothing
        """
        # add to view data 
        self.view.activeMap.addObject(pc.ID, instance)          
        
        # sync with game data
        if not self.gameState.PC:
            self.gameState.PC = pc
            
        self.gameState.PC.setup()


    def addObject(self, layer, obj, instance):
        """Adds an object to the map.
            Inputs:
                layer = FIFE layer object exists in
                obj = corresponding object class
                instance = FIFE instance of object
            Returns:
                Nothing
        """
        
        ref = self.gameState.getObjectById(obj.ID) 
        if ref is None:
            # no, add it to the game state
            obj.map_id = self.gameState.currentMap
            self.gameState.objects[obj.ID] = obj
        else:
            # yes, use the current game state data
            obj.X = ref.X
            obj.Y = ref.Y
            obj.gfx = ref.gfx  
            
        # add it to the view
        self.view.activeMap.addObject(obj.ID, instance)          
       
        if obj.trueAttr("NPC"):
            # create the agent
            obj.setup()
            
            # create the PC agent
            obj.start()

    def addDoors(self, doors):
        """Add all the doors to the map as well.
           As an object they will have already been added.
           @type doors: list
           @param doors: List of doors
           @return: None"""
        for i in doors:
            self.doors[str(i.id)] = MapDoor(i.id, i.destmap, (i.destx, i.desty))

    def objectActive(self, ident):
        """Given the objects ID, pass back the object if it is active,
           False if it doesn't exist or not displayed
开发者ID:mvbarracuda,项目名称:parpg_mvbarracuda,代码行数:70,代码来源:engine.py

示例3: GameModel

# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getObjectById [as 别名]

#.........这里部分代码省略.........
                      
        obj = self.createMapObject(self.active_map.agent_layer, 
                                   entity_data, inst_id, world)

        if agent.has_key("Statistics"):
            self.create_stats(obj)
            for name, val in agent["Statistics"].iteritems():
                obj.characterstats.primary_stats[name].value = val

        if agent.has_key("Inventory"):
            inv = agent["Inventory"]
            self.createInventoryItems(inv, obj, world)

        if agent.has_key("Equipment"):
            for slot, data in agent["Equipment"].iteritems():
                item = None
                if data.has_key("type"):
                    item_type = data["type"]
                    item_data = {}
                    item_data = self.checkAttributes(item_data, item_type)
                    if (item_data.has_key("containable") and 
                        item_data.has_key("equipable")):
                        item = self.createItem(
                            self.createUniqueID(data["ID"]), 
                            item_data, world, item_type)
                    else:
                        raise Exception(
                            "Item %s is not containable or equipable." % 
                            item_type
                        )
                else:
                    identifier = data["ID"]
                    if self.game_state.hasObject(identifier):
                        item = self.game_state.getObjectById(identifier)
                    else:
                        item_data = self.items[identifier]["Entity"]
                        item_type = item_data["containable"]["item_type"]
                        item = self.createItem(identifier, item_data,
                                                world, item_type)
                equip.equip(obj.equip, item.equipable, slot)
        if (obj.fifeagent and (obj.lockable and not obj.lockable.closed)):
            obj.fifeagent.behaviour.animate("opened", repeating=True)
        return obj

    def createInventoryItems(self, inv, obj, world):
        slots = inv["Slots"]
        obj.container.children = list()
        for x in xrange(slots):
            obj.container.children.append(None)
        items = inv["Items"] if inv.has_key("Items") else list()
        for data in items:
            item = None
            slot = data["Slot"] if data.has_key("Slot") else -1
            if data.has_key("type"):
                item_type = data["type"]
                item = self.createItemByType(item_type, data["ID"], world)
            else:
                identifier = data["ID"]
                item = self.createItemByID(world, identifier)
                    
            container.put_item(obj.container, item.containable, slot)

    def createItemByID(self, world, identifier):
        if self.game_state.hasObject(identifier):
            item = self.game_state.getObjectById(identifier)
        else:
开发者ID:parpg,项目名称:parpg,代码行数:70,代码来源:gamemodel.py

示例4: GameModel

# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getObjectById [as 别名]

#.........这里部分代码省略.........
        slot = attributes.pop("slot") if attributes.has_key("slot") else None
        obj = self.createContainerObject(attributes)        
        #obj = createObject(attributes, extra)
        if slot:
            container.moveItemToSlot(obj, slot)
        else:
            container.placeItem(obj, index)
    
    def deleteObject(self, object_id):
        """Removes an object from the game
        @param object_id: ID of the object
        @type object_id: str """
        del self.agents["All"][object_id]
        self.game_state.deleteObject(object_id)
        
    def save(self, path, filename):
        """Writes the saver to a file.
           @type filename: string
           @param filename: the name of the file to write to
           @return: None"""
        fname = '/'.join([path, filename])
        try:
            save_file = open(fname, 'w')
        except(IOError):
            sys.stderr.write("Error: Can't create save game: " + fname + "\n")
            return
        save_state = {}
        save_state["Agents"] = {}
        for map_name in self.agents:
            if map_name == self.ALL_AGENTS_KEY:
                continue
            agents_dict = {}
            for agent in self.agents[map_name]:
                agent_obj = self.game_state.getObjectById(agent, map_name)
                agent_inst = self.game_state.maps[map_name].\
                                    agent_layer.getInstance(agent)
                agent_dict = self.agents[map_name][agent]
                agent_dict.update(agent_obj.getStateForSaving())
                agent_dict["Rotation"] = agent_inst.getRotation()
                agents_dict[agent] = agent_dict
            save_state["Agents"][map_name] = agents_dict
        agents_dict = {}
        for agent in self.agents["All"]:
            map_name = self.agents["All"][agent]["Map"]
            agent_dict = self.agents["All"][agent]
            agent_obj = None
            if agent == "PlayerCharacter":
                agent_obj = self.game_state.player_character
            else:
                agent_obj = self.game_state.getObjectById(agent, map_name)
            if agent_obj:
                agent_inst = self.game_state.maps[map_name].\
                                    agent_layer.getInstance(agent)
                agent_dict.update(agent_obj.getStateForSaving())
                agent_dict["Rotation"] = agent_inst.getRotation()
                agent_dict["MapName"] = map_name
            agents_dict[agent] = agent_dict
        save_state["Agents"]["All"] = agents_dict
        save_state["GameState"] = self.game_state.getStateForSaving()
        yaml.dump(save_state, save_file)
        
        save_file.close()       

    def load(self, path, filename):
        """Loads a saver from a file.
           @type filename: string
开发者ID:mgeorgehansen,项目名称:PARPG_Technomage,代码行数:70,代码来源:gamemodel.py


注:本文中的gamestate.GameState.getObjectById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。