So im wanting a "weapon" to rotate around a specific pivot point which i have save as weapon_x, weapon_y. Then i made a function call rotatepivoted which will rotate an image. I want it to complete 1 full rotation a second and with my game running at 12 frames a second I want the image to rotate 15 degrees each frame. This currently make the axe fly off the screen for some reason.
def rotatePivoted(im, angle, pivot):
# rotate the leg image around the pivot
image = pygame.transform.rotate(im, angle)
rect = image.get_rect()
rect.center = pivot
return image, rect
while running:
screen.fill('White')
draw_floors()
draw_walls()
player.draw()
chort.draw()
#Key/event detection
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
run = False
if event.key == pygame.K_a:
player.moving_left = True
player.idle = False
if event.key == pygame.K_d:
player.moving_right = True
player.idle = False
if event.key == pygame.K_w:
player.moving_up = True
player.idle = False
if event.key == pygame.K_s:
player.moving_down = True
player.idle = False
if event.key == pygame.K_j:
pass
if event.type == pygame.KEYUP:
player.idle = True
player.moving_left = False
player.moving_right = False
player.moving_down = False
player.moving_up = False
screen.blit(weapon, (player.rect.x + player.rect.width - 8 , player.rect.y + (player.rect.height / 2) - weapon_y + 3))
weapon, rect = rotatePivoted(weapon, 15, (weapon_x, weapon_y))
player.move()
chort.ai_move(player.rect.x, player.rect.y)
pygame.display.flip()
player.update()
chort.update()
clock.tick(12)
pygame.quit