本文整理汇总了Python中gamestate.GameState.restoreFromState方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.restoreFromState方法的具体用法?Python GameState.restoreFromState怎么用?Python GameState.restoreFromState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gamestate.GameState
的用法示例。
在下文中一共展示了GameState.restoreFromState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameModel
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import restoreFromState [as 别名]
#.........这里部分代码省略.........
@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"] = self.agents
save_state["Items"] = self.items
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
@param filename: the name of the file (including path) to load from
@return: None"""
fname = os.path.join(path, filename)
try:
load_file = open(fname, 'r')
except(IOError):
sys.stderr.write("Error: Can't find save game file '" + fname + "'\n")
return
self.deleteMaps()
self.clearAgents()
save_state = yaml.load(load_file)
self.game_state.restoreFromState(save_state["GameState"])
maps = save_state["Agents"]
for map_name in maps:
for agent_name in maps[map_name]:
agent = {agent_name:maps[map_name][agent_name]}
self.addAgent(map_name, agent)
self.items = save_state["Items"]
load_file.close()
def teleport(self, agent, position):
"""Called when a an agent is moved instantly to a new position.
The setting of position may wan to be created as its own method down
the road.
@type position: String Tuple
@param position: X,Y coordinates passed from engine.changeMap
@return: fife.Location"""
logging.debug(position)
coord = fife.DoublePoint3D(float(position[0]), float(position[1]), 0)
location = fife.Location(self.active_map.agent_layer)
location.setMapCoordinates(coord)
agent.teleport(location)
def getObjectAtCoords(self, coords):
"""Get the object which is at the given coords
@type coords: fife.Screenpoint
@param coords: Coordinates where to check for an object
@rtype: fife.Object
@return: An object or None"""
instances = self.active_map.cameras[
self.active_map.my_cam_id].\
getMatchingInstances(coords, self.active_map.agent_layer)
# no object returns an empty tuple
示例2: GameModel
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import restoreFromState [as 别名]
#.........这里部分代码省略.........
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
@param filename: the name of the file (including path) to load from
@return: None"""
fname = '/'.join([path, filename])
try:
load_file = open(fname, 'r')
except(IOError):
sys.stderr.write("Error: Can't find save game file\n")
return
self.deleteMaps()
self.clearAgents()
save_state = yaml.load(load_file)
self.game_state.restoreFromState(save_state["GameState"])
maps = save_state["Agents"]
for map_name in maps:
for agent_name in maps[map_name]:
agent = {agent_name:maps[map_name][agent_name]}
self.addAgent(map_name, agent)
# Load the current map
if self.game_state.current_map_name:
self.loadMap(self.game_state.current_map_name)
load_file.close()
# Recreate all the behaviours. These can't be saved because FIFE
# objects cannot be pickled
self.placeAgents()
self.placePC()
# In most maps we'll create the PlayerCharacter Instance internally.
# In these cases we need a target position
def teleport(self, agent, position):
"""Called when a an agent is moved instantly to a new position.
The setting of position may wan to be created as its own method down the road.
@type position: String Tuple
@param position: X,Y coordinates passed from engine.changeMap
@return: fife.Location"""
print position
coord = fife.DoublePoint3D(float(position[0]), float(position[1]), 0)
location = fife.Location(self.active_map.agent_layer)
location.setMapCoordinates(coord)
agent.teleport(location)