Book Image

C++ Game Development By Example

By : Siddharth Shekar
Book Image

C++ Game Development By Example

By: Siddharth Shekar

Overview of this book

Although numerous languages are currently being used to develop games, C++ remains the standard for fabricating expert libraries and tool chains for game development. This book introduces you to the world of game development with C++. C++ Game Development By Example starts by touching upon the basic concepts of math, programming, and computer graphics and creating a simple side-scrolling action 2D game. You'll build a solid foundation by studying basic game concepts such as creating game loops, rendering 2D game scenes using SFML, 2D sprite creation and animation, and collision detection. The book will help you advance to creating a 3D physics puzzle game using modern OpenGL and the Bullet physics engine. You'll understand the graphics pipeline, which entails creating 3D objects using vertex and index buffers and rendering them to the scene using vertex and fragment shaders. Finally, you'll create a basic project using the Vulkan library that'll help you get to grips with creating swap chains, image views, render passes, and frame buffers for building high-performance graphics in your games. By the end of this book, you’ll be ready with 3 compelling projects created with SFML, the Vulkan API, and OpenGL, and you'll be able take your game and graphics programming skills to the next level.
Table of Contents (18 chapters)
Free Chapter
1
Section 1: Basic Concepts
4
Section 2: SFML 2D Game Development
8
Section 3: Modern OpenGL 3D Game Development
12
Section 4: Rendering 3D Objects with Vulkan

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...