O'Reilly logo

Learning Windows 8 Game Development by Michael Quandt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fighting for score

We've got a lot in place; now we just need to put these parts together in another way to add in some more gameplay, in the form of bullets that will be fired at the enemy.

Let's begin by creating a Bullet class; this will allow us to control the movement of the bullet and easily manage lifetime and damage.

class Bullet
{
private:
  RectangleCollider *_collider;
  std::shared_ptr<Sprite> _sprite;
  bool _isAlive;

public:
  int Damage;

  Bullet();
  ~Bullet();

  void Load();

  RectangleCollider* GetCollider() { return _collider; }

  void SetPosition(XMFLOAT2 topleft);
  void MoveForward(float deltaTime);

  void Destroy();
  void Respawn();
  bool GetIsAlive();
};

There's quite a bit in here, but most of it you have seen before. We need a Sprite and a collider ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required