@Maxxroxx

Почему персонаж движется,но не меняет направление обзора Python/PyGame?

import pygame
from settings import *
from player import Player
import math

pygame.init()
sc = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
player = Player()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    player.move()
    sc.fill(BLACK)

    pygame.draw.circle(sc, RED, player.pos, 12)
    pygame.draw.line(sc, RED, player.pos, (player.x + WIDTH * math.cos(PLAYER_ANGLE), player.y + WIDTH * math.sin(PLAYER_ANGLE)))
    pygame.display.update()
    clock.tick(120)

from settings import *
import pygame

class Player:
    def __init__(self):
        self.x, self.y = player_pos
        self.angle = PLAYER_ANGLE


    @property
    def pos(self):
        return (self.x, self.y)


    def move(self):
        keys = pygame.key.get_pressed()
        if keys[pygame.K_w]:
            self.y -= player_speed
        if keys[pygame.K_s]:
            self.y += player_speed
        if keys[pygame.K_a]:
            self.x -= player_speed
        if keys[pygame.K_d]:
            self.x += player_speed
        if keys[pygame.K_q]:
            self.angle -= 0.02
        if keys[pygame.K_e]:
            self.angle -= 0.02


#game settings
WIDTH = 1200
HEIGHT = 800
HALF_WIDTH = WIDTH // 2
HALF_HEIGHT = HEIGHT // 2
FPS = 60


#Player
player_pos = (HALF_WIDTH, HALF_HEIGHT)
PLAYER_ANGLE = 0.5
player_speed = 2

#Colour
GREEN = (0, 220, 0)
WHIE = (255, 255, 255)
RED = (220, 0, 0)
BLACK = (0, 0, 0)
BLUE = (0, 0, 220)
  • Вопрос задан
  • 93 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы