7 # Dictionary that stores the unicode character representations of the different pieces
8 # Chess was clearly the reason why unicode was invented
9 # For some reason none of the pygame chess implementations I found used them!
10 piece_char = {"white" : {"king" : u'\u2654',
17 "black" : {"king" : u'\u265A',
25 images = {"white" : {}, "black" : {}}
26 small_images = {"white" : {}, "black" : {}}
28 def create_images(grid_sz, font_name=os.path.join(os.path.curdir, "data", "DejaVuSans.ttf")):
31 l_size = 5*(grid_sz[0] / 8)
32 s_size = 3*(grid_sz[0] / 8)
34 for c in piece_char.keys():
37 for p in piece_char[c].keys():
38 images[c].update({p : pygame.font.Font(font_name, l_size).render(piece_char[c][p], True,(0,0,0))})
39 small_images[c].update({p : pygame.font.Font(font_name, s_size).render(piece_char[c][p],True,(0,0,0))})
41 for p in piece_char[c].keys():
42 images[c].update({p : pygame.font.Font(font_name, l_size+1).render(piece_char["black"][p], True,(255,255,255))})
43 images[c][p].blit(pygame.font.Font(font_name, l_size).render(piece_char[c][p], True,(0,0,0)),(0,0))
44 small_images[c].update({p : pygame.font.Font(font_name, s_size+1).render(piece_char["black"][p],True,(255,255,255))})
45 small_images[c][p].blit(pygame.font.Font(font_name, s_size).render(piece_char[c][p],True,(0,0,0)),(0,0))
48 def load_images(image_dir=os.path.join(os.path.curdir, "data", "images")):
49 if not os.path.exists(image_dir):
50 raise Exception("Couldn't load images from " + image_dir + " (path doesn't exist)")
51 for c in piece_char.keys():
52 for p in piece_char[c].keys():
53 images[c].update({p : pygame.image.load(os.path.join(image_dir, c + "_" + p + ".png"))})
54 small_images[c].update({p : pygame.image.load(os.path.join(image_dir, c + "_" + p + "_small.png"))})