I have been trying to make collisions in a game i'm working on and am trying to blit dialogue whenever two rects collide and the player presses e but cant figure it out
whenever i test it it shows me the dialogue once in 2 presses or sometimes never but when i put a print statement in the if part it works just fine but still doesnt blit the dialogue
import pygame
from sys import exit
pygame.init()
WIDTH = 800
HEIGHT = 800
x = 0
y = 0
my_font = pygame.font.Font(None, 30)
screen = pygame.display.set_mode((WIDTH, HEIGHT))
test_rect = pygame.Rect((x,y),(40,40))
dialogue_rect = pygame.Rect((150,150),(150,150))
dialogue = my_font.render('Hello mate', False, 'black')
running = True
while running:
screen.fill((255,255,255))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
running = False
exit()
def move():
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
test_rect.move_ip(0,-1)
elif keys[pygame.K_DOWN]:
test_rect.move_ip(0,1)
elif keys[pygame.K_RIGHT]:
test_rect.move_ip(1,0)
elif keys[pygame.K_LEFT]:
test_rect.move_ip(-1,0)
move()
if test_rect.colliderect(dialogue_rect):
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_e:
screen.blit(dialogue,(400,100))
pygame.draw.rect(screen, 'blue', test_rect)
pygame.draw.rect(screen, 'green', dialogue_rect)
pygame.display.update()