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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include "../game.h"
#include "objlist.h"
#include "physics/movement.h"
#include "player.h"
F32 PLAYER_HULL_HEIGHT = 48.f;
F32 PLAYER_HULL_WIDTH = 32.f;
PLAYER* player_create( VEC3 origin, F32 yaw ) {
PLAYER* p = obj_add<PLAYER>( "localplayer" );
p->pos = origin;
p->rot = { 0, yaw, 0 };
p->health = 100;
p->keeponlevel = 1;
p->velocity = {};
p->flags = {};
p->mins = {
-PLAYER_HULL_WIDTH * .5f,
-PLAYER_HULL_WIDTH * .5f,
0
};
p->maxs = {
PLAYER_HULL_WIDTH * .5f,
PLAYER_HULL_WIDTH * .5f,
PLAYER_HULL_HEIGHT
};
return p;
}
void capture_mouse( PLAYER* p ) {
F32* yaw = &p->input.cam.pos.y;
F32* pitch = &p->input.cam.pos.x;
if( input.keys[SDL_SCANCODE_F1] ) {
input_capture_mouse( 0 );
}
if( input.mouselock ) {
*yaw += input.mouse.pos_delta.x * input.msens;
*pitch -= input.mouse.pos_delta.y * input.msens;
if( *pitch > 89.f ) *pitch = 89.f;
if( *pitch < -89.f ) *pitch = -89.f;
input_reset_mouse_accumulator();
}
*yaw = remainderf( *yaw, 360.f );
p->rot.x = *pitch;
p->rot.y = *yaw;
}
void capture_move_keys( PLAYER* p ) {
VEC2* move = &p->input.move;
p->input.jump = input.keys[input.binds.jump];
if( input.keys[input.binds.fwd] ) {
if( !p->input.fwd_held ) move->x = 1.f;
p->input.fwd_held = 1;
} else {
if( p->input.fwd_held ) {
if( p->input.bk_held ) move->x = -1.f;
else move->x = 0.f;
}
p->input.fwd_held = 0;
}
if( input.keys[input.binds.back] ) {
if( !p->input.bk_held ) move->x = -1.f;
p->input.bk_held = 1;
} else {
if( p->input.bk_held ) {
if( p->input.fwd_held ) move->x = 1.f;
else move->x = 0.f;
}
p->input.bk_held = 0;
}
if( input.keys[input.binds.left] ) {
if( !p->input.left_held ) move->y = -1.f;
p->input.left_held = 1;
} else {
if( p->input.left_held ) {
if( p->input.right_held ) move->y = 1.f;
else move->y = 0.f;
}
p->input.left_held = 0;
}
if( input.keys[input.binds.right] ) {
if( !p->input.right_held ) move->y = 1.f;
p->input.right_held = 1;
} else {
if( p->input.right_held ) {
if( p->input.left_held ) move->y = -1.f;
else move->y = 0.f;
}
p->input.right_held = 0;
}
}
void player_input( GAME_DATA* game, PLAYER* p ) {
if( !p )
return;
capture_mouse( p );
capture_move_keys( p );
}
void player_move( GAME_DATA* game, PLAYER* p ) {
gmove_set_player( p );
gmove_tick();
}
VEC3 player_get_view_pos( PLAYER* p ) {
return VEC3( p->pos.x, p->pos.y, p->pos.z + p->eyeoffset );
}
|