-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
38 lines (32 loc) · 1.08 KB
/
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
36
37
38
import pygame as pg
from camera import Camera
from settings import *
class Player(Camera):
def __init__(self, app, position=PLAYER_POS, yaw=-90, pitch=0):
self.app = app
super().__init__(position, yaw, pitch)
def update(self):
self.keyboard_control()
self.mouse_control()
super().update()
def mouse_control(self):
mouse_dx, mouse_dy = pg.mouse.get_rel()
if mouse_dx:
self.rotate_yaw(delta_x=mouse_dx * MOUSE_SENSITIVITY)
if mouse_dy:
self.rotate_pitch(delta_y=mouse_dy * MOUSE_SENSITIVITY)
def keyboard_control(self):
key_state = pg.key.get_pressed()
vel = PLAYER_SPEED * self.app.delta_time
if key_state[pg.K_w]:
self.move_forward(vel)
if key_state[pg.K_s]:
self.move_backward(vel)
if key_state[pg.K_a]:
self.move_left(vel)
if key_state[pg.K_d]:
self.move_right(vel)
if key_state[pg.K_SPACE]:
self.move_up(vel)
if key_state[pg.K_LSHIFT]:
self.move_down(vel)