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