Advertisement
Guest User

SlashC++Programmer

a guest
Jul 7th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #ifndef BULLETPOOL_H
  2. #define BULLETPOOL_H
  3.  
  4. #include <iostream>
  5. #include <SFML/Graphics.hpp>
  6. #include <vector>
  7. #include "Bullet.h"
  8.  
  9. class BulletPool
  10. {
  11.     public:
  12.          BulletPool(Bullet, int num) // create a pool with any number of bullets in it
  13.          {
  14.            mCounter = num;
  15.  
  16.            int i = num;
  17.            while(--i > -1)
  18.            {
  19.              mBullets.push_back(Bullet());
  20.            }
  21.          }
  22.  
  23.         Bullet GetBullet() // get bullet from the pool
  24.         {
  25.             if(mCounter > 0)
  26.             {
  27.                 return mBullets[--mCounter];
  28.             }
  29.             else
  30.             {
  31.                 std::cout << "Error: You exhausted the pool!" << '\n';
  32.             }
  33.  
  34.             return mBullets[mCounter];
  35.         }
  36.  
  37.         void ReturnBullet(Bullet b) // return the bullet back to the pool
  38.         {
  39.             mBullets[mCounter++] = b;
  40.         }
  41.  
  42.     private:
  43.         std::vector<Bullet> mBullets;
  44.         int mCounter;
  45.  
  46.  
  47. };
  48.  
  49. #endif // BULLETPOOL_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement