Creating Floors For Players In Pygame
Creating The Floor
- Check the Collision between player and floor
- move player up if collission
if player.bottom > 324: player.bottom = 324 (324 = the top of the ground)
# Creating the floor
if player_rectangle.bottom >= 324: player_rectangle.bottom = 324
# The screen should always be at the bottom
screen.blit(player_surface, player_rectangle)
Creating the Ceil
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and player_rectangle.bottom >= 324: # if space is pressed and player is on the ground
player_gravity = -20
if event.type == pygame.MOUSEBUTTONDOWN:
if player_rectangle.collidepoint((event.pos)) and player_rectangle.bottom >= 324: # if btn is pressed and player is on the ground
player_gravity = -20