juhuuu
This commit is contained in:
parent
697f8e1fa9
commit
ec8913b108
1 changed files with 21 additions and 34 deletions
55
main.py
55
main.py
|
@ -24,26 +24,12 @@ def draw_feld(feld,color_key,block_size):
|
||||||
#print(feld)
|
#print(feld)
|
||||||
for a in range(len(feld[0])):
|
for a in range(len(feld[0])):
|
||||||
for b in range(len(feld)):
|
for b in range(len(feld)):
|
||||||
#print(a,b)
|
if feld[b][a] != " ":
|
||||||
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]])
|
|
||||||
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[0],
|
||||||
b*block_size[1],
|
b*block_size[1],
|
||||||
(a+1)*(block_size[0]),
|
(block_size[0]),
|
||||||
(b+1)*(block_size[1])))
|
(block_size[1])))
|
||||||
def get_block_size():
|
def get_block_size():
|
||||||
return 20,20
|
return 20,20
|
||||||
def get_meightboars(feld,position):
|
def get_meightboars(feld,position):
|
||||||
|
@ -58,8 +44,6 @@ def verarbeite_feld(feld):
|
||||||
feld2 = copy.deepcopy(feld)
|
feld2 = copy.deepcopy(feld)
|
||||||
for y in range(len(feld)):
|
for y in range(len(feld)):
|
||||||
for x in range(len(feld[0])):
|
for x in range(len(feld[0])):
|
||||||
#x += 1
|
|
||||||
pos = x,y
|
|
||||||
poschar = feld[y][x]
|
poschar = feld[y][x]
|
||||||
if poschar == "a":
|
if poschar == "a":
|
||||||
# uberprüfe unteren block
|
# uberprüfe unteren block
|
||||||
|
@ -67,25 +51,28 @@ 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 == "#":
|
|
||||||
break
|
if bellow == " " and not bellow == "#":
|
||||||
if 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 == " ":
|
elif bellowr == " " and not bellow == "#":
|
||||||
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 == " ":
|
elif bellowl == " " and not bellow == "#":
|
||||||
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
|
||||||
|
|
||||||
def make_feld(size):
|
def make_feld(size,mode):
|
||||||
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)],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
|
## klassen
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,14 +82,15 @@ 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,feldx,feldy = make_feld(20)
|
|
||||||
feld[feldy-1][0] = "#"
|
display_mode = "border"
|
||||||
|
feld,feldx,feldy = make_feld(20,display_mode)
|
||||||
|
|
||||||
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
|
||||||
|
@ -125,7 +113,7 @@ if __name__ == "__main__":
|
||||||
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]:
|
||||||
feld = make_feld(pixelsize)
|
feld,feldx,feldy = make_feld(pixelsize,display_mode)
|
||||||
print("reset")
|
print("reset")
|
||||||
|
|
||||||
preview_pressed_keys = pressed_keys
|
preview_pressed_keys = pressed_keys
|
||||||
|
@ -135,7 +123,7 @@ if __name__ == "__main__":
|
||||||
exit()
|
exit()
|
||||||
if event.type == pygame.WINDOWRESIZED:
|
if event.type == pygame.WINDOWRESIZED:
|
||||||
screensize = pygame.display.get_window_size()
|
screensize = pygame.display.get_window_size()
|
||||||
feld = make_feld(pixelsize)
|
feld,feldx,feldy = make_feld(pixelsize,display_mode)
|
||||||
r,g,b = acolor
|
r,g,b = acolor
|
||||||
if wechselfarbe == "r":
|
if wechselfarbe == "r":
|
||||||
r -= 1
|
r -= 1
|
||||||
|
@ -153,8 +141,7 @@ if __name__ == "__main__":
|
||||||
if b == 0:
|
if b == 0:
|
||||||
wechselfarbe = "r"
|
wechselfarbe = "r"
|
||||||
acolor = r,g,b
|
acolor = r,g,b
|
||||||
color_key = {" ":(0,0,0),
|
color_key = {"#":(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()
|
||||||
|
@ -170,4 +157,4 @@ if __name__ == "__main__":
|
||||||
## bildschirm aktuallisierung
|
## bildschirm aktuallisierung
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(30)
|
clock.tick(30)
|
||||||
#screen.fill((100,0,0))
|
screen.fill((0,0,0))
|
Loading…
Reference in a new issue