๐ฏ
Goal for this step Build the level from a list of platforms and land on top of them.
1 The level is just a list: platforms = [Rect(...), Rect(...), ...] , a ground strip plus floating ledges.
2 Replace the temporary floor with a loop over platforms.
3 Land only when FALLING onto the top: vy > 0 and the playerโs bottom was above the platform last frame.
4 Draw every platform green. Then redesign the layout, it is your level!
platforms = [
pygame.Rect(0, 440, 800, 40),
pygame.Rect(150, 340, 140, 16),
pygame.Rect(380, 260, 140, 16),
pygame.Rect(610, 180, 140, 16),
]
on_ground = False
for plat in platforms:
if player.colliderect(plat) and vy > 0 \
and player.bottom - vy <= plat.top:
player.bottom = plat.top
vy = 0
on_ground = True
for plat in platforms:
pygame.draw.rect(screen, (6, 214, 160), plat)
What happens without the vy > 0 check?
A Platforms disappear
B Jumping up through a platform would snap you on top of it instantly, teleport jumps
C Nothing changes
Check Answer
โ
Correct! Next Step โ