Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
C++ Game Development By Example

You're reading from  C++ Game Development By Example

Product type Book
Published in May 2019
Publisher Packt
ISBN-13 9781789535303
Pages 420 pages
Edition 1st Edition
Languages
Author (1):
Siddharth Shekar Siddharth Shekar
Profile icon Siddharth Shekar
Toc

Table of Contents (18) Chapters close

Preface 1. Section 1: Basic Concepts
2. C++ Concepts 3. Mathematics and Graphics Concepts 4. Section 2: SFML 2D Game Development
5. Setting Up Your Game 6. Creating Your Game 7. Finalizing Your Game 8. Section 3: Modern OpenGL 3D Game Development
9. Getting Started with OpenGL 10. Building on the Game Objects 11. Enhancing Your Game with Collision, Loops, and Lighting 12. Section 4: Rendering 3D Objects with Vulkan
13. Getting Started with Vulkan 14. Preparing the Clear Screen 15. Creating Object Resources 16. Drawing Vulkan Objects 17. Other Books You May Enjoy

Creating the Enemy class

The player character looks very lonely. She is ready to cause some mayhem, but there is nothing to shoot right now. Let's add some enemies to solve this problem:

  1. The enemies will be created using an enemy class; let's create a new class and call it Enemy.
  2. Just like the Hero class, the Enemy class will have a .h file and a .cpp file. In the Enemy.h file, add the following code:
#pragma once 
#include "SFML-2.5.1\include\SFML\Graphics.hpp" 
 
class Enemy 
{ 
public: 
   Enemy(); 
   ~Enemy(); 
 
 
   void init(std::string textureName, sf::Vector2f position, 
float_speed); void update(float dt); sf::Sprite getSprite(); private: sf::Texture m_texture; sf::Sprite m_sprite; sf::Vector2f m_position; float m_speed; };

Here, the Enemy class, just like the Hero class, also has a constructor and destructor...

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 €14.99/month. Cancel anytime