Я пытаюсь запрограммировать небольшую игру с pygame, в которой цель состоит в том, чтобы поймать как можно больше p oop и избежать зараженного p oop, но я не могу заставить противника сменить направление, когда оно ударяется о стену.
import pygame
from pygame.locals import *
pygame.init()
pygame.display.set_caption('POOPISTINKI')
screen_width = 800
screen_height = 600
game_running = True
pl_x = int(screen_width/10)
pl_y = int(screen_height/2)
pl_width = 80
pl_height = 40
pl_vel = 30
en_width = 80
en_height = 40
en_x = screen_width - screen_width/10 - en_width
en_y = int(screen_height/2)
en_yvel = 10
screen = pygame.display.set_mode((screen_width, screen_height))
while game_running:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_running = False
if event.type == MOUSEBUTTONDOWN:
if event.button == 4 and pl_y > pl_vel:
pl_y -= pl_vel
elif event.button == 5 and pl_y < screen_height - pl_width:
pl_y += pl_vel
if en_y == 0:
en_y += en_yvel
if en_y == screen_height - en_height:
en_y -= en_yvel
screen.fill((0, 0, 0))
pygame.draw.rect(screen, (105, 255, 125), (pl_x, pl_y, pl_width, pl_height))
pygame.display.update()
pygame.draw.rect(screen, (255, 125, 115), (en_x, en_y, en_width, en_height))
pygame.display.update()
pygame.quit()