mehr verbessert bug ist immernochd a

This commit is contained in:
Michael S. 2024-02-23 16:55:55 +01:00
parent ec8913b108
commit 1971b72419

25
main.py
View file

@ -26,10 +26,10 @@ def draw_feld(feld,color_key,block_size):
for b in range(len(feld)): for b in range(len(feld)):
if feld[b][a] != " ": if feld[b][a] != " ":
pygame.draw.rect(screen,color_key[feld[b][a]], pygame.draw.rect(screen,color_key[feld[b][a]],
(a*block_size[0], (a*block_size,
b*block_size[1], b*block_size,
(block_size[0]), block_size,
(block_size[1]))) block_size))
def get_block_size(): def get_block_size():
return 20,20 return 20,20
def get_meightboars(feld,position): def get_meightboars(feld,position):
@ -51,16 +51,15 @@ def verarbeite_feld(feld):
bellowr = feld2[(y+1)%feldy][(x+1)%feldx] bellowr = feld2[(y+1)%feldy][(x+1)%feldx]
bellowl = 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 direction = random.choice([-1, 1]) # Zufällige Auswahl der Richtung
if bellow == " " and not bellow == "#": if bellow == " " and not bellow == "#":
feld2[y][x] = feld[(y+1)%feldy][x] feld2[y][x] = feld[(y+1)%feldy][x]
feld2[(y+1)%feldy][x] = feld[y][x] feld2[(y+1)%feldy][x] = feld[y][x]
elif bellowr == " " and not bellow == "#": elif bellowr == " " and not bellowr == "#":
feld2[y][x] = feld[(y+1)%feldy][(x+direction)%feldx] feld2[y][x] = feld[(y+1)%feldy][(x+direction)%feldx]
feld2[(y+1)%feldy][(x+direction)%feldx] = feld[y][x] feld2[(y+1)%feldy][(x+direction)%feldx] = feld[y][x]
elif bellowl == " " and not bellow == "#": elif bellowl == " " and not bellowl == "#":
feld2[y][x] = feld[(y+1)%feldy][(x+direction)%feldx] feld2[y][x] = feld[(y+1)%feldy][(x+direction)%feldx]
feld2[(y+1)%feldy][(x+direction)%feldx] = feld[y][x] feld2[(y+1)%feldy][(x+direction)%feldx] = feld[y][x]
return feld2 return feld2
@ -91,7 +90,6 @@ wechselfarbe = "r"
using_element = "a" using_element = "a"
pixelsize = 20 pixelsize = 20
show_debug = False show_debug = False
running = True running = True
if __name__ == "__main__": if __name__ == "__main__":
@ -103,18 +101,23 @@ if __name__ == "__main__":
exit() exit()
if pressed_keys[pygame.K_PLUS] and not preview_pressed_keys[pygame.K_PLUS]: if pressed_keys[pygame.K_PLUS] and not preview_pressed_keys[pygame.K_PLUS]:
pixelsize += 2 pixelsize += 2
feld,feldx,feldy = make_feld(pixelsize,display_mode)
if pressed_keys[pygame.K_MINUS] and not preview_pressed_keys[pygame.K_MINUS]: if pressed_keys[pygame.K_MINUS] and not preview_pressed_keys[pygame.K_MINUS]:
pixelsize -= 2 pixelsize -= 2
feld,feldx,feldy = make_feld(pixelsize,display_mode)
if pressed_keys[pygame.K_d] and not preview_pressed_keys[pygame.K_d]: if pressed_keys[pygame.K_d] and not preview_pressed_keys[pygame.K_d]:
show_debug = not show_debug show_debug = not show_debug
if pressed_keys[pygame.K_RETURN] and not preview_pressed_keys[pygame.K_RETURN]: if pressed_keys[pygame.K_SPACE] and not preview_pressed_keys[pygame.K_SPACE]:
if using_element == "a": if using_element == "a":
using_element = "#" using_element = "#"
else: else:
using_element = "a" using_element = "a"
if pressed_keys[pygame.K_r] and not preview_pressed_keys[pygame.K_r]: if pressed_keys[pygame.K_r] and not preview_pressed_keys[pygame.K_r]:
if display_mode == "border":
display_mode = "loop"
else:
display_mode = "border"
feld,feldx,feldy = make_feld(pixelsize,display_mode) feld,feldx,feldy = make_feld(pixelsize,display_mode)
print("reset")
preview_pressed_keys = pressed_keys preview_pressed_keys = pressed_keys
## event managment ## event managment
@ -143,7 +146,7 @@ if __name__ == "__main__":
acolor = r,g,b acolor = r,g,b
color_key = {"#":(100,100,100), color_key = {"#":(100,100,100),
"a":acolor} "a":acolor}
draw_feld(feld,color_key,(pixelsize,pixelsize)) draw_feld(feld,color_key,pixelsize)
mx,my = pygame.mouse.get_pos() mx,my = pygame.mouse.get_pos()
mousepressed = pygame.mouse.get_pressed()[0] mousepressed = pygame.mouse.get_pressed()[0]
if mousepressed : if mousepressed :