Bonk sur le plafond

This commit is contained in:
theo@manjaro 2021-06-25 19:13:40 +02:00
parent dff1fa4175
commit b76e3b45d6

View File

@ -35,6 +35,17 @@ class Player(BaseObject):
self.onground = True
break
# Check if under ceiling
self.onceiling = False
targetpos = self.getgridpos(0,-1)
pos = [targetpos["ul"],targetpos["ur"]]
for x in range(pos[0]["x"],pos[1]["x"]+1):
if pos[0]["y"]>=0 and pos[0]["y"]<len(self.grid):
if x>=0 and x<len(self.grid[pos[0]["y"]]):
if self.grid[pos[0]["y"]][x]==1:
self.onceiling= True
break
if not self.onground:
self.vertical += self.gravity*self.game.dt
self.vertical = min(self.maxgrav,self.vertical)
@ -44,7 +55,8 @@ class Player(BaseObject):
else:
self.vertical = 0
print(self.vertical)
if self.onceiling and self.vertical < 0:
self.vertical = 0
self.move(hor*self.speed*self.game.dt,self.vertical*self.game.dt)