import pygame.gfxdraw import colors from drawable import * from portal import * def player(screen, offset, size): """ Draw the player as a white circle in the middle of the screen. """ rect = Vector(*screen.get_rect()[2:]) pygame.gfxdraw.aacircle(screen, *round(rect / 2), size // 2, colors.WHITE) pygame.gfxdraw.filled_circle(screen, *round(rect / 2), size // 2, colors.WHITE) def world(screen, wrld, offset, depth): """ Draw all objects in 'wrld' in the right order with their shadows and portal worlds to the maximum recursion-'depth'. """ # put all objects in a tuple with their distance to be sortable dists = [] for object in wrld: dists.append((object.dist_to(offset), object)) # draw the furtheset object first for object in reversed(sorted(dists)): if isinstance(object[1], drawable): # draw order: shadow, portal world, object object[1].draw_shadow(screen, offset, offset) if depth > 0 and type(object[1]) is Portal: world(screen, object[1].portal_world(wrld, offset), offset, depth - 1) object[1].draw(screen, offset) else: raise TypeError(f"draw_world() expected drawable objects, but '{object.__class__.__name__}' found") def debug(screen, y, info, color): """ Draw debug information 'info' to the top right corner. 'y' is the textline and 'color' the color. """ # binary representation of some chars chars = { '': [0b10101010, 0b01010101, 0b10101010, 0b01010101, 0b10101010, 0b01010101], '0': [0b00111110, 0b01000101, 0b01001001, 0b01010001, 0b00111110, 0b00000000], '1': [0b01000000, 0b01000000, 0b01111111, 0b01000010, 0b01000000, 0b00000000], '2': [0b01000110, 0b01001001, 0b01001001, 0b01010001, 0b01100010, 0b00000000], '3': [0b00110110, 0b01001001, 0b01001001, 0b01000001, 0b00100010, 0b00000000], '4': [0b01111111, 0b00010001, 0b00010010, 0b00010100, 0b00011000, 0b00000000], '5': [0b00111001, 0b01000101, 0b01000101, 0b01000101, 0b00100111, 0b00000000], '6': [0b00110000, 0b01001001, 0b01001001, 0b01001010, 0b00111100, 0b00000000], '7': [0b00000111, 0b00001001, 0b01110001, 0b00000001, 0b00000011, 0b00000000], '8': [0b00110110, 0b01001001, 0b01001001, 0b01001001, 0b00110110, 0b00000000], '9': [0b00011110, 0b00101001, 0b01001001, 0b01001001, 0b00000110, 0b00000000], '.': [0b01100000, 0b00000000], ',': [0b11100000, 0b00000000], '+': [0b00001000, 0b00001000, 0b00111110, 0b00001000, 0b00001000, 0b00000000], '-': [0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000000], ' ': [0b00000000, 0b00000000, 0b00000000], 'F': [0b00000001, 0b00001001, 0b00001001, 0b00001001, 0b01111111, 0b00000000], 'P': [0b00000110, 0b00001001, 0b00001001, 0b00001001, 0b01111111, 0b00000000], 'S': [0b00110001, 0b01001001, 0b01001001, 0b01001001, 0b01000110, 0b00000000], 'X': [0b01100011, 0b00010100, 0b00001000, 0b00010100, 0b01100011, 0b00000000], 'Y': [0b00000011, 0b00000100, 0b01111000, 0b00000100, 0b00000011, 0b00000000], } pos = screen.get_rect()[2] - 4 for char in reversed(str(info)): for line in chars.get(char, chars.get(char.upper(), chars[''])): for i in range(8): if line >> i & 0b1: pygame.gfxdraw.pixel(screen, pos, i+3 + 10*y, color) pos -= 1