本文整理汇总了Python中gamestate.GameState.getObjectsFromMap方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.getObjectsFromMap方法的具体用法?Python GameState.getObjectsFromMap怎么用?Python GameState.getObjectsFromMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gamestate.GameState
的用法示例。
在下文中一共展示了GameState.getObjectsFromMap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: data
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getObjectsFromMap [as 别名]
#.........这里部分代码省略.........
@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
def getItemActions(self, obj_id):
"""Given the objects ID, return the text strings and callbacks.
@type obj_id: string
@param obj_id: ID of object
@rtype: list
@return: List of text and callbacks"""
actions = []
# note: ALWAYS check NPC's first!
obj = self.game_state.getObjectById(obj_id, \
self.game_state.current_map_name)
if obj is not None:
if obj.trueAttr("NPC"):
# keep it simple for now, None to be replaced by callbacks
actions.append(["Talk", "Talk", self.initTalk, obj])
actions.append(["Attack", "Attack", self.nullFunc, obj])
else:
actions.append(["Examine", "Examine", \
self.game_state.PC.approach, [obj.X, obj.Y], \
ExamineBoxAction(self, obj.name, obj.text)])
# is it a Door?
if obj.trueAttr("door"):
actions.append(["Change Map", "Change Map", \
self.game_state.PC.approach, [obj.X, obj.Y], \
ChangeMapAction(self, obj.target_map_name, \
obj.target_map, obj.target_pos)])
示例2: data
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getObjectsFromMap [as 别名]
#.........这里部分代码省略.........
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
@type ident: string
@param ident: ID of object
@rtype: boolean
@return: Status of result (True/False)"""
for i in self.gameState.getObjectsFromMap(self.gameState.currentMap):
if (i.ID == ident):
# we found a match
return i
# no match
return False
def getItemActions(self, obj_id):
"""Given the objects ID, return the text strings and callbacks.
@type obj_id: string
@param obj_id: ID of object
@rtype: list
@return: List of text and callbacks"""
actions=[]
# note: ALWAYS check NPC's first!
obj = self.gameState.getObjectById(obj_id)
if obj:
if obj.trueAttr("NPC"):
# keep it simple for now, None to be replaced by callbacks
actions.append(["Talk", "Talk", self.initTalk, obj])
actions.append(["Attack", "Attack", self.nullFunc, obj])
elif obj.trueAttr("Door"):
actions.append(["Change Map", "Change Map", \
self.gameState.PC.approach, [obj.X, obj.Y], \
ChangeMapAction(self, self.doors[str(i.ID)].map, [i.destx, i.desty])])
pass
else:
actions.append(["Examine", "Examine", self.gameState.PC.approach,
[obj.X, obj.Y], ExamineBoxAction(self, obj.name, obj.text)])
# is it a container?
if obj.trueAttr("container"):
actions.append(["Open", "Open", self.gameState.PC.approach, [obj.X, obj.Y], OpenBoxAction(self, "Box")])
示例3: GameModel
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getObjectsFromMap [as 别名]
#.........这里部分代码省略.........
if ref is None:
# no, add it to the game state
self.game_state.addObject(obj.general.identifier,
self.game_state.current_map_name, obj)
else:
# yes, use the current game state data
obj.fifeagent.pos.X = ref.X
obj.fifeagent.pos.Y = ref.Y
obj.fifeagent.gfx = ref.gfx
if obj.fifeagent.behaviour:
obj.fifeagent.behaviour.parent = obj
fifeagent.setup_behaviour(obj.fifeagent)
obj.fifeagent.behaviour.speed = self.settings.get("parpg", "PCSpeed")
#Start the behaviour
obj.fifeagent.behaviour.idle()
# create the agent
#obj.setup()
#obj.behaviour.speed = self.settings.parpg.PCSpeed
# create the PlayerCharacter agent
#obj.start()
#if obj.trueAttr("AnimatedContainer"):
# create the agent
#obj.setup()
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 game_object in \
self.game_state.getObjectsFromMap(self.game_state.current_map_name):
if (game_object.general.identifier == ident):
# we found a match
return game_object
# no match
return False
def movePlayer(self, position):
"""Code called when the player should move to another location
@type position: fife.ScreenPoint
@param position: Screen position to move to
@return: None"""
player = self.game_state.getObjectById("PlayerCharacter")
if(self.pc_run == 1):
player.fifeagent.behaviour.run(position)
else:
player.fifeagent.behaviour.walk(position)
def teleportAgent(self, agent, position):
"""Code called when an agent should teleport to another location
@type position: fife.ScreenPoint
@param position: Screen position to teleport to
@return: None"""
agent.teleport(position)
self.agents[agent.ID]["Position"] = position
def readObjectDB(self):
"""Reads the Object Information Database from a file. """
database_file = vfs.VFS.open(self.object_db_file)
database = yaml.load_all(database_file)
for object_info in database:
self.object_db.update(object_info)
示例4: GameModel
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getObjectsFromMap [as 别名]
#.........这里部分代码省略.........
"""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.addObject(self.game_state.current_map_name, 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 PlayerCharacter agent
obj.start()
if obj.trueAttr("AnimatedContainer"):
# create the agent
obj.setup()
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 game_object in \
self.game_state.getObjectsFromMap(self.game_state.current_map_name):
if (game_object.ID == ident):
# we found a match
return game_object
# no match
return False
def movePlayer(self, position):
"""Code called when the player should move to another location
@type position: fife.ScreenPoint
@param position: Screen position to move to
@return: None"""
if(self.pc_run == 1):
self.game_state.player_character.run(position)
else:
self.game_state.player_character.walk(position)
def teleportAgent(self, agent, position):
"""Code called when an agent should teleport to another location
@type position: fife.ScreenPoint
@param position: Screen position to teleport to
@return: None"""
agent.teleport(position)
self.agents[agent.ID]["Position"] = position
def readObjectDB(self):
"""Reads the Object Information Database from a file. """
database_file = file(self.object_db_file, "r")
database = yaml.load_all(database_file)
for object_info in database:
self.object_db.update(object_info)
def getAgentImportFiles(self):
"""Searches the agents directory for import files """
files = locateFiles("*.xml", self.agents_directory)
for xml_file in files:
xml_file = os.path.relpath(xml_file).replace("\\", "/")
try:
root = ElementTree.parse(xml_file).getroot()
if root.tag == "object":
self.agent_import_files[root.attrib["id"]] = xml_file
except SyntaxError as error:
assert(isinstance(error, SyntaxError))
print "Error parsing file " + xml_file + ": " + error.msg
#TODO: We may want to make this an fatal error later.
def getDialogues(self):
"""Searches the dialogue directory for dialogues """
files = locateFiles("*.yaml", self.dialogues_directory)
dialogue_parser = YamlDialogueParser()
for dialogue_filepath in files:
dialogue_filepath = os.path.relpath(dialogue_filepath) \
.replace("\\", "/")
# Note Technomage 2010-11-13: the new DialogueEngine uses its own
# parser now, YamlDialogueParser.
# dialogues = yaml.load_all(file(dialogue_file, "r"))
with file(dialogue_filepath, 'r') as dialogue_file:
try:
dialogue = dialogue_parser.load(dialogue_file)
except (DialogueFormatError,) as error:
logging.error('unable to load dialogue file {0}: {1}'
.format(dialogue_filepath, error))
else:
self.dialogues[dialogue.npc_name] = dialogue