Wolf3D
weapon.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #include "enemy.hpp"
14 #include "global.hpp"
15 #include "renderwindow.hpp"
16 #include "sample.hpp"
17 
18 class Weapon {
19  public:
20  //
25  Weapon();
26 
32  int get_magazine();
33 
39  void set_magazine(int value);
40 
46  int get_capacity();
47 
53  void set_capacity(int value);
54 
63  void set_weapon_specifications(std::vector<SDL_Texture *> texture, int fire_frame = 3, int fire_cooldown = 0.75, int max_fire_distance = 6);
64 
70  void set_audio(Sample *sample);
71 
86  void fire(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, SDL_Haptic *haptic = NULL);
87 
93  void render(RenderWindow *window);
94 
95  private:
96  // Sound effect for when the Weapon fires
97  Sample *weapon_sample = NULL;
98  // The vector of the frames of the Weapon
99  std::vector<SDL_Texture *> weapon_texture;
100  // Frame for controlling the weapon_texture index
101  int frame = 0;
102  // Frame for when the Weapon has "fired", example for when the muzzle flash appears
103  int fire_frame = 3;
104  // How long in seconds before the Weapon can fire again
105  int fire_cooldown = 0.75;
106  // The Weapon's maximum fire range
107  int max_fire_distance = 6;
108  // Timer to control the Weapon's fire cooldown
109  double fire_timer = 0.0;
110  // Decremental timer for displaying the Weapon frames on the window
111  int timer = 3;
112  // Used to control whether to start the Weapon's fire frame sequence
113  bool fired = false;
114  // Used to prevent the sample playing multiple times per frame
115  bool weapon_sample_complete = true;
116  // Timer variables
117  double time = 0;
118  double previous_time = 0;
119  // The Weapon's damage
120  double damage = 40;
121 };
Definition: renderwindow.hpp:16
Definition: sample.hpp:18
Definition: weapon.hpp:18
void set_weapon_specifications(std::vector< SDL_Texture * > texture, int fire_frame=3, int fire_cooldown=0.75, int max_fire_distance=6)
Set the Weapon's specifications.
Definition: weapon.cpp:8
void fire(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, SDL_Haptic *haptic=NULL)
Fire the Weapon.
Definition: weapon.cpp:49
void set_magazine(int value)
Set the Weapon's magazine.
Weapon()
Construct the Weapon object.
Definition: weapon.cpp:5
void render(RenderWindow *window)
Render the weapon to the renderer.
Definition: weapon.cpp:19
int get_capacity()
Get the Weapon's capacity (clip)
void set_capacity(int value)
Set the Weapon's capacity (clip)
void set_audio(Sample *sample)
Set the Weapon's fire sound effect.
Definition: weapon.cpp:15
int get_magazine()
Get the Weapon's magazine.
Contains the header functions for the Enemy Class.
Contains the header functions for the RenderWindow Class.
Contains the header functions for the Enemy Class.