Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung | |||
ss20:neg_utility [2020/09/11 14:28] srather [generate] |
ss20:neg_utility [2020/09/11 14:28] (aktuell) srather [draw] |
||
---|---|---|---|
Zeile 164: | Zeile 164: | ||
from portal import * | from portal import * | ||
- | def player(screen, offset, player): | + | |
+ | def player(screen, offset, size): | ||
+ | """ | ||
+ | Draw the player as a white circle in the middle of the screen. | ||
+ | """ | ||
rect = Vector(*screen.get_rect()[2:]) | rect = Vector(*screen.get_rect()[2:]) | ||
- | # pygame.draw.aaline(screen, colors.BRIGHT_RED, round((rect + Vector(player, player)) / 2 - offset), round((rect - Vector(player, player)) / 2 - offset)) | + | pygame.gfxdraw.aacircle(screen, *round(rect / 2), size // 2, colors.WHITE) |
- | # pygame.draw.aaline(screen, colors.BRIGHT_RED, round((rect + Vector(player, -player)) / 2 - offset), round((rect - Vector(player, -player)) / 2 - offset)) | + | pygame.gfxdraw.filled_circle(screen, *round(rect / 2), size // 2, colors.WHITE) |
- | pygame.gfxdraw.aacircle(screen, *round(rect / 2), player // 2, colors.WHITE) | + | |
- | pygame.gfxdraw.filled_circle(screen, *round(rect / 2), player // 2, colors.WHITE) | + | |
- | def world(screen, wrld, offset, depth, M=Matrix((1,0),(0,1))): | + | 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 = [] | dists = [] | ||
for object in wrld: | for object in wrld: | ||
dists.append((object.dist_to(offset), object)) | dists.append((object.dist_to(offset), object)) | ||
+ | # draw the furtheset object first | ||
for object in reversed(sorted(dists)): | for object in reversed(sorted(dists)): | ||
if isinstance(object[1], drawable): | if isinstance(object[1], drawable): | ||
+ | # draw order: shadow, portal world, object | ||
object[1].draw_shadow(screen, offset, offset) | object[1].draw_shadow(screen, offset, offset) | ||
if depth > 0 and type(object[1]) is Portal: | if depth > 0 and type(object[1]) is Portal: | ||
Zeile 187: | Zeile 198: | ||
- | chars = { | + | def debug(screen, y, info, color): |
- | '': [0b10101010, 0b01010101, 0b10101010, 0b01010101, 0b10101010, 0b01010101], | + | """ |
- | '0': [0b00111110, 0b01000101, 0b01001001, 0b01010001, 0b00111110, 0b00000000], | + | Draw debug information 'info' to the top right corner. |
- | '1': [0b01000000, 0b01000000, 0b01111111, 0b01000010, 0b01000000, 0b00000000], | + | 'y' is the textline and 'color' the color. |
- | '2': [0b01000110, 0b01001001, 0b01001001, 0b01010001, 0b01100010, 0b00000000], | + | """ |
- | '3': [0b00110110, 0b01001001, 0b01001001, 0b01000001, 0b00100010, 0b00000000], | + | |
- | '4': [0b01111111, 0b00010001, 0b00010010, 0b00010100, 0b00011000, 0b00000000], | + | # binary representation of some chars |
- | '5': [0b00111001, 0b01000101, 0b01000101, 0b01000101, 0b00100111, 0b00000000], | + | chars = { |
- | '6': [0b00110000, 0b01001001, 0b01001001, 0b01001010, 0b00111100, 0b00000000], | + | '': [0b10101010, 0b01010101, 0b10101010, 0b01010101, 0b10101010, 0b01010101], |
- | '7': [0b00000111, 0b00001001, 0b01110001, 0b00000001, 0b00000011, 0b00000000], | + | '0': [0b00111110, 0b01000101, 0b01001001, 0b01010001, 0b00111110, 0b00000000], |
- | '8': [0b00110110, 0b01001001, 0b01001001, 0b01001001, 0b00110110, 0b00000000], | + | '1': [0b01000000, 0b01000000, 0b01111111, 0b01000010, 0b01000000, 0b00000000], |
- | '9': [0b00011110, 0b00101001, 0b01001001, 0b01001001, 0b00000110, 0b00000000], | + | '2': [0b01000110, 0b01001001, 0b01001001, 0b01010001, 0b01100010, 0b00000000], |
- | '.': [0b01100000, 0b00000000], | + | '3': [0b00110110, 0b01001001, 0b01001001, 0b01000001, 0b00100010, 0b00000000], |
- | ',': [0b11100000, 0b00000000], | + | '4': [0b01111111, 0b00010001, 0b00010010, 0b00010100, 0b00011000, 0b00000000], |
- | '+': [0b00001000, 0b00001000, 0b00111110, 0b00001000, 0b00001000, 0b00000000], | + | '5': [0b00111001, 0b01000101, 0b01000101, 0b01000101, 0b00100111, 0b00000000], |
- | '-': [0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000000], | + | '6': [0b00110000, 0b01001001, 0b01001001, 0b01001010, 0b00111100, 0b00000000], |
- | ' ': [0b00000000, 0b00000000, 0b00000000], | + | '7': [0b00000111, 0b00001001, 0b01110001, 0b00000001, 0b00000011, 0b00000000], |
- | 'F': [0b00000001, 0b00001001, 0b00001001, 0b00001001, 0b01111111, 0b00000000], | + | '8': [0b00110110, 0b01001001, 0b01001001, 0b01001001, 0b00110110, 0b00000000], |
- | 'P': [0b00000110, 0b00001001, 0b00001001, 0b00001001, 0b01111111, 0b00000000], | + | '9': [0b00011110, 0b00101001, 0b01001001, 0b01001001, 0b00000110, 0b00000000], |
- | 'S': [0b00110001, 0b01001001, 0b01001001, 0b01001001, 0b01000110, 0b00000000], | + | '.': [0b01100000, 0b00000000], |
- | 'X': [0b01100011, 0b00010100, 0b00001000, 0b00010100, 0b01100011, 0b00000000], | + | ',': [0b11100000, 0b00000000], |
- | 'Y': [0b00000011, 0b00000100, 0b01111000, 0b00000100, 0b00000011, 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], | ||
+ | } | ||
- | def debug(screen, y, fps, color): | ||
pos = screen.get_rect()[2] - 4 | pos = screen.get_rect()[2] - 4 | ||
- | for char in reversed(str(fps)): | + | for char in reversed(str(info)): |
for line in chars.get(char, chars.get(char.upper(), chars[''])): | for line in chars.get(char, chars.get(char.upper(), chars[''])): | ||
for i in range(8): | for i in range(8): |