Search icon CANCEL
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 by building fun games

Arrow left icon
Product type Paperback
Published in May 2024
Publisher Packt
ISBN-13 9781835081747
Length 648 pages
Edition 3rd Edition
Languages
Tools
Concepts
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 (24) Chapters Close

Preface 1. Welcome to Beginning C++ Game Programming Third Edition! 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 – Starting the Pong Game 7. AABB Collision Detection and Physics – Finishing the Pong Game 8. SFML Views – Starting the Zombie Shooter Game 9. C++ References, Sprite Sheets, and Vertex Arrays 10. Pointers, the Standard Template Library, and Texture Management 11. Coding the TextureHolder Class and Building a Horde of Zombies 12. Collision Detection, Pickups, and Bullets 13. Layering Views and Implementing the HUD 14. Sound Effects, File I/O, and Finishing the Game 15. Run! 16. Sound, Game Logic, Inter-Object Communication, and the Player 17. Graphics, Cameras, Action 18. Coding the Platforms, Player Animations, and Controls 19. Building the Menu and Making It Rain 20. Fireballs and Spatialization 21. Parallax Backgrounds and Shaders 22. Other Books You May Enjoy
23. Index

Coding the factory to use all our new classes

The Factory is an important class. It will be where we create all our smart pointers to derived Update and Graphics instances. We will call all the constructors and assemble function implementations while sharing the various required pointers that we have been coding. For example, the Factory is where we will share the pointer to the player and the position of the platforms with the LevelUpdate instance.

Remembering the texture coordinates

First of all, we will add code to the Factory.h file. In the Factory.h file, add the following variables to the private section:

  const int PLAYER_TEX_LEFT = 0;
  const int PLAYER_TEX_TOP = 0;
  const int PLAYER_TEX_WIDTH = 80;
  const int PLAYER_TEX_HEIGHT = 96;
  const float CAM_VIEW_WIDTH = 300.f;
  const float CAM_SCREEN_RATIO_LEFT = 0.f;
  const float CAM_SCREEN_RATIO_TOP = 0.f;
  const float CAM_SCREEN_RATIO_WIDTH = 1.f;
  const float CAM_SCREEN_RATIO_HEIGHT = 1.f;
  const int CAM_TEX_LEFT...
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 €18.99/month. Cancel anytime