-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
37 lines (30 loc) · 936 Bytes
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from settings import *
import pygame
import math
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 movement(self):
sin_a = math.sin(self.angle)
cos_a = math.cos(self.angle)
keys = pygame.key.get_pressed()
if keys[pygame.K_w]:
self.x += player_speed*cos_a
self.y += player_speed*sin_a
if keys[pygame.K_s]:
self.x -= player_speed*cos_a
self.y -= player_speed*sin_a
if keys[pygame.K_a]:
self.x += player_speed*sin_a
self.y -= player_speed*cos_a
if keys[pygame.K_d]:
self.x -= player_speed*sin_a
self.y += player_speed*cos_a
if keys[pygame.K_LEFT]:
self.angle -= 0.02
if keys[pygame.K_RIGHT]:
self.angle += 0.02