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)

3
maps/map_1.txt Normal file
View File

@@ -0,0 +1,3 @@
######## #################################
########## ################# ###########
#################################################

BIN
models/wall_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

52
models/wall_1.svg Normal file
View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg1"
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
sodipodi:docname="wall_1.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="0.72426347"
inkscape:cx="396.95499"
inkscape:cy="561.25984"
inkscape:window-width="1920"
inkscape:window-height="1009"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1" />
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#4d4d4d;stroke-width:0.264583"
id="rect1"
width="14.977859"
height="15.343174"
x="63.199261"
y="98.269371"
inkscape:export-filename="wall_1.png"
inkscape:export-xdpi="101.75021"
inkscape:export-ydpi="101.75021" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB