Updated tererain generation

This commit is contained in:
theo@manjaro 2021-09-13 10:53:42 +02:00
parent 70b1f0760d
commit e6d1d9c9dd

View File

@ -13,18 +13,20 @@ class Tiles(BaseObject):
self.nbcells = nbcells
self.cellsize = cellsize
self.grid = self.gengrid(nbcells,nbcells)
self.spawns = self.getspawnpoints(self.grid)
self.saferadius = 2
def gengrid(self,w,h):
self.grid = self.gengrid(nbcells,nbcells,minsize=self.saferadius*2+1)
self.spawns = self.getspawnpoints(self.grid,saferadius=self.saferadius)
def gengrid(self,w,h,minsize=3,randrange=4):
# Generating various rectangles on a map
grid = [ [0 for x in range(w)] for y in range(h) ]
nb_rects = int(sqrt(w*h)/1.5+0.5)
for i in range(nb_rects):
# Generating the rects
rectw = random.randint(3,7)
recth = random.randint(3,7)
rectw = random.randint(0,randrange)+minsize
recth = random.randint(0,randrange)+minsize
rectx = random.randint(0,w-rectw)
recty = random.randint(0,h-recth)