def update_tile_layer(self, layer): tw = self.tmx_data.tilewidth th = self.tmx_data.tileheight pos = self.position background = layer.properties['background'] tile_position = [0, 0] # iterate over the tiles in the layer if background == "true": for x, y, data in layer.tiles(): tile_set = data[0] tile_crop = data[1] tile_position[0] = int(((x - y) * tw / 2) + pos[0] + (self.size[0] / 2) - (tw / 2)) tile_position[1] = int(((x + y) * th / 2) + pos[1]) tile = subsurface(self.tile_sets[tile_set], tile_crop) rect = SDL_Rect(tile_position[0], tile_position[1]) SDL_BlitSurface(tile, None, self.bg_surface, rect) """
def update_tile_layer(self, layer): tw = self.tmx_data.tilewidth th = self.tmx_data.tileheight position = self.position tile_position = [0, 0] if "background" in layer.properties: background = convert_to_bool(layer.properties['background']) if background: for x, y, data in layer.tiles(): tile_set = data[0] tile_crop = data[1] tile_position[0] = int(((x - y) * tw / 2) + position[0] + (self.size[0] / 2) - (tw / 2)) tile_position[1] = int(((x + y) * th / 2) + position[1]) tile = subsurface(self.tile_sets[tile_set], tile_crop) rect = SDL_Rect(tile_position[0], tile_position[1]) SDL_BlitSurface(tile, None, self.surfaces["background"], rect) elif not background: for x, y, data in layer.tiles(): tile_set = data[0] tile_crop = data[1] tile_position[0] = int(((x - y) * tw / 2) + position[0] + (self.size[0] / 2)) tile_position[1] = int(((x + y) * th / 2) + position[1] - 72) if tile_position[1] < (WindowSize.HEIGHT / 2): tile = subsurface(self.tile_sets[tile_set], tile_crop) rect = SDL_Rect(tile_position[0], tile_position[1]) SDL_BlitSurface(tile, None, self.surfaces["behind"], rect) else: pass tile = subsurface(self.tile_sets[tile_set], tile_crop) rect = SDL_Rect(tile_position[0], tile_position[1]) SDL_BlitSurface(tile, None, self.surfaces["front"], rect)
def create_surface(self, lines, font_size): max_chars = 8 tile_size = 16 offset = tile_size * 4 width = font_size * max_chars height = font_size * lines surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width + offset, height + offset, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000) cols = int(width / tile_size) + 3 rows = int(height / tile_size) + 3 sprite_crop = [0, 0, tile_size, tile_size] for i in range(cols + 1): for j in range(rows + 1): if (i == 0) and (j == 0): sprite_crop[0] = 0 sprite_crop[1] = 0 elif (i < cols) and (j == 0): sprite_crop[0] = 16 sprite_crop[1] = 0 elif (i == cols) and (j == 0): sprite_crop[0] = 32 sprite_crop[1] = 0 elif (i == cols) and (j < rows): sprite_crop[0] = 32 sprite_crop[1] = 16 elif (i == 0) and (j < rows): sprite_crop[0] = 0 sprite_crop[1] = 16 elif (i == 0) and (j == rows): sprite_crop[0] = 0 sprite_crop[1] = 32 elif (i < cols) and (j == rows): sprite_crop[0] = 16 sprite_crop[1] = 32 elif (i == cols) and (j == rows): sprite_crop[0] = 32 sprite_crop[1] = 32 else: sprite_crop[0] = 16 sprite_crop[1] = 16 rect = SDL_Rect((16 * i), (16 * j)) tile = subsurface(self.border_sprite_sheet, sprite_crop) SDL_BlitSurface(tile, None, surface, rect) return surface
def get_surface(self, frame, motion_type, facing): self.frame = frame self.motion_type = motion_type self.facing = facing w, h = self.sprite_size crop = (w * self.frame, 0, w, h) self.sprite_surface = subsurface(self.images[self.motion_type], crop) return self.sprite_surface
def get_surface(self, frame, motion_type, facing): self.frame = frame self.motion_type = motion_type self.facing = facing crop = self.frame * self.sprite_size[0], \ self.facing * self.sprite_size[1] + self.surface_height * self.motion_type, \ self.sprite_size[0], self.sprite_size[1] self.sprite_surface = subsurface(self.surface.contents, crop) return self.sprite_surface