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

Preparing the player (and other sprites)


Let's add the code for the player's sprite, as well as a few more sprites and textures at the same time. This next, quite large, block of code also adds a gravestone sprite for when the player gets squished, an ax sprite to chop with, and a log sprite that can whiz away each time the player chops.

Notice that after the spritePlayer object we also declare a side variable, playerSide, to keep track of where the player is currently standing. Furthermore, we add some extra variables for the spriteLog object, including, logSpeedX, logSpeedY, and logActive to store how fast the log will move, and whether it is currently moving. The spriteAxe also has two related float constant variables to remember where the ideal pixel position is on both the left and the right.

Add this next block of code just before the while(window.isOpen()) code as we have done so often before. Note that all the code in this next listing is new, not just the highlighted code. I haven...