Game Development Reference
In-Depth Information
bullet, and MoveForward to let the bullet handle moving in the right direction and
updating both the collider and the sprite.
Destroy and Respawn both manage the _isAlive variable and ensure that the
sprite is only visible when the bullet is alive. Bullet::Load will load the texture loc-
ated at textures\bullet.DDS in the same way as the Player or Enemy .
Now we need to integrate the bullet class into the game. As we want the bullet fire
to be continuous we need a different way of caching and managing the bullets. For
this we'll use a pool system, as mentioned earlier. Add the following declarations to
Game.h :
std::list<Bullet*> _bullets;
std::queue<Bullet*> _bulletPool;
Bullet* CreateBullet();
Here we'll use the list to manage the bullets that exist, and the queue to allow us to
cache "dead" bullets that can be reused later. We'll encapsulate this management
functionality inside CreateBullet , which looks like this:
Bullet* Game::CreateBullet()
{
Bullet *b;
if (_bulletPool.size() == 0)
{
b = new Bullet();
b->Damage = 100;
b->Load();
}
else
{
b = _bulletPool.front();
_bulletPool.pop();
}
b->Respawn();
_bullets.push_back(b);
Search WWH ::




Custom Search