I want to make the Dragon on the picture rotate softly to the left when he flies to the left and rotate to the right when he flies to the right and up and down also.
How can I do that with the WASD keys? The Dragon can fly already up, down, lef, and right....but he doesn't turn...
My Code:
import pygame, sys
from pygame.locals import *
pygame.init()
size = width, height = 1600, 848
speed = [2, 2]
black = (0, 0, 0)
pygame.mouse.set_cursor(*pygame.cursors.broken_x)
screen = pygame.display.set_mode(size)
background = pygame.image.load("background.PNG")
dragon1 = pygame.image.load("dragon1.gif")
x,y=0,0
clock=pygame.time.Clock()
speed=250
movex, movey=0,0
while True:
screen.blit(background, (0,0))
screen.blit(dragon1, (x,y))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_a:
movex=-4
elif event.key==K_d:
movex=+4
elif event.key==K_w:
movey=-4
elif event.key==K_s:
movey=+4
if event.type==KEYUP:
if event.key==K_a:
movex=0
elif event.key==K_d:
movex=0
elif event.key==K_w:
movey=0
elif event.key==K_s:
movey=0
x+=movex
y+=movey
pygame.display.flip()