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
SFML Blueprints

You're reading from   SFML Blueprints Sharpen your game development skills and improve your C++ and SFML knowledge with five exciting projects

Arrow left icon
Product type Paperback
Published in May 2015
Publisher Packt
ISBN-13 9781784398477
Length 298 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

General structure of a game

Before starting to build randomly and without any specific planning, we need to have some information: what kind of game you want to build (RPG, FPS, or action-adventure), what elements will be used, and so on. The aim of this chapter is to understand the general game structure, which can be used in any kind of game. Through this part, we will study:

  • The game class
  • The frame rate
  • The player class
  • Event management

The game class

In the previous chapter, we have seen the minimal code required for a game, which contains:

  • Window creation
  • Creation of graphic display
  • Handle user inputs
  • Deal with the user inputs
  • Display game objects on the screen

Instead of having one function do all the work, we will make use of object-oriented practices and define various states in different functions. Moreover, we will encapsulate the methods in a new class named Game, and we will minimize the main function. This Game class will be the starting point for all our future games:

class Game
{
...
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