#
# modified from Hoop library - Game Programming With Python, Sean Riley
#

#from __future__ import division
import math, pygame, ui, copy, vect, constants, simobject
from numpy import *

class GridSquare(object):
    """ The object that makes up the grid.
    I contain sims, for collision detection
    I hold information about which sims might see me, and are currently viewing me
    """
    def __init__(self, grid, X, Y, width, height):
        self.grid = grid
        self.posX = X
        self.posY = Y
        self.location = X+0.5*width, Y+0.5*height
        #self.location = posX, posY
        self.grid_location = ( int(X/width), int(Y/height) )
        self.width = width
        self.height = height
        ## I can block movement
        self.blocked = False
        ##I can block sight
        self.opaque = False

        ## I contain these sims
        self.sims = set()
        ## how sims see me
        ## these sims might see me, I am within their sight range
        self.sims_sighting_tile = set()
        ##these sims definitely see me
        self.sims_viewing_tile = set()

        ## find adjacent grid_coordinates"""
        ## might want to run this code after entire grid made, and reference squares directly as optimisation...?"""
        self.find_adjacent_squares()
        self.find_face_squares()

        """ sprite image, can be None, or something like fog, or background.
        Pattern is 0-997 are "game sims" in drawing layers.
        998 is fog like things; shadow, unexplored
        999 is memorised immotive sims, like corpses, blocks, etc
        1000 is UI text, so you wont find it in here
        """
        self.images = set()
        self.fog = None

    def find_adjacent_squares(self):
        """ finds 8 adjacent squares """
        self.adjacent_squares = set()

        for offset in self.grid.translation_offsets:
            x,y = self.grid_location[0] + offset[0], self.grid_location[1] + offset[1]
            if x < 0 or y < 0 or x >= self.grid.numSquaresX or y >= self.grid.numSquaresY:
                continue
            else:
                self.adjacent_squares.add((x,y))

    def find_face_squares(self):
        """ finds adjacent face-face squares (max 4 in 2D)"""
        self.face_squares = set()

        for offset in self.grid.face_offsets:
            x,y = self.grid_location[0] + offset[0], self.grid_location[1] + offset[1]
            if x < 0 or y < 0 or x >= self.grid.numSquaresX or y >= self.grid.numSquaresY:
                continue
            else:
                self.face_squares.add((x,y))

    def add_sim(self, sim):
        """ adds a sim to me """
        self.sims.add(sim)
        if sim.block:
            self.blocked = True
        if sim.opaque:
            self.opaque = True
            for other_sim in self.sims_sighting_tile:
                other_sim.opaque_tiles.add(self.grid_location)
        """ shows the new sim I contain to sims viewing me """
        for other_sim in self.sims_viewing_tile.copy():
            other_sim.visible_sims.add(sim)
            self.grid.start_rendering(sim, other_sim.avatar)
            if self.opaque:
                self.grid.check_sims_tile_visibility(other_sim)

    def remove_sim(self, sim):
        """ removes a sim from me, try statement as it is possible for two sims to try to remove one object from me, eg ammo """
        if sim in self.sims:
            self.sims.remove(sim)
            if sim.block:
                self.blocked = False
            if sim.opaque:
                temp_viewers = self.sims_viewing_tile.copy()
                self.opaque = False
                for other_sim in temp_viewers:
                    if sim in other_sim.visible_sims:
                        other_sim.visible_sims.remove(sim)
                        self.grid.stop_rendering(sim, other_sim.avatar)
                    if self.grid_location in other_sim.opaque_tiles:
                        other_sim.opaque_tiles.remove(self.grid_location)
                        # should this be indented like below?
                        self.grid.check_sims_tile_visibility(other_sim)
                for other_sim in self.sims_sighting_tile.difference(temp_viewers):
                    if self.grid_location in other_sim.opaque_tiles:
                        other_sim.opaque_tiles.remove(self.grid_location)
                    # if we indent this then block arent viewed proerply sometimes, although it should be...
                    self.grid.check_sims_tile_visibility(other_sim)
            else:
                for other_sim in self.sims_viewing_tile:
                    if sim in other_sim.visible_sims:
                        other_sim.visible_sims.remove(sim)
                        self.grid.stop_rendering(sim, other_sim.avatar)

    def add_sim_viewing_tile(self, sim):
        self.sims_viewing_tile.add(sim)
        self.update_tile_in_sim_memory(sim)
        if self.grid_location not in sim.memorised_tiles:
            sim.memorised_tiles.add(self.grid_location)
        for other_sim in self.sims:
            sim.visible_sims.add(other_sim)
            self.grid.start_rendering(other_sim, sim.avatar)

    def remove_sim_viewing_tile(self, sim):
        self.sims_viewing_tile.remove(sim)
        for other_sim in self.sims:
            # add an immobile sim to memory of sim
            if not other_sim.motive:
                self.add_tile_to_sim_memory(sim, other_sim)
            if other_sim in sim.visible_sims:
                sim.visible_sims.remove(other_sim)
                self.grid.stop_rendering(other_sim, sim.avatar)
        if sim.avatar and self.fog == None:
            self.fog = sim.world.grid.draw_image(sim.world, self.location, "fog_image")


    def update_tile_in_sim_memory(self, sim):
        sim.memory[self.grid_location] = set()
        if sim.avatar:
            for image in self.images:
                image.kill()
            if self.fog:
                self.fog.kill()
                self.fog = None


    def add_tile_to_sim_memory(self, sim, other_sim):
        """ adds other_sim info to sim memory and if necessary
        the GridSquares image list
        """
        sim.memory[self.grid_location].add(other_sim.sim_type)
        if sim.avatar:
            ## can store many images
            self.images.add(sim.world.grid.draw_image(sim.world, other_sim.location, "mem_"+other_sim.sim_type+"_image", other_sim.direction))



class GridSuperSquare(GridSquare):
    def __init__(self, grid, X, Y, width, height):
        GridSquare.__init__(self, grid, X, Y, width, height)

    def find_adjacent_squares(self):
        """ finds 8 adjacent squares """
        self.adjacent_squares = set()

        for offset in self.grid.translation_offsets:
            x,y = self.grid_location[0] + offset[0], self.grid_location[1] + offset[1]
            if x < -1 or y < -1 or x >= self.grid.numSquaresX+1 or y >= self.grid.numSquaresY+1:
                continue
            else:
                self.adjacent_squares.add((x,y))

    def find_face_squares(self):
        """ finds adjacent face-face squares (max 4 in 2D)"""
        self.face_squares = set()

        for offset in self.grid.face_offsets:
            x,y = self.grid_location[0] + offset[0], self.grid_location[1] + offset[1]
            if x < -1 or y < -1 or x >= self.grid.numSquaresX+1 or y >= self.grid.numSquaresY+1:
                continue
            else:
                self.face_squares.add((x,y))


class LOS_mask:
    def __init__(self, radius):
        """ makes a circular line of sight marks of Radius "radius" """
        self.radius = radius
        self.tile_offsets = set()
        radius_sqd = radius**2
        for x in xrange( -radius, radius+1):
            for y in xrange( -radius, radius+1):
                if x**2+y**2 < radius_sqd:
                    self.tile_offsets.add((x,y))

class LOS_Dmask:
    def __init__(self, Grid, radius, offset):
        """ creates a dicitonary of "add tiles" and "remove tiles" applied to the view map when a sim changes square """
        self.tile_changes = {}
        """ need to copy mask or else will edit mask """
        self.old_mask_tiles = Grid.LOS_masks[radius].tile_offsets
        self.new_mask_tiles = set()
        for old_tile in self.old_mask_tiles:
            new_tile = (old_tile[0]+offset[0],old_tile[1]+offset[1])
            self.new_mask_tiles.add(new_tile)
        """ need to make a temp copy or else this for loop will end prematurely due to some stupid random logic about the length of the loop """
        self.tile_changes[-1] = self.old_mask_tiles.difference(self.new_mask_tiles)
        self.tile_changes[1] = self.new_mask_tiles.difference(self.old_mask_tiles)

class Shadow_map:
    """ creates a list of "shadowed tiles" applied to the view map when a sim changes square """
    def __init__(self, Grid, radius, offset):
        self.tile_offsets = set()

        dx = Grid.square_width/2.0
        dy = Grid.square_height/2.0

        lines = set()
        angles = set()

        for delta in ((dx,dy),(dx,-dy),(-dx,dy),(-dx,-dy)):
            lines.add((offset[0]+delta[0],offset[1]+delta[1]))

        angle = math.atan2(offset[1],offset[0])

        if angle > math.pi/2.0 or angle < -math.pi/2.0:
            for line in lines:
                angles.add(vect.NRT_angle_to((line[1], line[0])))
        else:
            for line in lines:
                angles.add(math.atan2(line[1], line[0]))

        min_angle = min(angles)
        max_angle = max(angles)

        r_min_sq = offset[0]**2+offset[1]**2
        r_max_sq = radius**2

        for tile in Grid.LOS_masks[radius].tile_offsets:
            x,y = tile[1], tile[0]
            r_sq = x**2 + y**2
            if r_min_sq <= r_sq and r_sq <= r_max_sq:
                if angle > math.pi/2.0 or angle < -math.pi/2.0:
                    tile_angle = vect.NRT_angle_to((x,y))
                else:
                    tile_angle = math.atan2(x, y)
                if min_angle <= tile_angle and tile_angle <= max_angle:
                    self.tile_offsets.add(tile)

class Grid:
    """ grid that stores sims"""
    def __init__(self, width, height, ratio):
        self.width = width
        self.height = height
        self.square_width = width / ratio
        self.square_height = height / ratio
        self.numSquaresX = int(width / self.square_width)
        self.numSquaresY = int(height / self.square_height)
        self.squares = ndarray((self.numSquaresX, self.numSquaresY), dtype=GridSquare) # dictionary of grid squares by location
        self.LOS_masks = {} # dictionary of line of sight masks by radii
        self.translation_offsets = set() # set of translation offsets used for precomputing changes in LOS masks.
        self.LOS_Dmasks = {} # dictionary of additions and deletions by radii for LOS mask movement
        self.shadow_maps = {} # dictionary of shadows cast objects, by radii and object offset
        self.face_offsets = [(-1,0),(0,-1),(1,0),(0,1)]

        self.super_set_squares = ndarray((self.numSquaresX+2, self.numSquaresY+2), dtype=GridSuperSquare)

        """ creates 8-way translations from (0,0) which can be used to offset LOS_masks from each other to find LOS_dmasks """
        for x in xrange(-1,2):
            for y in xrange(-1,2):
                self.translation_offsets.add((x,y))
        self.translation_offsets.remove((0,0))
        """ [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] """

        """ creates the squares in the grid """
        for y in range(0,self.numSquaresY+0):
            for x in range(0,self.numSquaresX+0):
                self.squares[ (x,y) ] = GridSquare(self, x*self.square_width,y*self.square_height,self.square_width, self.square_height)

        """ creates the squares in the super_grid """
        for y in range(-1,self.numSquaresY+1):
            for x in range(-1,self.numSquaresX+1):
                self.super_set_squares[ (x,y) ] = GridSuperSquare(self, x*self.square_width,y*self.square_height,self.square_width, self.square_height)

        """ creates LOS_masks for radii 15 and 25. This could be automated by making xrange(15,26)
        but most wont be needed in current game design, so this is an optimisation - suspect will change this when I add variable lighting"""
        radii = set()
        for radius in constants.SIGHT_RADII:
            radii.add(int(radius/self.square_width))
        for radius in radii:
            self.LOS_masks[ radius ] = LOS_mask(radius)

        """ creates delta masks for LOS_masks and offsets """
        for radius in self.LOS_masks.keys():
            self.LOS_Dmasks[radius] = {}
            for offset in self.translation_offsets:
                self.LOS_Dmasks[radius][offset] = LOS_Dmask(self, radius, offset)

        """ creates shadow maps for LOS_masks and offsets """
        for radius in self.LOS_masks.keys():
            self.shadow_maps[radius] = {}
            for offset in self.LOS_masks[ radius ].tile_offsets:
                self.shadow_maps[radius][offset] = Shadow_map(self, radius, offset)

    def check_square_in_grid(self, grid_ref):
        x,y = grid_ref
        if x < 0 or y < 0 or x >= self.numSquaresX or y >= self.numSquaresY:
            return None
        else:
            return (x,y)

    def add_sim(self, sim):
        sim.check_world_boundary()
        x,y = sim.location
        grid_location = int(x/self.square_width), int(y/self.square_height)
        #self.check_grid_location_in_grid(grid_location)

        sim.grid_location = grid_location

        """ cleans the memory of map from avatar sim """
        if sim.avatar:
            for other_sim in sim.world.spriteGroups[-1]:
                if other_sim == sim:
                    pass
                else:
                    self.stop_rendering(other_sim)
            sim.unexplored_tiles = ndindex(self.squares.shape)
            for key in sim.unexplored_tiles:
                location = key[0]+self.square_width/2, key[1]+self.square_height/2
                self.squares[key].images.add(sim.world.grid.draw_image(sim.world, location, "shadow_image"))

        if sim.sight_radius > 0:
            self.apply_LOS_mask(sim)
            self.check_sims_tile_visibility(sim)

        square = self.squares[grid_location]
        square.add_sim(sim)

        """ shows all sims to player if avatar dies """
        if sim.world.player is None:
            self.start_rendering(sim)
        else:
            if sim.world.player.health < 0:
                self.start_rendering(sim)

    def remove_sim(self, sim):
        if sim.grid_location:
            square = self.squares[sim.grid_location]
            square.remove_sim(sim)
            sim.grid_location = None

    def check_grid_location_in_grid(self, new_grid_ref):
        x,y = new_grid_ref
        if 0 <= x < self.numSquaresX:
            if 0 <= y < self.numSquaresY:
                return new_grid_ref


    def moveSim(self, sim):
        """ this moves the sim from one square to the next """
        if sim.grid_location:
            #sim.check_world_boundary()
            X,Y = sim.location
            new_grid_location = ( int(X/self.square_width), int(Y/self.square_height) )
            in_grid = self.check_grid_location_in_grid(new_grid_location)
            if new_grid_location != sim.grid_location and in_grid:
                translation = new_grid_location[0] - sim.grid_location[0], new_grid_location[1] - sim.grid_location[1]

                old_square= self.squares[sim.grid_location]
                old_square.remove_sim(sim)

                if sim.sight_radius > 0:
                    if sim.health >= 0:
                    # an explosion can push a sim really fast
                    #FIX
                        if translation[0]**2+translation[1]**2 <= 2:
                            self.move_LOS_mask(sim, translation)
                        else:
                            sim.health = -1

                if sim.health >= 0:
                    sim.grid_location = new_grid_location

                    new_square = self.squares[new_grid_location]
                    new_square.add_sim(sim)

                    if sim.sight_radius > 0:
                            self.check_sims_tile_visibility(sim)

    def draw_local_collision_grid(self,sim,(x,y)):
        bottom_left = ui.screen_pos(sim.world, (x*self.square_width,y*self.square_height))
        top_right = ui.screen_pos(sim.world, ((x+1)*self.square_width,(y+1)*self.square_height))
        pygame.draw.line(sim.world.screen, (0,0,0), bottom_left, top_right, 2)

    def apply_LOS_mask(self, sim):
        """ applies a LOS mask to a sim to find the maximum set of tiles a sim can see """
        """ note it does not apply shadow casting - it is used to find the tiles that can cast shadows """
        """ each tile returned by this will store the sim in its self.sims_sighting_tile list """
        radius = int(sim.sight_radius/self.square_width)
        mask = self.LOS_masks[radius]
        for tile_offset in mask.tile_offsets:
            self.add_sight_tile(sim, tile_offset)

    def move_LOS_mask(self, sim, translation):
        radius = int(sim.sight_radius/self.square_width)
        mask = self.LOS_Dmasks[radius][translation]
        for tile_offset in mask.tile_changes[-1]:
            self.remove_sight_tile(sim, tile_offset)
        for tile_offset in mask.tile_changes[1]:
            self.add_sight_tile(sim, tile_offset)

    def remove_sim_tiles(self, sim):
        """ this empties out the sims tiles of all sim data when the sim dies """
        sim.opaque_tiles = set()
        for tile in sim.sight_tiles:
            self.squares[tile].sims_sighting_tile.remove(sim)
        sim.sight_tiles = set()
        for tile in sim.visible_tiles:
            self.squares[tile].sims_viewing_tile.remove(sim)
        sim.visible_tiles = set()
        sim.visible_sims = set()
        sim.shadowed_tiles = set()
        sim.memorised_tiles = set()
        sim.unexplored_tiles = set()
        sim.memory = {}
        sim.fogged_tiles = set()
        if sim.avatar:
            for other_sim in sim.world.spriteGroups[-1]:
                self.start_rendering(other_sim)
            for i in xrange(997,1000):
                sim.world.spriteGroups[i].empty()
            sim.world.spriteGroups[-2].empty()


    def add_sight_tile(self, sim, tile_offset):
        x,y = sim.grid_location[0]+tile_offset[0],sim.grid_location[1]+tile_offset[1]
        tile = self.check_square_in_grid((x,y))
        if tile is not None:
            sim.sight_tiles.add(tile)
            square = self.squares[tile]
            if square.opaque:
                sim.opaque_tiles.add(tile)
            square.sims_sighting_tile.add(sim)

    def remove_sight_tile(self, sim, tile_offset):
        x,y = sim.grid_location[0]+tile_offset[0],sim.grid_location[1]+tile_offset[1]
        tile = self.check_square_in_grid((x,y))
        if tile in sim.sight_tiles:
            sim.sight_tiles.remove(tile)
            square = self.squares[tile]
            if square.opaque:
                sim.opaque_tiles.remove(tile)
            square.sims_sighting_tile.remove(sim)

    def add_visible_tile(self, sim, tile):
        sim.visible_tiles.add(tile)
        square = self.squares[tile]
        square.add_sim_viewing_tile(sim)

    def remove_visible_tile(self, sim, tile):
        if tile in sim.visible_tiles:
            sim.visible_tiles.remove(tile)
        square = self.squares[tile]
        square.remove_sim_viewing_tile(sim)

    def find_shadowed_tiles(self, sim):
        """ Finds the set of blocking objects, and applies shadows from them.
        """
        shadows = set()
        radius = sim.sight_radius
        location = sim.grid_location
        potential_draw_list = set()
        #FIX
        for tile in sim.opaque_tiles:
            # we do not want the tile we are in to create a shadow
            # or else shrubs block sight in a nonsensical way
            if tile != location:
            # find if tile is in shadow
                if sim.world.slow_precise_shadowing:
                    # we shadow every block in range for preciseness
                    partial_shadow = self.shadowcast(sim, tile)
                    if partial_shadow is not None:
                        shadows = shadows.union(partial_shadow)
                        potential_draw_list.add(tile)
                else:
                    # we cull "non face visible" tiles for speed, but this can cull too many...
                    if self.face_visibility(sim, tile, shadows):
                        # this is not yet in shadow, so lets shadow it
                        partial_shadow = self.shadowcast(sim, tile)
                        if partial_shadow is not None:
                            shadows = shadows.union(partial_shadow)
                            potential_draw_list.add(tile)

        temp_shadows = shadows.copy()
        for tile in potential_draw_list:
            if self.face_visibility(sim, tile, temp_shadows):
                # lets remove this tile from the shadow list as it is visible
                shadows.difference_update([tile])
                # we need this code to show blocks when they are added to a currently seen square.
                sim_list = self.squares[tile].sims
                for other_sim in sim_list:
                    if other_sim in sim.visible_sims:
                        pass
                    else:
                        sim.visible_sims.add(other_sim)
                        self.start_rendering(other_sim, sim.avatar)

        return shadows

    def face_visibility(self, sim, tile, shadows):
        """ Determines if any of the faces of a shadowed "block" square are visible.
        """
        visible = False
        sight_tiles = sim.sight_tiles
        shadow_set = shadows
        face_tiles = self.squares[tile].face_squares
        for face_tile in face_tiles:
            if face_tile in sight_tiles:
                if face_tile not in shadow_set:
                    if not self.squares[face_tile].opaque:
                        visible = True
        return visible

    def shadowcast(self, sim, tile):
        """ Applies a shadow from a blocking object.

        Does not apply shadows outside of grid
        """
        shadow_set = set()
        gx,gy = sim.grid_location
        offset = tile[0] - gx, tile[1] - gy
        shadow = self.shadow_maps[sim.sight_radius][offset].tile_offsets
        for tile in shadow:
            grid_ref = gx+tile[0], gy+tile[1]
            checked_tile = self.check_square_in_grid(grid_ref)
            if checked_tile is not None:
                shadow_set.add(checked_tile)
        return shadow_set

    def check_sims_tile_visibility(self, sim):

        old_visible_tiles = sim.visible_tiles.copy()

        if sim.avatar:
            old_shadowed_tiles = sim.shadowed_tiles.copy()

        adj_squares = self.squares[sim.grid_location].adjacent_squares
        current_location = set()
        current_location.add(tuple(sim.grid_location))
        surrounding_tiles = adj_squares.union(current_location)

        sim.shadowed_tiles = self.find_shadowed_tiles(sim).difference(surrounding_tiles)

        sim.visible_tiles = (sim.sight_tiles.difference(sim.shadowed_tiles))

        remove_visible_tiles = old_visible_tiles.difference(sim.visible_tiles)
        add_visible_tiles = sim.visible_tiles.difference(old_visible_tiles)

        if sim.avatar:
            remove_shadowed_tiles = (old_shadowed_tiles.difference(sim.shadowed_tiles)).intersection(sim.sight_tiles)
            add_shadowed_tiles = sim.shadowed_tiles.difference(old_shadowed_tiles)

            for tile in remove_shadowed_tiles:
                square = self.squares[tile]
                square.fog.kill()
                square.fog = None

            for tile in add_shadowed_tiles:
                square = self.squares[tile]
                if not square.fog:
                    location = tile[0]+self.square_width/2, tile[1]+self.square_height/2
                    square.fog = self.draw_image(sim.world, location, "fog_image")

        for tile in add_visible_tiles:
            self.add_visible_tile(sim, tile)

        for tile in remove_visible_tiles:
            self.remove_visible_tile(sim, tile)

    def draw_image(self, world, location, image_string, direction=0):
        #location = (grid_ref[0]+0.5)*self.square_width, (grid_ref[1]+0.5)*self.square_height
        image = simobject.Image(world, location, image_string, direction)
        return image

    def start_rendering(self, sim, boolean = True):
        if boolean:
            #sim.world.spriteGroups[sim.elevation].add(sim)
            sim.grid_viewed = True
            #sim.drawn = True

    def stop_rendering(self, sim, boolean = True):
        if boolean:
            #sim.world.spriteGroups[sim.elevation].remove(sim)
            sim.grid_viewed = False
            #sim.drawn = False

    def check_collision_grid(self, sim):
        """ 87 mus """
        """ check the collision for a sim in world space through local and adjacent squares. """
        if sim.grid_location:
            sim.collide_group = self.squares[sim.grid_location].sims
            """ iterate through local and adjacent squares """
            list = self.squares[sim.grid_location].adjacent_squares
            for location in list:
                sim.collide_group = sim.collide_group.union(self.squares[location].sims)
                #if sim.world.draw_sprite_paths:
                    #self.draw_local_collision_grid(sim,location)

    def draw_rect(self, world, grid_ref, color):
        extension = 0
        x,y = grid_ref[0]*self.square_width, (grid_ref[1]+1)*self.square_height
        position = ui.screen_pos(world, (x,y))
        if -constants.WORLD_PPM <= position[0] <= world.screen_width and -constants.WORLD_PPM <= position[1] <= world.screen_height:
            position = int(position[0])-extension,int(position[1])+extension
            size = int(math.ceil(self.square_width*world.PPM*world.scale))+extension, int(math.ceil(self.square_height*world.PPM*world.scale)+extension)
            pygame.draw.rect(world.screen, color, (position,size),0)

#===============================================================================
#
#    def draw_player_shadowed_tiles(self,world):
#        """ (square[1]+1) because things are drawn from the top top left, but my coords are bottom left """
#        color = (0,0,0)
#        for grid_ref in world.player.shadowed_tiles:
#            #self.draw_rect(world, grid_ref, color)
#            #self.draw_fog(world, grid_ref)
#            pass
#
#    def draw_player_memorised_tiles(self,world):
#        """ (square[1]+1) because things are drawn from the top top left, but my coords are bottom left """
#        for grid_ref in world.player.memorised_tiles:
#            x,y = grid_ref [0]*self.square_width, (grid_ref [1])*self.square_height
#            corner1 = ui.screen_pos(world, (x*self.square_width,(y+1)*self.square_height))
#            corner2 = ui.screen_pos(world, ((x+1)*self.square_width,(y)*self.square_height))
#            pygame.draw.line(world.screen, (200,200,200), corner1,corner2,1)
#
#    def draw_player_opaque_tiles(self,world):
#        """ (square[1]+1) because things are drawn from the top top left, but my coords are bottom left """
#        color = (255,0,0)
#        for grid_ref  in world.player.opaque_tiles:
#            self.draw_rect(world, grid_ref, color)
#
#    def draw_player_memory(self,world):
#        """ (square[1]+1) because things are drawn from the top top left, but my coords are bottom left """
#        memory = world.player.memory
#        color_dict = {}
#        color_dict["ammo"] = (255,255,0)
#        color_dict["medkit"] = (255,255,255)
#        color_dict["concrete_block"] = (70,70,70)
#        color_dict["zombie_hive"] = (211,25,176)
#        color_dict["Pistol"] = (11,118,213)
#        color_dict["SMG"] = color_dict["Pistol"]
#        color_dict["AssaultR"] = color_dict["Pistol"]
#        color_dict["SniperR"] = color_dict["Pistol"]
#        color_dict["LaserR"] = color_dict["Pistol"]
#
#        for grid_ref in memory.keys():
#            if memory[grid_ref] in color_dict.keys():
#                color = color_dict[memory[grid_ref]]
#                self.draw_rect(world, grid_ref, color)
#
#    def draw_player_fogged_tiles(self,world):
#        """ (square[1]+1) because things are drawn from the top top left, but my coords are bottom left """
#        color = (100,100,100)
#        for grid_ref in world.player.fogged_tiles:
#            self.draw_rect(world, grid_ref, color)
#
#    def draw_player_unexplored_tiles(self,world):
#        """ (square[1]+1) because things are drawn from the top top left, but my coords are bottom left """
#        color = (0,0,0)
#        for grid_ref in world.player.unexplored_tiles:
#            self.draw_rect(world, grid_ref, color)
#
#    def draw_player_tiles(self, world):
#        if world.player:
#            self.draw_player_shadowed_tiles(world)
#
#            self.draw_player_unexplored_tiles(world)
#
#            if world.draw_sprite_paths == 1:
#                #self.draw_player_fogged_tiles(world)
#                #self.draw_player_opaque_tiles(world)
#
#            self.draw_player_memory(world)
#
#===============================================================================
