Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef BULLETPOOL_H
- #define BULLETPOOL_H
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <vector>
- #include "Bullet.h"
- class BulletPool
- {
- public:
- BulletPool(Bullet, int num) // create a pool with any number of bullets in it
- {
- mCounter = num;
- int i = num;
- while(--i > -1)
- {
- mBullets.push_back(Bullet());
- }
- }
- Bullet GetBullet() // get bullet from the pool
- {
- if(mCounter > 0)
- {
- return mBullets[--mCounter];
- }
- else
- {
- std::cout << "Error: You exhausted the pool!" << '\n';
- }
- return mBullets[mCounter];
- }
- void ReturnBullet(Bullet b) // return the bullet back to the pool
- {
- mBullets[mCounter++] = b;
- }
- private:
- std::vector<Bullet> mBullets;
- int mCounter;
- };
- #endif // BULLETPOOL_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement