-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectileManager.h
More file actions
140 lines (122 loc) · 4.34 KB
/
projectileManager.h
File metadata and controls
140 lines (122 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef PROJECTILE_MANAGER_H
#define PROJECTILE_MANAGER_H
#include <vector>
#include <random>
#include "projectile.h"
#include "projectiles/apple.h"
#include "projectiles/orange.h"
#include "projectiles/corn.h"
#include "projectiles/banana.h"
/**
* @class ProjectileManager
* @brief Manages all projectiles in Slice Defender (creation, update, cleanup, and slicing).
*
* Handles the lifecycle of projectiles, including launching, updating, drawing, collision detection,
* and slicing logic. Also manages cannon configuration and statistics for projectiles launched.
*
* @author: Aubin SIONVILLE, Estevan SCHMITT
*/
class ProjectileManager
{
public:
/**
* @brief Constructor. Initializes the projectile manager and random generator.
*/
ProjectileManager();
/**
* @brief Destructor. Cleans up all projectiles.
*/
~ProjectileManager();
/**
* @brief Updates all projectiles (movement, state, etc.).
* @param deltaTime Time elapsed since last update (in seconds)
*/
void update(float deltaTime);
/**
* @brief Draws all active projectiles.
*/
void draw();
/**
* @brief Launches a random projectile from the cannon.
*/
void launchProjectile();
/**
* @brief Creates and adds a specific type of projectile.
* @tparam T Projectile type
* @tparam Args Constructor arguments
* @param args Arguments to forward to the projectile constructor
*/
template <typename T, typename... Args>
void createProjectile(Args &&...args);
/**
* @brief Removes inactive projectiles from the manager.
*/
void cleanupProjectiles();
/**
* @brief Clears all projectiles (for game reset).
*/
void clearProjectiles();
/**
* @brief Sets the position of the cannon.
* @param position Array of 3 floats [x, y, z]
*/
void setCannonPosition(const float position[3]);
/**
* @brief Sets the direction of the cannon.
* @param direction Array of 3 floats [dx, dy, dz]
*/
void setCannonDirection(const float direction[3]);
/**
* @brief Sets the initial speed for launched projectiles.
* @param speed Initial speed value
*/
void setInitialSpeed(float speed);
/**
* @brief Adds a new projectile to the manager.
* @param projectile Pointer to the projectile to add
*/
void addProjectile(Projectile *projectile);
/**
* @brief Checks all projectiles for slicing and handles split logic.
*/
void checkProjectilesForSlicing();
/**
* @brief Returns a reference to the vector of projectiles (for collision detection, etc.).
* @return Reference to the vector of projectile pointers
*/
std::vector<Projectile *> &getProjectiles() { return m_projectiles; }
/**
* @brief Sets whether the game is actively running (controls launching).
* @param active True if the game is active
*/
void setGameActive(bool active) { m_gameActive = active; }
/**
* @brief Sets the Game instance to be passed to projectiles.
* @param game Pointer to the game instance
*/
void setGame(Game *game) { m_game = game; }
/**
* @brief Returns the number of projectiles launched.
* @return Number of projectiles launched
*/
int getProjectilesLaunched() const { return m_projectilesLaunched; }
/**
* @brief Resets the projectile launch statistics.
*/
void resetStats() { m_projectilesLaunched = 0; }
private:
std::vector<Projectile *> m_projectiles; // Active projectiles
float m_timeSinceLastLaunch; // Time since the last projectile was launched
static constexpr float LAUNCH_INTERVAL = 2.0f; // Launch interval (seconds)
bool m_gameActive = false; // Flag to indicate if the game is active
int m_projectilesLaunched = 0; // Number of projectiles launched
Game *m_game = nullptr; // Reference to the game instance
// Cannon properties
float m_cannonPosition[3]; // Cannon position in world coordinates
float m_cannonDirection[3]; // Cannon direction vector
float m_initialProjectileSpeed; // Initial speed of launched projectiles
// Random number generator
std::mt19937 m_rng; // Mersenne Twister random number generator
std::uniform_int_distribution<int> m_projectileTypeDist{0, 4}; // Distribution for projectile type selection
};
#endif // PROJECTILE_MANAGER_H