Arcade Shooter
ProjectilePool.h
1 
2 /* . ,'`. .
3  . .." _.-;' ⁄‚ `. . `
4  _.-"`.##%"_.--" ,' ⁄` `. "#" ___,,od000
5  ,'"-_ _.-.--"\ ,' `-_ '%#%',,/00000000000
6  ,' |_.' )`/- __..--""`-_`-._ J L/00000000000000
7  . + ,' _.-" / / _-"" `-._`-_/___\///0000 000M
8  .'_.-"" ' :_/_.-' _,`-/__V__\0000 00MMM
9  . _-"" . ' _,/000\ | /000 0MMMMM
10 _-" . ' . . ,/ 000\ | /000000000MMMMM
11  ` Shooter Library ' ,/ 000\|/000000000MMMMMM
12 . © 2017 - Shuriken Studios LLC ,/0 00000|0000000000MMMMMM */
13 
14 #pragma once
15 
16 namespace ShooterLibrary
17 {
18 
21  {
22 
23  public:
24 
29  ProjectilePool(Level *pLevel, bool expands = true)
30  {
31  m_pLevel = pLevel;
32  m_expands = expands;
33  }
34 
35  virtual ~ProjectilePool() { }
36 
43  virtual void Draw(SpriteBatch *pSpriteBatch);
44 
45 
48  void Add(Projectile *pProjectile);
49 
50 
53  template <typename T>
55  {
56  m_projectileIt = m_projectiles.begin();
57  for (; m_projectileIt != m_projectiles.end(); m_projectileIt++)
58  {
59  Projectile *pProjectile = (*m_projectileIt);
60  if (!pProjectile->IsActive()) return pProjectile;
61  }
62 
63  if (m_expands)
64  {
65  T *pT = new T();
66  m_pLevel->AddGameObject(pT);
67  m_projectiles.push_back(pT);
68  return pT;
69  }
70 
71  return nullptr;
72  }
73 
74  private:
75 
76  Level *m_pLevel;
77 
78  bool m_expands;
79 
80  std::vector<Projectile *> m_projectiles;
81  std::vector<Projectile *>::iterator m_projectileIt;
82 
83  };
84 }
Used to recycle projectiles.
Definition: ProjectilePool.h:20
Base class for all shooter levels.
Definition: Level.h:21
virtual void AddGameObject(GameObject *pGameObject)
Adds a game object so it can be managed by the level.
Definition: Level.h:50
Shooter Library is a library of classes, interfaces, and value types that provides a foundation for d...
Definition: Background.h:16
Projectile * GetInactiveProjectile()
Get the next available projectile.
Definition: ProjectilePool.h:54
Base class for all projectile types.
Definition: Projectile.h:20
ProjectilePool(Level *pLevel, bool expands=true)
Instantiate a projectile pool object.
Definition: ProjectilePool.h:29
void Add(Projectile *pProjectile)
Add a projectile to the pool.
Definition: ProjectilePool.cpp:17
virtual bool IsActive() const
Determines if the game object is active.
Definition: GameObject.h:68
virtual void Draw(SpriteBatch *pSpriteBatch)
Renders all of the projectiles in the pool.
Definition: ProjectilePool.cpp:7