本文整理汇总了Python中level.Level.player方法的典型用法代码示例。如果您正苦于以下问题:Python Level.player方法的具体用法?Python Level.player怎么用?Python Level.player使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类level.Level
的用法示例。
在下文中一共展示了Level.player方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_level
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import player [as 别名]
def load_level(game, filename):
filename = os.path.join('levels', filename)
try:
tmx_data = pytmx.load_pygame(filename, pixelalpha=True)
except:
print 'Level %s could not be read as a TMX file.' % (filename)
raise
try:
name = tmx_data.name
except AttributeError:
print 'Level %s has no name: invalid level file.' % (filename)
width = tmx_data.width
height = tmx_data.height
state_images = defaultdict(dict)
animations = defaultdict(lambda: defaultdict(Animation))
for tile_id, properties in tmx_data.tile_properties.items():
image = tmx_data.getTileImageByGid(tile_id)
try:
name = properties['name']
except KeyError:
continue
state = properties.get('state', 'default')
frame = properties.get('frame', None)
if frame:
delay = properties.get('frame-delay', '4')
try:
delay = int(delay)
except ValueError:
print "Level %s has invalid frame delay of %s for frame %s/%s/%s" % (filename, delay, name, state, frame)
try:
frame = int(frame)
except ValueError:
print "Level %s has invalid frame: %s/%s/%s" % (filename, name, state, frame)
animations[name][state].add_frame(frame, image, delay)
else:
state_images[name][state] = image
for state in animations.values():
for animation in state.values():
animation.finalise()
level = Level(game, name, width, height)
for layer in tmx_data.tilelayers:
for (x, y, tile) in layer:
if tile == 0:
continue
name = tmx_data.tile_properties[tile]['name']
state = tmx_data.tile_properties[tile].get('state', 'default')
objtype = OBJECTS[name]
obj = objtype(level=level, location=(x, y))
obj.state = state
obj.state_images = state_images[name]
obj.animations = animations[name]
if isinstance(obj, Player):
level.player = obj
for obj in tmx_data.getObjects():
x = int(obj.x / TILE_W)
y = int(obj.y / TILE_H)
w = int(obj.width / TILE_W)
h = int(obj.height / TILE_H)
region = Region(obj.name, level, (x, y), (w, h))
if hasattr(obj, 'message'):
region.message = obj.message.decode('string-escape')
if hasattr(obj, 'points'):
region.set_vertices([(px/TILE_W, py/TILE_H) for (px, py) in obj.points])
if hasattr(obj, 'dependencies'):
for name in obj.dependencies.split(','):
region.add_dependency(name)
if hasattr(obj, 'anti_dependencies'):
for name in obj.anti_dependencies.split(','):
region.add_anti_dependency(name)
region.visible = hasattr(obj, 'show')
region.state_images = {'default' : None, 'visible' : state_images['hint']['default']}
level.load_finished()
return level