0

I am trying to rotate my paddle object on a key press and have the pong ball hit the rotated object.

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))

I expected to display a rotated image of my player, but that doesn't happen on a key press of u. Also, when I wrote another function earlier to rotate my player, the ball would not hit the rotated image, but instead it would still hit the rectangle of the previously unrotated image. Also, here is my PlayerPaddle class.

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()
martineau
  • 119,623
  • 25
  • 170
  • 301
turtlefish12
  • 241
  • 3
  • 12
  • where do you have `screen.fill()` which clears screen ? I expect it is after you draw rotated paddle - so you can't see it. – furas Dec 02 '17 at 18:34
  • if you rotate image then it doesn't change `self.rect` automatically - so you still use the same `rect` to check collision. But `rect` always has sides vertical and horizontal. You can't rotate `rect`. You will have to build own method to check collision. – furas Dec 02 '17 at 18:37
  • BTW: see [pygame.sprite.collide_mask()](http://pygame.org/docs/ref/sprite.html#pygame.sprite.collide_mask) – furas Dec 02 '17 at 19:02

0 Answers0