diff --git a/main.py b/main.py index 0e7a66b..722af6a 100644 --- a/main.py +++ b/main.py @@ -24,26 +24,12 @@ def draw_feld(feld,color_key,block_size): #print(feld) for a in range(len(feld[0])): for b in range(len(feld)): - #print(a,b) - if feld[b][a] == ".": - - print(".") - #pygame.gfxdraw.box(screen,pygame.Rect( - # a*block_size[0], - # b*block_size[1], - # (a+1)*(block_size[0]), - # (b+1)*(block_size[1])),(100,100,100)) - else: - #pygame.gfxdraw.box(screen,pygame.Rect( - # a*block_size[0], - # b*block_size[1], - # (a+1)*(block_size[0]), - # (b+1)*(block_size[1])),color_key[feld[b][a]]) + if feld[b][a] != " ": pygame.draw.rect(screen,color_key[feld[b][a]], (a*block_size[0], b*block_size[1], - (a+1)*(block_size[0]), - (b+1)*(block_size[1]))) + (block_size[0]), + (block_size[1]))) def get_block_size(): return 20,20 def get_meightboars(feld,position): @@ -58,8 +44,6 @@ def verarbeite_feld(feld): feld2 = copy.deepcopy(feld) for y in range(len(feld)): for x in range(len(feld[0])): - #x += 1 - pos = x,y poschar = feld[y][x] if poschar == "a": # uberprüfe unteren block @@ -67,25 +51,28 @@ def verarbeite_feld(feld): bellowr = feld2[(y+1)%feldy][(x+1)%feldx] bellowl = feld2[(y+1)%feldy][(x-1)%feldx] direction = random.choice([-1, 1]) # Zufällige Auswahl der Richtung - if bellow == "#": - break - if bellow == " ": + + if bellow == " " and not bellow == "#": feld2[y][x] = feld[(y+1)%feldy][x] feld2[(y+1)%feldy][x] = feld[y][x] - elif bellowr == " ": + elif bellowr == " " and not bellow == "#": feld2[y][x] = feld[(y+1)%feldy][(x+direction)%feldx] feld2[(y+1)%feldy][(x+direction)%feldx] = feld[y][x] - elif bellowl == " ": + elif bellowl == " " and not bellow == "#": feld2[y][x] = feld[(y+1)%feldy][(x+direction)%feldx] feld2[(y+1)%feldy][(x+direction)%feldx] = feld[y][x] return feld2 -def make_feld(size): +def make_feld(size,mode): x = screensize[0]//size y = screensize[1]//size - return [[" " for _ in range(x)] for _ in range(y)],x,y + feld = [[" " for _ in range(x)] for _ in range(y)] + if mode == "border": + for x in range(x): + feld[y-1][x] = "#" + return feld ,x,y ## klassen @@ -95,14 +82,15 @@ pygame.display.set_caption("SAND") screensize = pygame.display.get_window_size() clock = pygame.time.Clock() default_font = pygame.font.SysFont("sans", 14) -feld,feldx,feldy = make_feld(20) -feld[feldy-1][0] = "#" + +display_mode = "border" +feld,feldx,feldy = make_feld(20,display_mode) + acolor = (255,0,0) wechselfarbe = "r" using_element = "a" pixelsize = 20 -#display_mode = "durchfallen" show_debug = False running = True @@ -125,7 +113,7 @@ if __name__ == "__main__": else: using_element = "a" if pressed_keys[pygame.K_r] and not preview_pressed_keys[pygame.K_r]: - feld = make_feld(pixelsize) + feld,feldx,feldy = make_feld(pixelsize,display_mode) print("reset") preview_pressed_keys = pressed_keys @@ -135,7 +123,7 @@ if __name__ == "__main__": exit() if event.type == pygame.WINDOWRESIZED: screensize = pygame.display.get_window_size() - feld = make_feld(pixelsize) + feld,feldx,feldy = make_feld(pixelsize,display_mode) r,g,b = acolor if wechselfarbe == "r": r -= 1 @@ -153,8 +141,7 @@ if __name__ == "__main__": if b == 0: wechselfarbe = "r" acolor = r,g,b - color_key = {" ":(0,0,0), - "#":(100,100,100), + color_key = {"#":(100,100,100), "a":acolor} draw_feld(feld,color_key,(pixelsize,pixelsize)) mx,my = pygame.mouse.get_pos() @@ -170,4 +157,4 @@ if __name__ == "__main__": ## bildschirm aktuallisierung pygame.display.flip() clock.tick(30) - #screen.fill((100,0,0)) \ No newline at end of file + screen.fill((0,0,0)) \ No newline at end of file