如何在pygame中同时显示正方形和圆形?

我正在尝试制作一个有大量掉落的圆并且玩家(正方形)需要避免掉落的圆的游戏。我设法控制了播放器和所有下降的圆圈,但是当我按播放时,我看到的只是下降的圆圈,没有正方形。正方形显示的唯一时间是当我按箭头键时。如何使正方形和圆形同时显示?

 import pygame
from pygame.locals import *
import os
import random
import math
import sys
import time

white = (255,255,255)
blue = (0,0,255)
gravity = 10
size =10
height = 500
width =600
varHeigth = height
ballNum = 5
eBall = []
apGame = pygame.display.set_mode((width, height))
pygame.display.set_caption("AP Project")

clock = pygame.time.Clock()

class Player(object):

  def __init__(self):
    red = (255, 0, 0)
    move_x = 300
    move_y = 400
    self.rect = pygame.draw.rect(apGame,red, (move_x, move_y, 10, 10))
    self.dist = 10

  def handle_keys(self):
    for e in pygame.event.get():
      if e.type == pygame.QUIT:
        pygame.quit();
        exit()
      elif e.type == pygame.KEYDOWN:
        key = e.key
        if key == pygame.K_LEFT:
          self.draw_rect(-1, 0)
        elif key == pygame.K_RIGHT:
          self.draw_rect(1, 0)
        elif key == pygame.K_ESCAPE:
          pygame.quit();
          exit()

  def draw_rect(self, x, y):
    red = (255, 0, 0)
    black = (0, 0, 0)
    '''apGame.fill(black)'''
    self.rect = self.rect.move(x * self.dist, y * self.dist);
    pygame.draw.rect(apGame, red , self.rect)
    pygame.display.update()


  def draw(self,surface):
    red = (255, 0, 0)
    move_x = 300
    move_y = 400
    pygame.draw.rect(apGame, red, (move_x, move_y, 10, 10))


move_x = 300
move_y = 400
red = (255, 0, 0)
black = (0, 0, 0)
player = Player()
clock = pygame.time.Clock()
'''apGame.fill(black)'''
player.draw(apGame)
pygame.display.update()

for q in range(ballNum):
  x = random.randrange(0, width)
  y = random.randrange(0, varHeigth)
  eBall.append([x, y])

while True:
#I think this is where my problem is
  apGame.fill(black)
  player.handle_keys()

  for i in range(len(eBall)):

    pygame.draw.circle(apGame, blue, eBall[i], size)

    eBall[i][1] += 5

    if eBall[i][1] > height:

        y = random.randrange(-50, -10)
        eBall[i][1] = y

        x = random.randrange(0, width)
        eBall[i][0] = x


  pygame.display.flip()
  clock.tick(30)
评论