#include #include "player.h" #define DEFAULT_STAND_HEIGHT 6.0f #define DEFAULT_DUCK_HEIGHT 2.5f #define DEFAULT_HEAD_MARGIN 1.0f #define DEFAULT_KNEE_HEIGHT 2.0f void player_default(player_t *player) { player->pos = (struct xyz){0.0f, 0.0f, 0.0f}; player->velocity = (struct xyz){0.0f, 0.0f, 0.0f}; player->angle = 0.0f; player->anglesin = 0.0f; player->anglecos = 1.0f; player->sector = 0; player->stand_height = DEFAULT_STAND_HEIGHT; player->duck_height = DEFAULT_DUCK_HEIGHT; player->head_margin = DEFAULT_HEAD_MARGIN; player->knee_height = DEFAULT_KNEE_HEIGHT; player->ducking = false; } void player_input(player_t *player, bool *input, int rmouse_x, int rmouse_y) { (void)rmouse_y; player->angle += rmouse_x * 0.03f; float move_vec[2] = {0.f, 0.f}; if(input[0]) { move_vec[0] += player->anglecos*0.2f; move_vec[1] += player->anglesin*0.2f; } if(input[2]) { move_vec[0] -= player->anglecos*0.2f; move_vec[1] -= player->anglesin*0.2f; } if(input[1]) { move_vec[0] += player->anglesin*0.2f; move_vec[1] -= player->anglecos*0.2f; } if(input[3]) { move_vec[0] -= player->anglesin*0.2f; move_vec[1] += player->anglecos*0.2f; } if(input[4]) { if(player->velocity.z == 0.0f) player->velocity.z += 0.5f; } player->ducking = input[5]; bool pressing = input[0] || input[1] || input[2] || input[3] || input[4]; float acceleration = pressing ? 0.4f : 0.2f; player->velocity.x = player->velocity.x * (1-acceleration) + move_vec[0] * acceleration; player->velocity.y = player->velocity.y * (1-acceleration) + move_vec[1] * acceleration; player->anglesin = sinf(player->angle); player->anglecos = cosf(player->angle); } void player_update(player_t *player) { player->pos.x += player->velocity.x; player->pos.y += player->velocity.y; player->pos.z += player->velocity.z; }