Included primitiv maps generator

This commit is contained in:
2024-07-08 20:40:44 +02:00
parent 35fca2dec8
commit 891a90f90a
4 changed files with 89 additions and 9 deletions

43
main.py
View File

@@ -15,13 +15,36 @@ ROT = (255,0,0)
PLAYGROUND = pygame.Surface((1024,728))
gamestate = True
map_file = open("maps/map_1.txt")
map_texture_map1 = pygame.image.load("models/wall_1.png")
pacman = pygame.image.load("models/pacman_1.png")
pacman_posx = 0
pacman_posy = 0
pacman_movespeed = 5
pacman_startpoint = {0,0}
movedirection = {"up":False, "down":False, "left":False, "right":False}
map1 = list()
def generate_map(*mapfile):
#Generate row
startpos_x = 0
startpos_y = 0
id = 0
for line in map_file:
#print(line)
for byte in line:
#print(byte)
if(byte == "#"):
map1.append({"id":id,"object": pygame.image.load("models/wall_1.svg"), "x":startpos_x, "y":startpos_y})
startpos_x +=60
id += 1
#print(line)
startpos_x = 0
startpos_y += 60
generate_map()
while(gamestate==True):
MAINSCREEN.fill(WEISS)
@@ -53,26 +76,28 @@ while(gamestate==True):
if(movedirection["up"] == True):
pacman_posy -= pacman_movespeed
if(pacman_posy >= 0):
pacman_posy -= pacman_movespeed
if(movedirection["down"] == True):
pacman_posy += pacman_movespeed
if(pacman_posy <= (MAINSCREEN_SIZE[1]-30)):
pacman_posy += pacman_movespeed
if(movedirection["right"] == True):
if(pacman_posx != MAINSCREEN_SIZE[0]):
if(pacman_posx <= (MAINSCREEN_SIZE[0]-30)):
pacman_posx += pacman_movespeed
print(pacman_posx)
print(MAINSCREEN_SIZE[0])
if(movedirection["left"] == True):
if(pacman_posx != -1):
if(pacman_posx >= 0):
pacman_posx -= pacman_movespeed
#print(pacman_posx)
#print(pacman_posy)
MAINSCREEN.blit(pacman, (pacman_posx,pacman_posy))
for row in map1:
print(row)
MAINSCREEN.blit(row["object"], (row["x"],row["y"]))
pygame.display.flip()
clock.tick(60)