-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControls.py
More file actions
64 lines (52 loc) · 2.3 KB
/
Controls.py
File metadata and controls
64 lines (52 loc) · 2.3 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#Controls.py
import sys
import pygame
from Constants import *
import ScreenManager
class ControlManager:
def __init__(self, camera):
self.camera = camera
self.togglePause = False
self.isPaused = False
self.firstCall = True
#manage moving camera controls
def checkUserInputs(self, deltaTime):
#camera position movement
if pygame.key.get_pressed()[pygame.K_a]:
self.camera.moveRelHorz((-MOVE_SPEED * deltaTime, 0, 0))
if pygame.key.get_pressed()[pygame.K_d]:
self.camera.moveRelHorz((MOVE_SPEED * deltaTime, 0, 0))
if pygame.key.get_pressed()[pygame.K_w]:
self.camera.moveRelHorz((0, 0, MOVE_SPEED * deltaTime))
if pygame.key.get_pressed()[pygame.K_s]:
self.camera.moveRelHorz((0, 0, -MOVE_SPEED * deltaTime))
if pygame.key.get_pressed()[pygame.K_SPACE]:
self.camera.moveRelHorz((0, MOVE_SPEED * deltaTime, 0))
if pygame.key.get_pressed()[pygame.K_LCTRL]:
self.camera.moveRelHorz((0, -MOVE_SPEED * deltaTime, 0))
for event in pygame.event.get():
#camera turning movement
if event.type == pygame.MOUSEMOTION and not self.isPaused and self.firstCall != True:
if event.pos != (DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2):
pos = [event.pos[0]-DISPLAY_WIDTH/2, event.pos[1]-DISPLAY_HEIGHT/2]
self.camera.rotate((TURN_SPEED * pos[0] * deltaTime,- TURN_SPEED * pos[1] * deltaTime))
pygame.mouse.set_pos((DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2))
#pausing
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.togglePause = True
#quit event handle
elif event.type == pygame.QUIT:
pygame.quit()
sys.exit()
#negate first call jank
if self.firstCall:
self.firstCall = False
#called by main thread, checks for pause request
def checkPauseToggleRequest(self):
if self.togglePause:
self.togglePause = False
return True
return False
def setPausedState(self, state):
self.isPaused = state