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