jogeht halbwegs

This commit is contained in:
Michael S. 2024-02-23 15:17:07 +01:00
parent a3ca843364
commit 914262698b

64
main.py
View file

@ -46,42 +46,44 @@ def draw_feld(feld,color_key,block_size):
(b+1)*(block_size[1])))
def get_block_size():
return 20,20
def get_meightboars(feld,position):
nachtbaren = []
return nachtbaren
def save_list(liste,index1,index2):
if index2 > len(liste[0]) and index1 > len(liste):
return liste[index1][index2]
else:
return "a"
def verarbeite_feld(feld):
feld2 = copy.deepcopy(feld)
for y in range(len(feld)-1):
for x in range(len(feld[0])-2):
x += 1
if feld[y][x] == "a":
if feld[y+1][x] == " ":
feld2[y][x] = feld[y+1][x]
feld2[y+1][x] = feld[y][x]
elif feld[y+1][x] == "#":
break
elif feld2[y+1][x+1] == " " or feld2[y+1][x-1] == " ":
# Überprüfen, seiten
direction = random.choice([-1, 1]) # Zufällige Auswahl der Richtung
if feld[y+1][x+direction] == " ":
feld2[y][x] = feld[y+1][x+direction]
feld2[y+1][x+direction] = feld[y][x]
break
else:
direction = -direction
if feld2[y+1][x+direction] == " ":
feld2[y][x] = feld[y+1][x+direction]
feld2[y+1][x+direction] = feld[y][x]
break
else:
feld2[y][x] = "."
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
bellow = feld[(y+1)%feldy][x]
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 == " ":
feld2[y][x] = feld[(y+1)%feldy][x]
feld2[(y+1)%feldy][x] = feld[y][x]
else:
feld2[y][x] = "."
elif bellowr == " ":
feld2[y][x] = feld[(y+1)%feldy][(x+direction)%feldx]
feld2[(y+1)%feldy][(x+direction)%feldx] = feld[y][x]
elif bellowl == " ":
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):
x = screensize[0]//size
y = screensize[1]//size
return [[" " for _ in range(x)] for _ in range(y)]
return [[" " for _ in range(x)] for _ in range(y)],x,y
## klassen
@ -91,12 +93,14 @@ pygame.display.set_caption("SAND")
screensize = pygame.display.get_window_size()
clock = pygame.time.Clock()
default_font = pygame.font.SysFont("sans", 14)
feld = make_feld(20)
feld,feldx,feldy = make_feld(20)
acolor = (255,0,0)
wechselfarbe = "r"
using_element = "a"
pixelsize = 20
display_mode = "durchfallen"
show_debug = False
running = True
if __name__ == "__main__":
@ -147,8 +151,6 @@ if __name__ == "__main__":
wechselfarbe = "r"
acolor = r,g,b
color_key = {" ":(0,0,0),
#".":(0,100,100,100),
"#":(100,100,100),
"a":acolor}
draw_feld(feld,color_key,(pixelsize,pixelsize))
mx,my = pygame.mouse.get_pos()