spherecast

wip first person shooter engine
Download | Log | Files | Refs

player.h (1292B)


      1 #pragma once
      2 
      3 #include <raylib.h>
      4 
      5 enum Input {
      6   INPUT_FORWARD = 1 << 0,
      7   INPUT_BACKWARD = 1 << 1,
      8   INPUT_LEFT = 1 << 2,
      9   INPUT_RIGHT = 1 << 3,
     10   INPUT_JUMP = 1 << 4,
     11   INPUT_SPRINT = 1 << 5,
     12   INPUT_CROUCH = 1 << 6,
     13 };
     14 
     15 typedef enum { MOVE_WALK, MOVE_SPRINT, MOVE_CROUCH, MOVE_SLIDE } MoveMode;
     16 
     17 typedef struct {
     18   bool move;
     19   bool sprint;
     20   bool crouch;
     21   bool jump;
     22 } PlayerIntent;
     23 
     24 /*
     25  * NOTE: Players will eventually be serialized and networked so everything
     26  * in here should be strictly relevant for interactivity on other clients.
     27  * For example camera data like fov shouldn't be stored here as it's either
     28  * irrelevant data on remote clients or it can be derived from other details
     29  * like velocity or player state.
     30  */
     31 typedef struct {
     32   float height;
     33   float radius;
     34 
     35   float maxSpeed;
     36   float accel;
     37   Vector3 vel;
     38   Vector3 rot;
     39   Vector3 pos;
     40 
     41   MoveMode mode;
     42   bool grounded;
     43 
     44   float groundedTimer;
     45 } Player;
     46 
     47 // void PlayerCollide(Player *p, Triangle *tris, int triCount, float dt);
     48 
     49 void PlayerUpdateState(Player *p, enum Input i, float dt);
     50 
     51 void PlayerApplyAcceleration(Player *p, enum Input i, float dt);
     52 
     53 void PlayerUpdate(Player *p, enum Input i, float dt);
     54 
     55 void PlayerHandleMovement(Player *p, PlayerIntent in);
     56 
     57 void PlayerApplyFriction(Player *p, float dt);