#include "player.h"
#include "input.h"
+#include "audio.h"
VG_STATIC void player_walk_drop_in_vector( player_instance *player, v3f vec )
{
VG_STATIC void player_walk_drop_in_to_skate( player_instance *player )
{
+ player->immobile = 0;
player->subsystem = k_player_subsystem_skate;
struct player_walk *w = &player->_walk;
v3_muladds( player->rb.co, player->rb.to_world[1], 1.0f, s->state.cog );
v3_copy( init_velocity, s->state.cog_v );
v3_copy( init_velocity, player->rb.v );
- v3_copy( init_velocity, player->cam_velocity_smooth );
+ v3_copy( init_velocity, player->cam_control.cam_velocity_smooth );
v3_copy( (v3f){1.0f,0.0f,0.0f}, s->state.trick_euler );
}
VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
{
struct player_walk *w = &player->_walk;
- world_instance *world = get_active_world();
+ world_instance *world = world_current_instance();
v3f dir, center;
q_mulv( player->rb.q, (v3f){0.0f,0.0f,1.0f}, dir );
if( ray_world( world, pos, ray_dir, ray ) )
{
vg_line( pos, ray->pos, VG__RED );
- vg_line_pt3( ray->pos, 0.025f, VG__BLACK );
+ vg_line_point( ray->pos, 0.025f, VG__BLACK );
sample_count ++;
}
if( ray_world( world, va, v0, &ray ) )
{
vg_line( va, vb, VG__RED );
- vg_line_pt3( ray.pos, 0.1f, VG__RED );
+ vg_line_point( ray.pos, 0.1f, VG__RED );
vg_error( "invalidated\n" );
return 0;
}
if( ray_world( world, vb, v0, &ray ) )
{
vg_line( va, vb, VG__RED );
- vg_line_pt3( ray.pos, 0.1f, VG__RED );
+ vg_line_point( ray.pos, 0.1f, VG__RED );
vg_error( "invalidated\n" );
return 0;
}
player->subsystem = k_player_subsystem_drive;
}
else{
+ struct player_board *board =
+ addon_cache_item_if_loaded( k_addon_type_board,
+ player->board_view_slot );
+
+ if( !board ) return;
+
if( w->state.activity == k_walk_activity_ground ){
if( player_walk_scan_for_drop_in( player ) ){
w->state.outro_type = k_walk_outro_drop_in;
}
}
}
+ else if( button_down( k_srbind_jump ) && !player->immobile ){
+ w->state.jump_queued = 1;
+ w->state.jump_input_time = vg.time;
+ }
}
VG_STATIC int player_walk_normal_standable( player_instance *player, v3f n )
{
struct player_walk *w = &player->_walk;
v3_copy( player->rb.co, w->state.prev_pos );
+ v3_zero( player->rb.w );
+
+ world_instance *world = world_current_instance();
+
+ if( world->water.enabled ){
+ if( player->rb.co[1]+0.4f < world->water.height ){
+ audio_oneshot_3d( &audio_splash, player->rb.co, 40.0f, 1.0f );
+ player__dead_transition( player );
+ return;
+ }
+ }
enum walk_activity prev_state = w->state.activity;
m3x3_copy( player->rb.to_world, mtx );
v3_add( player->rb.co, player->basis[1], mtx[3] );
- debug_capsule( mtx, w->collider.radius, w->collider.height, VG__WHITE );
+ vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__WHITE );
rb_ct manifold[64];
int len;
m3x3_mulv( player->basis, forward_dir, forward_dir );
m3x3_mulv( player->basis, right_dir, right_dir );
- w->move_speed = v2_length( srinput.joy_steer );
- world_instance *world = get_active_world();
+ v2f steer;
+ joystick_state( k_srjoystick_steer, steer );
+
+ w->move_speed = v2_length( steer );
/*
* Collision detection
*/
float accel_speed = 0.0f, nominal_speed = 0.0f;
v3f movedir;
- v3_muls( right_dir, srinput.joy_steer[0], movedir );
- v3_muladds( movedir, forward_dir, srinput.joy_steer[1], movedir );
+
+ v3_muls( right_dir, steer[0], movedir );
+ v3_muladds( movedir, forward_dir, steer[1], movedir );
if( w->state.activity == k_walk_activity_ground ){
v3_normalize( surface_avg );
v3f tx, ty;
- rb_tangent_basis( surface_avg, tx, ty );
+ v3_tangent_basis( surface_avg, tx, ty );
- if( v2_length2(srinput.joy_steer) > 0.001f ){
+ if( v2_length2(steer) > 0.001f ){
/* clip movement to the surface */
float d = v3_dot(surface_avg,movedir);
v3_muladds( movedir, surface_avg, -d, movedir );
nominal_speed = k_walkspeed;
/* jump */
- if( button_down( k_srbind_jump ) ){
- float d = v3_dot( player->basis[1], player->rb.v );
- v3_muladds( player->rb.v, player->basis[1], -d, player->rb.v );
- v3_muladds( player->rb.v, player->basis[1], 5.0f, player->rb.v );
- w->state.activity = k_walk_activity_air;
- prev_state = k_walk_activity_air;
- accel_speed = k_walk_air_accel;
- nominal_speed = k_airspeed;
+ if( w->state.jump_queued ){
+ w->state.jump_queued = 0;
+
+ f32 t = vg.time - w->state.jump_input_time;
+ if( t < PLAYER_JUMP_EPSILON ){
+ float d = v3_dot( player->basis[1], player->rb.v );
+ v3_muladds( player->rb.v, player->basis[1], -d, player->rb.v );
+ v3_muladds( player->rb.v, player->basis[1], 5.0f, player->rb.v );
+ w->state.activity = k_walk_activity_air;
+ prev_state = k_walk_activity_air;
+ accel_speed = k_walk_air_accel;
+ nominal_speed = k_airspeed;
+ }
}
else{
player_friction( player->rb.v );
nominal_speed = k_airspeed;
}
- if( v2_length2( srinput.joy_steer ) > 0.001f ){
+ if( v2_length2( steer ) > 0.001f ){
player_accelerate( player->rb.v, movedir, nominal_speed, accel_speed );
v3_normalize( movedir );
}
v3_muladds( player->rb.co, player->rb.v, k_rb_delta, player->rb.co );
v3_add( player->rb.co, player->basis[1], mtx[3] );
- debug_capsule( mtx, w->collider.radius, w->collider.height, VG__GREEN );
+ vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__GREEN );
/*
* CCD routine
rb_update_transform( &player->rb );
v3_add( player->rb.co, player->basis[1], mtx[3] );
- debug_capsule( mtx, w->collider.radius, w->collider.height, VG__RED );
+ vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__RED );
}
}
float substep = vg.time_fixed_extrapolate;
v3_muladds( mtx[3], player->rb.v, k_rb_delta*substep, mtx[3] );
- debug_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW );
+ vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW );
/* Calculate header */
q_normalize( player->rb.q );
}
- vg_line_pt3( w->state.drop_in_target, 0.1f, VG__GREEN );
+ vg_line_point( w->state.drop_in_target, 0.1f, VG__GREEN );
v3f p1;
v3_muladds( w->state.drop_in_target, w->state.drop_in_normal, 0.3f, p1 );
vg_line( w->state.drop_in_target, p1, VG__GREEN );
vg_line( w->state.drop_in_target, p1, VG__GREEN );
vg_line( w->state.drop_in_target, w->state.drop_in_foot_anchor, VG__WHITE );
- vg_line_pt3( w->state.drop_in_foot_anchor, 0.08f, VG__PINK );
+ vg_line_point( w->state.drop_in_foot_anchor, 0.08f, VG__PINK );
float a = player_get_heading_yaw( player );
audio_lock();
if( w->surface == k_surface_prop_concrete ){
audio_oneshot_3d(
- &audio_footsteps[rand()%vg_list_size(audio_footsteps)],
+ &audio_footsteps[vg_randu32()%vg_list_size(audio_footsteps)],
player->rb.co, 40.0f, 1.0f
);
}
else if( w->surface == k_surface_prop_grass ){
audio_oneshot_3d(
- &audio_footsteps_grass[rand()%vg_list_size(audio_footsteps_grass)],
+ &audio_footsteps_grass[vg_randu32()%vg_list_size(audio_footsteps_grass)],
player->rb.co, 40.0f, 1.0f
);
}
else if( w->surface == k_surface_prop_wood ){
audio_oneshot_3d(
- &audio_footsteps_wood[rand()%vg_list_size(audio_footsteps_wood)],
+ &audio_footsteps_wood[vg_randu32()%vg_list_size(audio_footsteps_wood)],
player->rb.co, 40.0f, 1.0f
);
}