Advertisement
Kitomas

player.hpp as of 2024-03-29

Mar 29th, 2024 (edited)
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #ifndef _PLAYER_HPP
  2. #define _PLAYER_HPP
  3.  
  4. #include <globals.hpp>
  5.  
  6.  
  7.  
  8.  
  9.  
  10. struct Player {
  11.   SoundEffect* sfx_footstep = nullptr;
  12.   SoundEffect* sfx_jumping  = nullptr;
  13.   SoundEffect* sfx_landing  = nullptr;
  14.  
  15.   kit::shape::fpoint pos; //the player's CENTER position, in pixels
  16.   kit::shape::fpoint vel; //how many pixels to move pos by
  17.   kit::shape::fpoint acc; //how many pixels to change vel by
  18.  
  19.   kit::u32 ticksInAir = 0; //game ticks, which are 1/4 a frame long (approx. 4.1ms)
  20.  
  21.   kit::f32 runningState = 0.0f; //current animation frame when running
  22.  
  23.   bool gc_sfx        = true; //'garbage collect sound effects?'
  24.   bool facingRight   = true;
  25.   bool visible       = true;
  26.   bool enforceMaxVel = true;
  27.   bool confused      = false;
  28.   bool jumped        = false;
  29.   bool footstep      = false; //used to sync footstep sound effects
  30.  
  31.   char _[1];
  32.  
  33.  
  34.  
  35.   Player(kit::f32 startX = 0.0f, kit::f32 startY = 0.0f) : pos(startX, startY) {}
  36.  
  37.   ~Player(){
  38.     if(gc_sfx){
  39.       if(sfx_footstep) delete sfx_footstep;
  40.       if(sfx_jumping ) delete sfx_jumping;
  41.       if(sfx_landing ) delete sfx_landing;
  42.     }
  43.   }
  44.  
  45.  
  46.   void blit(kit::f32 scaleX = 1.0f, kit::f32 scaleY = 1.0f);
  47.  
  48.   void update(); //advance animation by 1 frame
  49.  
  50.  
  51.   bool queryFootstep(){ //resets the footstep flag after reading it
  52.     bool state = footstep;
  53.     footstep = false;
  54.     return state;
  55.   }
  56. };
  57.  
  58.  
  59.  
  60.  
  61.  
  62. #endif /* _PLAYER_HPP */
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement