Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, ctx, filename):
self.ctx = ctx
self.event = sdl.Event()
self.running = False
self.pressed = collections.defaultdict(bool)
# load data from pytmx
tmx_data = load_pysdl2_cffi(ctx, filename)
# create new data source
map_data = pyscroll.data.TiledMapData(tmx_data)
# create new renderer
screen_size = ctx.window.getWindowSize()
self.map_layer = pyscroll.TextureRenderer(ctx, map_data, screen_size)
self.center = [(i // self.map_layer.zoom) // 2 for i in map_data.pixel_size]
# create a font and pre-render some text to be displayed over the map
# f = pygame.font.Font(pygame.font.get_default_font(), 20)
# t = ["scroll demo. press escape to quit",
# "arrow keys move"]
# save the rendered text
# self.text_overlay = [f.render(i, 1, (180, 180, 0)) for i in t]
# set our initial viewpoint in the center of the map
def __init__(self):
filename = self.get_map('level.tmx')
# Load data from pyTMX
self.tmx_data = pytmx.load_pygame(filename, pixelalpha=True)
# Create new data source for pyScroll
self.map_data = pyscroll.data.TiledMapData(self.tmx_data)
# true while running
self.running = False
# load data from pytmx
tmx_data = load_pygame(self.filename)
# setup level geometry with simple pygame rects, loaded from pytmx
self.walls = list()
for object in tmx_data.objects:
self.walls.append(pygame.Rect(
object.x, object.y,
object.width, object.height))
# create new data source for pyscroll
map_data = pyscroll.data.TiledMapData(tmx_data)
# create new renderer (camera)
self.map_layer = pyscroll.BufferedRenderer(map_data, screen.get_size(), clamp_camera=False, tall_sprites=1)
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 = PyscrollGroup(map_layer=self.map_layer, default_layer=2)
self.hero = Hero()
# put the hero in the center of the map
self.hero.position = self.map_layer.map_rect.center
self.hero._position[0] += 200
# true while running
self.running = False
# load data from pytmx
tmx_data = load_pygame(self.filename)
# setup level geometry with simple pygame rects, loaded from pytmx
self.walls = list()
for object in tmx_data.objects:
self.walls.append(pygame.Rect(
object.x, object.y,
object.width, object.height))
# create new data source for pyscroll
map_data = pyscroll.data.TiledMapData(tmx_data)
# create new renderer (camera)
self.map_layer = pyscroll.BufferedRenderer(map_data, screen.get_size())
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 = PyscrollGroup(map_layer=self.map_layer, default_layer=2)
self.hero = Hero()
# put the hero in the center of the map
self.hero.position = self.map_layer.map_rect.center
def __init__(self, filename):
# load data from pytmx
tmx_data = load_pygame(filename)
# create new data source
map_data = pyscroll.data.TiledMapData(tmx_data)
# create new renderer
self.map_layer = pyscroll.orthographic.BufferedRenderer(map_data, screen.get_size())
# create a font and pre-render some text to be displayed over the map
f = pygame.font.Font(pygame.font.get_default_font(), 20)
t = ["scroll demo. press escape to quit",
"arrow keys move"]
# save the rendered text
self.text_overlay = [f.render(i, 1, (180, 180, 0)) for i in t]
# set our initial viewpoint in the center of the map
self.center = [self.map_layer.map_rect.width / 2,
self.map_layer.map_rect.height / 2]
# setup level geometry with simple pygame rects, loaded from pytmx
self.walls = list()
for object in tmx_data.objects:
self.walls.append(pygame.Rect(
object.x, object.y,
object.width, object.height))
# create fog layer
if self.fog_enabled:
fog_width = tmx_data.tilewidth * tmx_data.width
fog_height = tmx_data.tileheight * tmx_data.height
self.fog_of_war = fog.FogOfWar((fog_width, fog_height), self.walls)
# 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()
def initialize_renderer(self):
""" Initialize the renderer for the map and sprites
:rtype: pyscroll.BufferedRenderer
"""
# TODO: Use self.edges == "stitched" here when implementing seamless maps
visual_data = pyscroll.data.TiledMapData(self.data)
clamp = (self.edges == "clamped")
return pyscroll.BufferedRenderer(visual_data, prepare.SCREEN_SIZE, clamp_camera = clamp, tall_sprites = 2)