Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# create new data source for pyscroll
map_data = pyscroll.data.TiledMapData(tmx_data)
# create new renderer (camera)
# clamp_camera is used to prevent the map from scrolling past the edge
self.map_layer = pyscroll.BufferedRenderer(map_data,
screen.get_size(),
clamp_camera=True)
self.map_layer.zoom = 2
# pyscroll supports layered rendering. our map has 3 'under' layers
# layers begin with 0, so the layers are 0, 1, and 2.
# since we want the sprite to be on top of layer 1, we set the default
# layer for sprites as 2
self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer)
self.hero = Hero()
# put the hero in the starting position of the map
self.hero.position = get_starting_position(tmx_data.tilewidth,
starting_position)
# add our hero to the group
self.group.add(self.hero)
if self.fog_enabled:
self.group.add(self.fog_of_war)
self.screen = world.screen
w, h = world.screen.get_size()
#Create new renderer/camera
self.map_layer = pyscroll.BufferedRenderer(self.world.level.map_data,
(w, h),
clamp_camera=False,
colorkey=None,
alpha=True)
#The player, enemies, items etc. should to be on top of
#layer named in TMX "decoration behind"
#Find layer number of the layer named "decoration behind"
self.render_layer = 0
for layer_index in range(len(self.world.level.tmx_data.layers)):
if self.world.level.tmx_data.layers[layer_index].name == "walls":
self.render_layer = layer_index #content will be drawn on top of walls layer
self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer,
default_layer=self.render_layer)
#Players image position is actually camera position
player_image_position = self.world.appearance[self.world.player].rect
#Parallax background
self.star_field = parallaxStarfield.ParallaxStarfield(w, h,
player_image_position.x,
player_image_position.y)