arctic-masher/mapgen.py

53 lines
1.8 KiB
Python
Raw Normal View History

2023-05-17 12:09:48 +00:00
import random
2023-05-17 12:42:21 +00:00
import uuid
2023-05-17 12:09:48 +00:00
from globals import *
2023-05-17 12:09:48 +00:00
from player import *
from blocks import *
from enemies import *
def generateMap():
gameMap.clear()
for i in range(tileCountx):
column = []
for j in range(tileCounty):
column.append(False)
gameMap.append(column)
2023-05-17 12:09:48 +00:00
for i in range(300):
try:
spot = [random.randint(0, tileCountx - 1), random.randint(0, tileCounty - 1)]
if gameMap[spot[0]][spot[1]]:
raise Exception("spot taken!")
gameMap[spot[0]][spot[1]] = Block(uuid.uuid4(), spot[0], spot[1])
2023-05-17 12:09:48 +00:00
except Exception as error:
continue
2023-05-18 05:45:11 +00:00
for i in range(60):
2023-05-17 12:09:48 +00:00
for j in range(50):
try:
spot = [random.randint(0, tileCountx - 1), random.randint(0, tileCounty - 1)]
if gameMap[spot[0]][spot[1]]:
raise Exception("spot taken!")
newEnemy = Enemy(uuid.uuid4(), spot[0], spot[1])
gameMap[spot[0]][spot[1]] = newEnemy
enemies[newEnemy.id] = newEnemy
2023-05-17 12:09:48 +00:00
break
except Exception as error:
continue
2023-05-17 12:42:21 +00:00
for id, player in players.items():
2023-05-17 12:09:48 +00:00
maxTries = 5
2023-05-18 04:34:16 +00:00
for i in range(maxTries + 1):
if i == maxTries:
2023-05-17 12:09:48 +00:00
raise Exception("No spots found for player!")
try:
spot = [random.randint(0, tileCountx - 1), random.randint(0, tileCounty - 1)]
if gameMap[spot[0]][spot[1]]:
raise Exception("spot taken!")
gameMap[spot[0]][spot[1]] = player
player.x = spot[0]
player.y = spot[1]
2023-05-18 07:35:26 +00:00
player.pathMap = player.buildOwnPathMap()
2023-05-17 12:09:48 +00:00
break
except Exception as error:
continue