trying to use pygames collide rect method to detect collision for the x axis of the player.
the collisions are not registering at all... which is my problem im trying to mave a square to the right when i hold down the d button, and when i reach the platform, the program below should restrict me from passing through it
player_x = 400
player_y = 300
pygame.init()
player = pygame.image.load(the player)
player_rect = player.get_rect(midbottom = (player_x,player_y))
platform=pygame.image.load(the platform)
platform_rect=platform.get_rect(midbottom = (500,320))
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit
exit()
keys = pygame.key.get_pressed()
if keys[pygame.K_d]:
player_x += 1
platforms = [platform_rect]
x_collision = False
new_player_rect = player.get_rect(midbottom = (player_x,player_y))
for p in platforms:
if p.colliderect(new_player_rect):
x_collision = True
break
if not x_collision:
current_player_x = player_x
screen.blit(BACKGROUND, (0,0))
screen.blit(platform,platform_rect)
screen.blit(player,(current_player_x, player_y))
pygame.display.flip()