ebook img

Learning C++ by creating games with UE4 PDF

524 Pages·2015·12.479 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learning C++ by creating games with UE4

Learning C++ by Creating Games with UE4 Table of Contents Learning C++ by Creating Games with UE4 Credits About the Author About the Reviewers www.PacktPub.com Support files, eBooks, discount offers, and more Why subscribe? Free access for Packt account holders Preface What is a game engine anyway? What will using UE4 cost me? Why don’t I just program my own engine and save the 5 percent? A game’s overview – the Play-Reward-Growth loop Monetization Why C++ What this book covers What you need for this book Who this book is for Conventions Reader feedback Customer support Downloading the example code Downloading the color images of this book Errata Piracy Questions 1. Coding with C++ Setting up our project Using Microsoft Visual C++ on Windows Using XCode on a Mac Creating your first C++ program Semicolons Handling errors Warnings What is building and compiling? Scripting Exercise – ASCII art Summary 2. Variables and Memory Variables Declaring variables – touching the silicon Reading and writing to your reserved spot in memory Numbers are everything More on variables Math in C++ Exercises Generalized variable syntax Primitive types Object types Exercise – Player Solution Pointers What can pointers do? Address of operator & The Null pointers cin printf() Exercise Solution Summary 3. If, Else, and Switch Branching Controlling the flow of your program The == operator Coding if statements Coding else statements Testing for inequalities using other comparison operators (>, >=, <, <=, and !=) Using logical operators The Not (!) operator Exercises Solution The And (&&) operator The Or (||) operator Our first example with Unreal Engine Exercise Solution Branching code in more than two ways The else if statement Exercise Solution The switch statement Switch versus if Exercise Solution Summary 4. Looping The while loop Infinite loops Exercises Solutions The do/while loop The for loop Exercises Solutions Looping with Unreal Engine Summary 5. Functions and Macros Functions An example of a <cmath> library function – sqrt() Writing our own functions A sample program trace Exercise Solution Functions with arguments Functions that return values Exercises Solutions Variables, revisited Global variables Local variables The scope of a variable Static local variables Const variables Function prototypes .h and .cpp files prototypes.h contains funcs.cpp contains main.cpp contains Extern variables Macros Advice – try to use const variables where possible Macros with arguments Advice – use inline functions instead of macros with arguments Summary 6. Objects, Classes, and Inheritance struct objects Member functions The this keyword Strings are objects? Invoking a member function Exercises Solutions Privates and encapsulation Some people like it public class versus struct Getters and setters Getters Setters But what’s the point of get/set operations? Constructors and destructors Class inheritance Derived classes Syntax of inheritance What does inheritance do? is-a relationship protected variables Virtual functions Purely virtual functions (and abstract classes) Multiple inheritance private inheritance Putting your classes into headers .h and .cpp Exercise Summary 7. Dynamic Memory Allocation Dynamic memory allocation The delete keyword Memory leaks Regular arrays The array syntax Exercise Solutions C++ style dynamic size arrays (new[] and delete[]) Dynamic C-style arrays Summary 8. Actors and Pawns Actors versus pawns Creating a world to put your actors in The UE4 editor Editor controls Play mode controls Adding objects to the scene Starting from scratch Adding light sources Collision volumes Adding collision detection for the objects editor Adding an actor to the scene Creating a player entity Inheriting from UE4 GameFramework classes Associating a model with the Avatar class Downloading free models Loading the mesh Creating a blueprint from our C++ class Writing C++ code that controls the game’s character Making the player an instance of the Avatar class Setting up controller inputs Exercise Solution Yaw and pitch Creating non-player character entities Displaying a quote from each NPC dialog box Displaying messages on the HUD Using TArray<Message> Exercise Solution Triggering an event when it is near an NPC Make the NPC display something to the HUD when something is nearby Exercises Solutions Summary 9. Templates and Commonly Used Containers Debugging the output in UE4 UE4’s TArray<T> An example that uses TArray<T> Iterating a TArray The vanilla for loop and square brackets notation Iterators Finding whether an element is in the TArray TSet<T> Iterating a TSet Intersecting TSet Unioning TSet Finding TSet TMap<T, S> A list of items for the player’s inventory

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.