试图旋转桨对象并在旋转的桨上有乒乓球击球

时间:2017-12-02 18:32:36

标签: python rotation pygame

我正在尝试在按键上旋转我的球拍对象并让乒乓球击中旋转的物体。

for event in pygame.event.get():
    if event.type == QUIT:
        running = False

    if event.type == KEYDOWN:
        if event.key in keymap:
            keymap[event.key] = True
        if event.key == K_UP:
            player_paddle.direction = -1
        elif event.key == K_DOWN:
            player_paddle.direction = 1
        elif event.key == K_u:
            newImage= pygame.transform.rotate(player_paddle.image, 30)
            screen.blit(newImage, player_paddle.rect))

我希望显示我的播放器的旋转图像,但这不会发生在u的按键上。此外,当我之前编写另一个功能来旋转我的播放器时,球不会击中旋转的图像,而是仍然会击中先前未旋转的图像的矩形。另外,这是我的PlayerPaddle课程。

class PlayerPaddle(object):
    def __init__(self, screensize):
        self.screensize = screensize
        self.centerx = 50
        self.centery = screensize[1]//2

        self.height = 100
        self.width = 20
        self.image = pygame.image.load("naruto.png").convert_alpha()
        self.image = pygame.transform.scale(self.image, (self.width, self.height))
        #self.rect = pygame.Rect(0, self.centery-(self.height // 2), self.width, self.height)
        self.rect = self.image.get_rect()

0 个答案:

没有答案