Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Beginning C++ Game Programming

You're reading from   Beginning C++ Game Programming Learn C++ from scratch and get started building your very own games

Arrow left icon
Product type Paperback
Published in Oct 2016
Publisher Packt
ISBN-13 9781786466198
Length 520 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
John Horton John Horton
Author Profile Icon John Horton
John Horton
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. C++, SFML, Visual Studio, and Starting the First Game FREE CHAPTER 2. Variables, Operators, and Decisions ā€“ Animating Sprites 3. C++ Strings, SFML Time, Player Input, and HUD 4. Loops, Arrays, Switch, Enumerations, and Functions ā€“ Implementing Game Mechanics 5. Collisions, Sound, and End Conditions ā€“ Making the Game Playable 6. Object-Oriented Programming, Classes, and SFML Views 7. C++ References, Sprite Sheets, and Vertex Arrays 8. Pointers, the Standard Template Library, and Texture Management 9. Collision Detection, Pickups, and Bullets 10. Layering Views and Implementing the HUD 11. Sound Effects, File I/O, and Finishing the Game 12. Abstraction and Code Management ā€“ Making Better Use of OOP 13. Advanced OOP ā€“ Inheritance and Polymorphism 14. Building Playable Levels and Collision Detection 15. Sound Spatialization and HUD 16. Extending SFML Classes, Particle Systems, and Shaders 17. Before you go...

Building the Player-the first class


Let's think about what our Player class will need to do. The class will need to know how fast it can move, where in the game world it currently is, and how much health it has. As the Player class, in the player's eyes, is represented as a 2D graphical character, the class will need both a Sprite and a Texture object.

Furthermore, although the reasons might not be obvious at this point, our Player class will also benefit from knowing a few details about the overall environment the game is running in. These details are screen resolution, the size of the tiles that make up an arena, and the overall size of the current arena.

As the Player class will be taking full responsibility for updating itself each frame, it will need to know the player's intentions at any given moment. For example, is the player currently holding down a particular keyboard direction key? Or is the player currently holding down multiple keyboard direction keys? Boolean variables to determine...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime