Passage à travers les semi plateformes

This commit is contained in:
theo@manjaro 2021-07-07 16:53:58 +02:00
parent 2019416980
commit 5f4d490f07

View File

@ -57,6 +57,14 @@ class Player(BaseObject):
self.move(0,self.stepsize)
else:
self.move(hor*self.speed*self.game.dt,self.vertical*self.game.dt)
# Je passe en dessous des semi-plateformes
if not self.checkcollisions(0,1,semi=False):
semi = self.checkcollisions(0,1,classic=False)
if semi!=self.checkcollisions(0,0,classic=False) and semi:
if keys["down"]["timer"]==1:
self.rect.bottom = semi.top+1
self.game.globals["camerax"] = self.rect.center[0]-self.game.globals["cameraw"]/2
self.game.globals["cameray"] = self.rect.center[1]-self.game.globals["camerah"]/2
@ -106,16 +114,17 @@ class Player(BaseObject):
ver-=diffy
self.rect[1]+=diffy
def checkcollisions(self,offx,offy):
def checkcollisions(self,offx,offy,classic=True,semi=True):
temprect = self.rect.copy()
temprect[0]+=offx
temprect[1]+=offy
result = False
for rect in self.collisionrects:
if temprect.colliderect(rect):
result = rect
break
if not result:
if classic:
for rect in self.collisionrects:
if temprect.colliderect(rect):
result = rect
break
if not result and semi:
for rect in self.semirects:
if self.rect.bottom<=rect.top:
if temprect.colliderect(rect):