How can I make an Image / Sprite rotate to left / right when left-/right arrow key is pressed ? ... Like a wheel.
So here's the code which runs the game loop:
def gameplay_loop():
exitgame = False
cellpos_x = 0
cellpos_y = cancer_cell.get_rect().height*2
while not exitgame:
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
exitgame = True
quitgame()
key_pressed = pygame.key.get_pressed()
if key_pressed[pygame.K_LEFT]:
cellpos_x -= 10
if key_pressed[pygame.K_RIGHT]:
cellpos_x += 10
gameplay_bg = pygame.image.load("/Users/nedimkanat/Desktop/python/img/gameplay_bg.png").convert()
main_screen.fill(white)
main_screen.blit(gameplay_bg, [0,0])
main_screen.blit(cancer_cell, [cellpos_x, cellpos_y])
pygame.display.flip()
clock.tick(20)
I have tried to add it under key_pressed conditions, but nothing happened and I did as this guy says : https://stackoverflow.com/a/19316827/6256879
The sprite is called cancer_cell
and as I mentioned above, I want it to rotate to Left/Right while Left/Right key is held down.