So I keep trying to detect two different moving rects in pygame colliding but its just constantly registering a collision. As in the console constantly print lose, but the enemy isn't even touching the ball. The effect I want is just a simple game where the ball has to avoid the tack so that the ball doesn't pop.
import pygame import sys import math import random pygame.init() size = width, height = 800, 600 white = 255, 255, 255 red = 255, 0, 0 clock = pygame.time.Clock() screen = pygame.display.set_mode(size) character = pygame.image.load("intro_ball.gif") charrect = character.get_rect() x = 340 y = 480 enemy = pygame.image.load("ho.png") enrect = enemy.get_rect() ex = random.randint(0, 690) ey = 0 lose = False while 1: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if ey >= 600 and lose != True: ey = 0 ex = random.randint(0, 690) collide = pygame.Rect.colliderect(charrect, enrect) if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT and x < 690: x += 4 if event.key == pygame.K_LEFT and x > 0: x -= 4 if collide: lose = True else: lose = False if lose == True: print("lose") ey += 2 screen.fill(white) screen.blit(enemy, (ex, ey)) screen.blit(character, (x, y)) pygame.display.update()