我试图用我拥有的另一个rect进行rect拍摄,但是当我调用该函数时,什么也没发生。我不明白为什么。我使用速度变量更改了y坐标,但仍然没有任何反应。这是我的代码: 任何帮助将不胜感激
import pygame
pygame.init()
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
width, height = 800, 600
gameDisplay = pygame.display.set_mode((width, height))
velocity = 0.2
toggle_flag = 1
class App():
def __init__(self):
pass
def fill_screen(self, color):
self.color = color
gameDisplay.fill(self.color)
def draw_player(self, color, lead_x, lead_y, block_size):
self.color = color
self.lead_x = lead_x
self.lead_y = lead_y
self.block_size = block_size
pygame.draw.rect(gameDisplay, self.color, [self.lead_x, self.lead_y, self.block_size, self.block_size])
class Player():
lead_x = width/2
lead_y = height/2
block_size = 10
def __init__(self):
pass
def shoot_player(self, lead_x, lead_y, block_size):
self.lead_x = lead_x
self.lead_y = lead_y
self.block_size = block_size
lead_y2 = self.lead_y
pygame.draw.rect(gameDisplay, RED, [self.lead_x, lead_y2, self.block_size, self.block_size])
lead_y2 += -velocity
exitGame = False
app = App()
player = Player()
while not exitGame:
app.fill_screen(WHITE)
app.draw_player(BLACK, width/2, height/2, 10)
for event in pygame.event.get():
if event.type == pygame.QUIT:
exitGame = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
player.shoot_player(width/2, height/2, 2)
pygame.display.update()
pygame.quit()
quit()