-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
87 lines (73 loc) · 2.79 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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pyglet
from pyglet.gl import *
from pyglet.window import key
import math
import numpy as np
import grav as grav
import model as mod
from MYUI import settings as sets
import old_window as win
class Player:
def __init__(self, d, grav, pos=(0,0,0), rot = (0,0)):
self.grav = grav
self.d = d
self.pos = list(pos)
self.rot = list(rot)
self.airborn = 0
self.acceleration = 0
self.airacceleration = 1.001
self.accelerationconst = 1.01
self.movvec = [0, 0, 0]
def mouse_motion(self, dx, dy):
dx/8; dy/8; self.rot[0] += dy; self.rot[1] -=dx
if self.rot[0] > 90: self.rot[0] = 90
elif self.rot[0] < -90: self.rot[0] = -90
def jump(self):
self.jumpenable = -1
self.speed = 0
if self.airborn:
self.speed = 1
if self.grav.colisionBottom:
self.jumpenable *= -1
else:
self.speed = 0
if self.grav.colisionBottom:
self.jumpenable *= -1
self.airborn = 0
if self.jumpenable:
self.pos[1] += self.s*self.sens * self.speed
def update(self, dt, keys):
self.sens = self.d['walking'] #movement speed
self.s = dt*10
rotY = -self.rot[1]/180*math.pi
dx = self.s*math.sin(rotY)
dz = self.s*math.cos(rotY)
self.jump()
if self.d['console'] != 1:
if keys[key.W]:
self.movvec[0] = +(dx*self.sens)
self.movvec[2] = -(dz*self.sens)
if keys[key.S]:
self.movvec[0] = -(dx*self.sens)
self.movvec[2] = +(dz*self.sens)
if keys[key.A]:
self.movvec[0] = -(dz*self.sens)
self.movvec[2] = -(dx*self.sens)
if keys[key.D]:
self.movvec[0] = +(dz*self.sens)
self.movvec[2] = +(dx*self.sens)
if keys[key.SPACE]:
self.airborn = 1 #jump (on keypress && !colision)
if keys[key.LSHIFT]:
self.pos[1] -= self.s*self.sens
self.pos[1] += self.grav.pos[0] #pull from gravity
self.pos[0] += self.movvec[0]
self.pos[1] += self.movvec[1]
self.pos[2] += self.movvec[2]
if self.airborn:
self.acceleration = self.airacceleration
else:
self.acceleration = self.accelerationconst
self.movvec[0] = self.movvec[0] / self.acceleration
self.movvec[1] = self.movvec[1] / self.acceleration
self.movvec[2] = self.movvec[2] / self.acceleration