Wolf3D
player.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #include "enemy.hpp"
14 #include "global.hpp"
15 #include "pistol.hpp"
16 #include "renderwindow.hpp"
17 #include "sample.hpp"
18 
19 class Player {
20  public:
21  //
37  Player(RenderWindow *window, double *position_x, double *position_y, double *direction_x, double *direction_y, double *plane_x, double *plane_y, std::vector<std::vector<int>> *world_map, json *sprite, std::vector<Enemy *> *enemies);
38  ~Player();
39 
46  void handle_input(const Uint8 *inkeys, double frameTime);
47 
52  void render();
53 
59  double get_health();
60 
65  void hit();
66 
72  void hit(double damage);
73 
79  void buffer_damage(double damage);
80 
85  void clear_buffer_damage();
86 
92  double *get_position_x();
93 
99  double *get_position_y();
100 
106  std::vector<std::vector<int>> *get_world_map();
107 
108 
109  private:
110  // The controller and it's haptic feedback
111  SDL_GameController *controller = NULL;
112  SDL_Haptic *haptic = NULL;
113  // How much the stick needs to move before it's considered an input
114  double controller_tolerance = 0.3;
115  // How much the trigger needs to be pressed before it's considered a click 0-1
116  double controller_trigger_tolerance = 0.5;
117  // When left stick clicked, how much of a speed multiplier
118  double speed_multiplier = 2;
119 
120  // Player's Position, Direction, and Camera Plane
121  double *position_x;
122  double *position_y;
123  double *direction_x;
124  double *direction_y;
125  double *plane_x;
126  double *plane_y;
127 
128  // Player health
129  double health = 100;
130  double damage_buffer = 0;
131  // Sample for death sound effect
132  Sample *sound_player_die;
133  // Vector of Samples for pain sound effects
134  std::vector<Sample *> sound_player_pain;
135 
136  // Used for timing for displaying the border and sound effect
137  bool taking_damage = false;
138 
139  // Timer variables
140  double previous_time = 0.0;
141  double time = 0.0;
142  double pain_timer = 0.0;
143 
144  // The world map vector
145  std::vector<std::vector<int>> *world_map;
146  // "Vector" of the sprites
147  json *sprite;
148  // Vector of the enemies
149  std::vector<Enemy *> *enemies;
150  // The renderer
151  RenderWindow *window;
152  // Pistol Weapon
153  Pistol *pistol = nullptr;
154 };
Definition: pistol.hpp:18
Definition: player.hpp:19
std::vector< std::vector< int > > * get_world_map()
Get the world map.
Definition: player.cpp:287
double get_health()
Get the Player's health.
Definition: player.cpp:255
double * get_position_x()
Get the Player's position x.
Definition: player.cpp:281
void clear_buffer_damage()
Clear the accumulated damage.
Definition: player.cpp:277
double * get_position_y()
Get the Player's position y.
Definition: player.cpp:284
void hit()
Removes the buffered damage from the Player's health, plays the hurt sound effect and displays a red ...
Definition: player.cpp:259
Player(RenderWindow *window, double *position_x, double *position_y, double *direction_x, double *direction_y, double *plane_x, double *plane_y, std::vector< std::vector< int >> *world_map, json *sprite, std::vector< Enemy * > *enemies)
Construct the Player object.
Definition: player.cpp:3
void handle_input(const Uint8 *inkeys, double frameTime)
Handles the input for the Player, uses both keyboard and a controller.
Definition: player.cpp:68
void buffer_damage(double damage)
Accumulates damage which can be then dealt with hit()
Definition: player.cpp:274
void render()
Renders the Player's elements and it's children's elements.
Definition: player.cpp:234
Definition: renderwindow.hpp:16
Definition: sample.hpp:18
Contains the header functions for the Enemy Class.
Contains the header functions for the Pistol Class.
Contains the header functions for the RenderWindow Class.
Contains the header functions for the Enemy Class.