Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Windows 8 Game Development

You're reading from   Learning Windows 8 Game Development Windows 8 brings touchscreens to the tablet and PC. This book will show you how to develop games for both by following clear, hands-on examples. Takes your C++ skills into exciting areas of 3D development.

Arrow left icon
Product type Paperback
Published in Oct 2013
Publisher Packt
ISBN-13 9781849697446
Length 244 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Michael Quandt Michael Quandt
Author Profile Icon Michael Quandt
Michael Quandt
Arrow right icon
View More author details
Toc

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 for the bullet so that we can display it and easily check for collisions with the enemy. We use SetPosition to set the initial position when we spawn the bullet, and MoveForward to let the bullet...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime