Beginning C++ Game Programming
eBook - ePub

Beginning C++ Game Programming

Learn to program with C++ by building fun games, 2nd Edition

John Horton

Buch teilen
  1. 746 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Beginning C++ Game Programming

Learn to program with C++ by building fun games, 2nd Edition

John Horton

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Get to grips with programming techniques and game development using C++ libraries and Visual Studio 2019

Key Features

  • Learn game development and C++ with a fun, example-driven approach
  • Build clones of popular games such as Timberman, Zombie Survival Shooter, a co-op puzzle platformer, and Space Invaders
  • Discover tips to expand your finished games by thinking critically, technically, and creatively

Book Description

The second edition of Beginning C++ Game Programming is updated and improved to include the latest features of Visual Studio 2019, SFML, and modern C++ programming techniques. With this book, you'll get a fun introduction to game programming by building five fully playable games of increasing complexity. You'll learn to build clones of popular games such as Timberman, Pong, a Zombie survival shooter, a coop puzzle platformer and Space Invaders.

The book starts by covering the basics of programming. You'll study key C++ topics, such as object-oriented programming (OOP) and C++ pointers, and get acquainted with the Standard Template Library (STL). The book helps you learn about collision detection techniques and game physics by building a Pong game. As you build games, you'll also learn exciting game programming concepts such as particle effects, directional sound (spatialization), OpenGL programmable shaders, spawning objects, and much more. Finally, you'll explore game design patterns to enhance your C++ game programming skills.

By the end of the book, you'll have gained the knowledge you need to build your own games with exciting features from scratch

What you will learn

  • Set up your game development project in Visual Studio 2019 and explore C++ libraries such as SFML
  • Explore C++ OOP by building a Pong game
  • Understand core game concepts such as game animation, game physics, collision detection, scorekeeping, and game sound
  • Use classes, inheritance, and references to spawn and control thousands of enemies and shoot rapid-fire machine guns
  • Add advanced features to your game using pointers, references, and the STL
  • Scale and reuse your game code by learning modern game programming design patterns

Who this book is for

This book is perfect for you if you have no C++ programming knowledge, you need a beginner-level refresher course, or you want to learn how to build games or just use games as an engaging way to learn C++. Whether you aspire to publish a game (perhaps on Steam) or just want to impress friends with your creations, you'll find this book useful.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Beginning C++ Game Programming als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Beginning C++ Game Programming von John Horton im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming Games. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2019
ISBN
9781838647650

Chapter 1: C++, SFML, Visual Studio, and Starting the First Game

Welcome to Beginning C++ Game Programming. I will not waste any time in getting you started on your journey to writing great games for the PC using C++ and the OpenGL powered SFML.
This is quite a hefty first chapter, but we will learn absolutely everything we need so that we have the first part of our first game up and running. Here is what we will do in this chapter:
  • Find out about the games we will build
  • Meet C++
  • Find out about Microsoft Visual C++
  • Explore SFML and its relationship with C++
  • Setting up the development environment
  • Plan and prepare for the first game project, Timber!!!
  • Write the first C++ code of this book and make a runnable game that draws a background

The games we will build

This journey will be smooth as we will learn about the fundamentals of the super-fast C++ language one step at a time, and then put this new knowledge to use by adding cool features to the five games we are going to build.
The following are our five projects for this book.

Timber!!!

The first game is an addictive, fast-paced clone of the hugely successful Timberman, which can be found at http://store.steampowered.com/app/398710/. Our game, Timber!!!, will introduce us to all the basics of C++ while we build a genuinely playable game. Here is what our version of the game will look like when we are done and we have added a few last-minute enhancements:

Pong

Pong was one of the first video games to be made, and you can find out about its history here: https://en.wikipedia.org/wiki/Pong. It is an excellent example of how the basics of game object animation and dynamic collision detection work. We will build this simple retro game to explore the concept of classes and object-oriented programming. The player will use the bat at the bottom of the screen and hit the ball back to the top of the screen:

Zombie Arena

Next, we will build a frantic, zombie survival shooter, not unlike the Steam hit Over 9,000 Zombies!, which you can find out more about at http://store.steampowered.com/app/273500/. The player will have a machine gun and must fight off ever-growing waves of zombies. All this will take place in a randomly generated, scrolling world. To achieve this, we will learn about how object-oriented programming allows us to have a large code base (lots of code) that is easy to write and maintain. Expect exciting features such as hundreds of enemies, rapid-fire weaponry, pickups, and a character that can be “leveled up” after each wave:

Thomas was late

The fourth game will be a stylish and challenging single-player and co-op puzzle platformer. It is based on the very popular game Thomas was Alone (http://store.steampowered.com/app/220780/). Expect to learn about cool topics such as particle effects, OpenGL Shaders, and split-screen cooperative multiplayer:
Tip
If you want to play any of the games now, you can do so from the download bundle in the Runnable Games folder. Just double-click on the appropriate .exe file. Note that, in this folder, you can run either the completed games or any game in its partially completed state from any chapter.

Space Invaders ++

The final game will be a Space Invaders clone. In some ways, the game itself is not what is important about this project. The project will be used to learn about game programming patterns. As will become abundantly clear as this book progresses, our code keeps getting longer and more complicated. Each project will introduce one or more techniques for coping with this, but the complexity and length of our code will keep coming back to challenge us, despite these techniques.
The Space Invaders project (called Space Invaders ++) will show us ways in which we can radically reorganize our game code also that we can take control of and properly manage our code once and for all. This will leave you with all the knowledge you need to plan and build deep, complex, and innovative games, without ending up in a tangle of code.
The game will also introduce concepts such as screens, input handlers, and entity-component systems. It will also allow us to learn how to let the player use a gamepad instead of the keyboard and introduce the C++ concepts of smart pointers, casts, assertions, breakpoint debugging, and teach us the most important lesson from the whole book: how to build your own unique games:
Let’s get started by introducing C++, Visual Studio, and SFML!

Meet C++

Now that we know what games we will be building, let’s get started by introducing C++, Visual Studio, and SFML. One question you might have is, why use the C++ language at all? C++ is fast – very fast. What makes this true is the fact that the code that we write is directly translated into machine-executable instructions. These instructions are what make the game. The executable game is contained within a .exe file, which the player can simply double-click to run.
There are a few steps in the process of changing our code into an executable file. First, the preprocessor looks to see if any other code needs to be included within our own code and adds it. Next, all the code is compiled into object files by the compiler program. Finally, a third program, called the linker, joins all the object files into the executable file for our game.
In addition, C++ is well established at the same time as being extremely up to date. C++ is an object-oriented programming (OOP) language, which means we can write and organize our code using well-tested conventions that make our games efficient and manageable. The benefits as well as the necessity of this will reveal themselves as we progress through this book.
Most of this other code that I referred to, as you might be able to guess, is SFML, and we will find out more about SFML in just a minute. The preprocessor, compiler, and linker programs I have just mentioned are all part of the Visual Studio integrated development environment (IDE).

Microsoft Visual Studio

Visual Studio hides away the complexity of preprocessing, compiling, and linking. It wraps it all up into the press of a button. In addition to this, it provides a slick user interface for us to type our code into and manage what will become a large selection of code files and other project assets as well.
While there are advanced versions of Visual Studio that cost hundreds of dollars, we will be able to build all five of our games in the free “Express 2019 for Community” version. This is the latest free version of Visual Studio.

SFML

SFML is the Simple Fast Media Library. It is not the only C++ library for games and multimedia. It is possible to make an argument to use other libraries, but SFML seems to come through for me every time. Firstly, it is written using object-oriented C++. The benefits of object-oriented C++ are numerous, and you will experience them as you pr...

Inhaltsverzeichnis