Added spawnpoints

This commit is contained in:
theo@manjaro 2021-09-13 07:41:32 +02:00
parent 2aef0afc1c
commit 47da0e400e
2 changed files with 27 additions and 0 deletions

View File

@ -9,6 +9,7 @@ class Lemming(BaseObject):
self.holdradius = 65 self.holdradius = 65
self.holdrect = self.holdrect.inflate(self.holdradius,self.holdradius) self.holdrect = self.holdrect.inflate(self.holdradius,self.holdradius)
self.basespeed = 40+random.randint(-speedmargin,speedmargin) # Speed that he normally walks by self.basespeed = 40+random.randint(-speedmargin,speedmargin) # Speed that he normally walks by
self.holdtimer = game.lib.Timer(2.5) # Max seconds of holding
self.normalspeed = self.basespeed # Speed "objective" self.normalspeed = self.basespeed # Speed "objective"
self.speed = 0 # Current speed, leaning towards objective speed self.speed = 0 # Current speed, leaning towards objective speed
@ -57,6 +58,11 @@ class Lemming(BaseObject):
# Releasing it # Releasing it
if mouse["click"]==0 or not self.holdrect.collidepoint(mouse["campos"]): if mouse["click"]==0 or not self.holdrect.collidepoint(mouse["campos"]):
self.launch() self.launch()
else:
if self.holdtimer.tick(self.game.dt):
self.selected = False
self.holdtimer.reset()
self.normalspeed = self.basespeed
if self.game.inputs["mouse"]["click"]==1: if self.game.inputs["mouse"]["click"]==1:
if self.rect.collidepoint(mouse["campos"]): if self.rect.collidepoint(mouse["campos"]):
self.selected = True self.selected = True

View File

@ -14,6 +14,7 @@ class Tiles(BaseObject):
self.cellsize = cellsize self.cellsize = cellsize
self.grid = self.gengrid(nbcells,nbcells) self.grid = self.gengrid(nbcells,nbcells)
self.spawns = self.getspawnpoints(self.grid)
def gengrid(self,w,h): def gengrid(self,w,h):
# Generating various rectangles on a map # Generating various rectangles on a map
@ -33,9 +34,29 @@ class Tiles(BaseObject):
return grid return grid
def getspawnpoints(self,grid,saferadius=2):
spawns = []
for y in range(saferadius,len(grid)-saferadius):
for x in range(saferadius,len(grid[y])-saferadius):
canspawn = True
for safey in range(-saferadius,saferadius+1):
for safex in range(-saferadius,saferadius+1):
if grid[y+safey][x+safex]==0: # If a pit is inside the radius, can't spawn here
canspawn = False
if canspawn:
spawns.append([x,y])
return spawns
def draw(self): def draw(self):
# Drawing the grid # Drawing the grid
for y in range(len(self.grid)): for y in range(len(self.grid)):
for x in range(len(self.grid[y])): for x in range(len(self.grid[y])):
if self.grid[y][x]==1: if self.grid[y][x]==1:
self.game.pygame.draw.rect(self.game.window,[255]*3,[self.rect[0]+x*self.cellsize,self.rect[1]+y*self.cellsize,self.cellsize,self.cellsize]) self.game.pygame.draw.rect(self.game.window,[255]*3,[self.rect[0]+x*self.cellsize,self.rect[1]+y*self.cellsize,self.cellsize,self.cellsize])
# Draw spawn points
if self.game.globals["debug"]:
for x,y in self.spawns:
screenx = self.rect[0]+(x+0.5)*self.cellsize
screeny = self.rect[1]+(y+0.5)*self.cellsize
point = (screenx,screeny)
self.game.pygame.draw.circle(self.game.window,[100,100,0],point,radius=3)