diff options
Diffstat (limited to 'src/game/player.cpp')
| -rw-r--r-- | src/game/player.cpp | 95 |
1 files changed, 25 insertions, 70 deletions
diff --git a/src/game/player.cpp b/src/game/player.cpp index 51d1cf8..65daa9b 100644 --- a/src/game/player.cpp +++ b/src/game/player.cpp @@ -1,6 +1,7 @@ #include "../game.h" #include "SDL_scancode.h" #include "objlist.h" +#include "physics/movement.h" #include "world/trace.h" #include <cmath> #include "player.h" @@ -34,8 +35,9 @@ PLAYER* player_create( VEC3 origin, F32 yaw ) { 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( false ); + input_capture_mouse( 0 ); } if( input.mouselock ) { @@ -56,59 +58,47 @@ void capture_mouse( PLAYER* p ) { void capture_move_keys( PLAYER* p ) { VEC2* move = &p->input.move; if( input.keys[input.binds.fwd] ) { - if( !p->input.fwd_held ) - move->x = 1.f; - p->input.fwd_held = true; + 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; + if( p->input.bk_held ) move->x = -1.f; + else move->x = 0.f; } - p->input.fwd_held = false; + p->input.fwd_held = 0; } if( input.keys[input.binds.back] ) { - if( !p->input.bk_held ) - move->x = -1.f; - p->input.bk_held = true; + 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; + if( p->input.fwd_held ) move->x = 1.f; + else move->x = 0.f; } - p->input.bk_held = false; + p->input.bk_held = 0; } if( input.keys[input.binds.left] ) { - if( !p->input.left_held ) - move->y = -1.f; - p->input.left_held = true; + 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; + if( p->input.right_held ) move->y = 1.f; + else move->y = 0.f; } - p->input.left_held = false; + p->input.left_held = 0; } if( input.keys[input.binds.right] ) { - if( !p->input.right_held ) - move->y = 1.f; - p->input.right_held = true; + 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; + if( p->input.left_held ) move->y = -1.f; + else move->y = 0.f; } - p->input.right_held = false; + p->input.right_held = 0; } } @@ -121,43 +111,8 @@ void player_input( GAME_DATA* game, PLAYER* p ) { } void player_move( GAME_DATA* game, PLAYER* p ) { - VEC2 move = p->input.move; - F32 yawrad = m_deg2rad( p->rot.y ); - - VEC3 wishdir = { - move.x * cosf( yawrad ) - move.y * sinf( yawrad ), - move.y * cosf( yawrad ) + move.x * sinf( yawrad ), - 0 - }; - - VEC3 vel = wishdir * 70.f; - p->velocity = vel; - VEC3 wishmove = vel * TICK_INTERVAL; - // todo : should never be false - if( vec_len( wishmove ) > BSP_TRACE_EPSILON && game->state.map->bsp ) { - BSP_TRACE tr{}; - AABB aabb{}; - tr.in_start = p->pos; - tr.in_end = tr.in_start + wishmove; - aabb.min = p->mins; - aabb.max = p->maxs; - - bsp_trace( &tr, game->state.map->bsp, aabb ); - if( !tr.hit ) - p->pos += wishmove; - else { - p->pos += wishmove * tr.frac; - - - // TODO: clipvelocity fixes this, clips velocity to 1 wall (should do 4) - VEC3 left = wishmove * (1.f - tr.frac); - F32 into = vec_dot( left, tr.normal ); - if( into < 0.f ) - left -= tr.normal * into; - - p->pos += left; - } - } + gmove_set_player( p ); + gmove_tick(); } VEC3 player_get_view_pos( PLAYER* p ) { |
