Code: Select all
def move(self, dt, platforms):
# horizontal movement
self.rect.centerx += round(self.velocity_x * SPEED['player'] * dt)
# vertical movement
self.velocity_y += GRAVITY * dt
self.rect.centery+= round(self.velocity_y * dt)
# ground collision
if self.rect.bottom >= WINDOW_HEIGHT:
self.rect.bottom = WINDOW_HEIGHT
self.velocity_y = 0
for platform in platforms:
if self.rect.colliderect(platform):
if self.velocity_y >= 0 and self.jump_check(platforms): # falling down
self.rect.bottom = platform.top + 1
self.velocity_y = 0
< /code>
Und hier ist die Funktion Jump_Check < /p>
def jump_check(self, platforms):
for platform in platforms:
if self.rect.colliderect(platform) and abs(self.rect.bottom - platform.top) < 10 and self.velocity_y >= 0:
return True
return False