#include #include #include "physics.h" #include "player.h" #define TOP_SPEEDX 100 #define TOP_SPEEDY 100 #define ACCEL_X 40 void add_player(float xpos, float ypos) { struct entity player = { .flags = (ENTITY_ACTIVE | ENTITY_VISIBLE), .type = Player_Entity, .position = (Vector2) {xpos, ypos}, .texture = LoadTexture("assets/Graphics/spritesheet-characters-double.png"), .sprite_source_rect = (Rectangle) { .x = 0, .y = 0, .width = 257, .height = 257 }, .sprite_dest_rect = (Rectangle) { .x = -50, .y = -50, .width = 100, .height = 100 } }; add_entity(&player); } float get_x_acceleration_direction() { if (IsKeyDown(KEY_A)) { return -1.0; } else if (IsKeyDown(KEY_D)) { return 1.0; } return 0.0; } void handle_movement(struct entity* player, float dt) { Vector2 accel = { .x = get_x_acceleration_direction() * ACCEL_X, .y = GRAVITY }; player->velocity = Vector2Add(player->velocity, Vector2Scale(accel, dt * 0.5)); move_and_collide(player, dt); player->velocity = Vector2Add(player->velocity, Vector2Scale(accel, dt * 0.5)); } void handle_input(struct entity* player) { } void update_player(struct entity* player, float dt) { handle_movement(player, dt); handle_input(player); }