#include "player.h" #include #include void player_accelerate(struct Player *player, int dir_x, int dir_y, float delta) { double vel_x = player->vel_x + dir_x * delta * player->accel_x; double vel_y = player->vel_y + dir_y * delta * player->accel_y; if (vel_x > player->max_vel_x) vel_x = player->max_vel_x; if (vel_x < -player->max_vel_x) vel_x = -player->max_vel_x; if (vel_y > player->max_vel_y) vel_y = player->max_vel_y; if (vel_y < -player->max_vel_y) vel_y = -player->max_vel_y; player->vel_x = vel_x; player->vel_y = vel_y; } // TODO: field boundaries void player_move(struct Player *player, enum Direction direction, float delta) { if (direction == UP) { player->pos_y -= player->vel_y * delta; for (int i = 0; i < player->geometry_len; i++) { player->geometry[i].position.y -= player->vel_y * delta; } } if (direction == DOWN) { player->pos_y += player->vel_y * delta; for (int i = 0; i < player->geometry_len; i++) { player->geometry[i].position.y += player->vel_y * delta; } } if (direction == LEFT) { player->pos_x -= player->vel_x * delta; for (int i = 0; i < player->geometry_len; i++) { player->geometry[i].position.x -= player->vel_x * delta; } } if (direction == RIGHT) { player->pos_x += player->vel_x * delta; for (int i = 0; i < player->geometry_len; i++) { player->geometry[i].position.x += player->vel_x * delta; } } }