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

Adding an enemy

Before we add an enemy to the scene, let's clean up our code a little bit and create a new function called addRigidBodies in main.cpp so that all the rigid bodies will be created in a single function. To do so, follow these steps:

  1. In the source of the main.cpp file, create a new function called addRigidBodies above the main() function.
  1. Add the following code to the addRigidBodies function. This will add the sphere and ground. We are doing this instead of putting all the game code in the main() function:
   // Sphere Rigid Body 
 
   btCollisionShape* sphereShape = new btSphereShape(1); 
   btDefaultMotionState* sphereMotionState = new 
btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1),
btVector3(0, 0.5, 0))); btScalar mass = 13.0f; btVector3 sphereInertia(0, 0, 0); sphereShape->calculateLocalInertia(mass, sphereInertia...
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