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