Book Image

Beginning C++ Game Programming

Book Image

Beginning C++ Game Programming

Overview of this book

This book is all about offering you a fun introduction to the world of game programming, C++, and the OpenGL-powered SFML using three fun, fully-playable games. These games are an addictive frantic two-button tapper, a multi-level zombie survival shooter, and a split-screen multiplayer puzzle-platformer. We will start with the very basics of programming, such as variables, loops, and conditions and you will become more skillful with each game as you move through the key C++ topics, such as OOP (Object-Orientated Programming), C++ pointers, and an introduction to the Standard Template Library. While building these games, you will also learn exciting game programming concepts like particle effects, directional sound (spatialization), OpenGL programmable Shaders, spawning thousands of objects, and more.
Table of Contents (24 chapters)
Beginning C++ Game Programming
Credits
About the Author
About the Reviewer
www.PacktPub.com
Dedication
Preface
17
Before you go...

Making decisions with if and else


The C++ if and else keywords are what enable us to make decisions. Actually, we have already seen if in action in the previous chapter when we detected, in each frame, whether the player had pressed the Esc  key:

if (Keyboard::isKeyPressed(Keyboard::Escape)) 
{ 
   window.close(); 
} 

So far we have seen how we can use arithmetic and assignment operators to create expressions. Now we can see some new operators.

Logical operators

Logical operators are going to help us make decisions by building expressions that can be tested for a value of either true or false. At first this might seem like quite a narrow choice and insufficient for the kind of choices that might be needed in an advanced PC game. Once we dig a little deeper, we will see that we can actually make all the required decisions we will need, with just a few logical operators.

Here is a table of the most useful logical operators. Take a look at them and their associated examples...