I want the image to face the way it is going. The game runs, but it does not show the player rotating. I need help because I've tried many different ways. There are no errors in the code either it just doesn't work. I also tried making a new variable that's the rotated version of the first one.
here's the code
import pygame
import os
pygame.init
pygame.font.init()
WIDTH, HEIGHT = 800, 700
WIN = pygame.display.set_mode((WIDTH,HEIGHT))
pygame.display.set_caption("zombie game")
FPS = 60
VEL = 5
PERSON_WIDTH, PERSON_HEIGHT = 55,40
GRASS = pygame.transform.scale(pygame.image.load(os.path.join(r'C:\Users\gabri\Downloads\zombie game\grass.png')), (WIDTH, HEIGHT))
PERSON_IMAGE = pygame.image.load(os.path.join(r'C:\Users\gabri\Downloads\zombie game\person.png'))
PERSON = pygame.transform.scale(PERSON_IMAGE, (PERSON_WIDTH, PERSON_HEIGHT))
WHITE = (0,0,0)
def draw_window(player):
WIN.blit(GRASS, (0,0))
WIN.blit(PERSON, (player.x, player.y))
pygame.display.update()
def handle_movement(keys_pressed, player):
if keys_pressed[pygame.K_a] and player.x - VEL > 0:
player.x -= VEL
pygame.transform.rotate(PERSON, 270)
if keys_pressed[pygame.K_d] and player.x + VEL < WIDTH - 55:
player.x += VEL
pygame.transform.rotate(PERSON, 90)
if keys_pressed[pygame.K_w] and player.y - VEL > 0:
player.y -= VEL
pygame.transform.rotate(PERSON, 0)
if keys_pressed[pygame.K_s] and player.y + VEL + player.height < HEIGHT:
player.y += VEL
pygame.transform.rotate(PERSON, 180)
def main():
player = pygame.Rect(372, 330, PERSON_WIDTH, PERSON_HEIGHT)
clock = pygame.time.Clock()
run = True
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys_pressed = pygame.key.get_pressed()
handle_movement(keys_pressed, player)
draw_window(player)
if __name__ == "__main__":
main()