O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

SFML Blueprints

Book Description

Sharpen your game development skills and improve your C++ and SFML knowledge with five exciting projects

In Detail

SFML is a cross-platform software development library written in C++ with bindings available for many programming languages. This book contains useful information that you'll need to create any kind of 2D games. Starting with the basics of game programming, resource management, and building simple 2D games, you'll then delve into more complex features such as the physics engine, constructing a game UI, and more advanced concepts of 2D gaming using SFML. You'll develop advanced functionality in your game using the concept of multithreading and learn how various threads interact. In later chapters, you'll quickly grasp the usage and implementation of isometric views and image transformation in your 2D real time tower defense game. You'll wrap up by adding networking and database management systems to your game with SQLite using an ORM.

What You Will Learn

  • Build a complete game and integrate advanced features by adding a multiplayer layer
  • Get to grips with SFML resources and build a generic and reusable resource manager
  • Gather knowledge about different entity models and build your own 2D games
  • Explore the Box2D engine and add physics properties to your game
  • Add a nice user interface to your game to make it more user friendly
  • Discover the SFGUI library and learn how to customize your game
  • Delve into the importance of multithreading and boost your code
  • Add networking and learn about serialization and database management using Sqlite3

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. SFML Blueprints
    1. Table of Contents
    2. SFML Blueprints
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Preparing the Environment
      1. C++11
      2. SFML
      3. Installation of a C++11 compiler
        1. For Linux users
        2. For Mac users
        3. For Windows users
        4. For all users
      4. Installing CMake
        1. For Linux users
        2. For other operating systems
      5. Installing SFML 2.2
        1. Building SFML yourself
          1. Installing dependencies
          2. Linux
          3. Other operating systems
          4. Compilation of SFML
            1. Linux
            2. Windows
        2. Code::Blocks and SFML
        3. A minimal example
      6. Summary
    9. 2. General Game Architecture, User Inputs, and Resource Management
      1. General structure of a game
        1. The game class
        2. Game loops
          1. The frame rate
            1. Fixed time steps
            2. Variable time steps
            3. Minimum time steps
        3. Move our player
          1. The player class
      2. Managing user inputs
        1. Polling events
        2. Real-time events
        3. Handling user inputs
        4. Using the Action class
        5. Action target
        6. Event map
        7. Back to action target
      3. Keeping track of resources
        1. Resources in SFML
          1. The texture class
          2. The image class
          3. The font class
          4. The shader class
          5. The sound buffer class
          6. The music class
        2. Use case
        3. RAII idiom
        4. Building a resources manager
        5. Changing the player's skin
      4. Summary
    10. 3. Making an Entire 2D Game
      1. Turning our application to an Asteroid clone
        1. The Player class
        2. The levels
        3. The enemies
        4. The meteors
        5. The flying saucers
      2. Modifying our application
        1. The World class
        2. The hierarchical entity system
        3. The entity component system
      3. Designing our game
        1. Prepare the collisions
        2. The Entity class
        3. The Player class
        4. The Enemy class
        5. The Saucer class
        6. The Meteor class
        7. The Shoot class
      4. Building a Tetris clone
        1. The Stats class
        2. The Piece class
        3. The Board class
        4. The Game class
      5. Summary
    11. 4. Playing with Physics
      1. A physics engine – késako?
        1. 3D physics engines
        2. 2D physics engines
      2. Physics engine comparing game engine
      3. Using Box2D
        1. Preparing Box2D
          1. Build
          2. Install
      4. Pairing Box2D and SFML
        1. Box2D, how does it work?
      5. Adding physics to a game
        1. The Piece class
        2. The World class
        3. The Game class
        4. The Stats class
      6. Summary
    12. 5. Playing with User Interfaces
      1. What is a GUI?
        1. Creating a GUI from scratch
        2. Class hierarchy
          1. The Widget class
          2. The Label class
          3. The Button class
          4. The TextButton class
          5. The Container class
          6. The Frame class
          7. The Layout class
          8. The VLayout class
      2. Adding a menu to the game
        1. Building the main menu
        2. Building the pause menu
        3. Building the configuration menu
      3. Using SFGUI
        1. Installing SFGUI
        2. Using the features of SFGUI
        3. Building the starting level
      4. Summary
    13. 6. Boost Your Code Using Multithreading
      1. What is multithreading?
        1. The fork() function
        2. The exec() family functions
      2. Thread functionality
        1. Why do we need to use the thread functionality?
        2. Using threads
      3. Adding multithreading to our games
      4. Summary
    14. 7. Building a Real-time Tower Defense Game from Scratch – Part 1
      1. The goal of the game
      2. Building animations
        1. The Animation class
        2. The AnimatedSprite class
        3. A usage example
      3. Building a generic Tile Map
        1. The Geometry class as an isometric hexagon
        2. VLayer and Layer classes
        3. VMap and Map classes
        4. Dynamic board loading
        5. The MapViewer class
        6. A usage example
      4. Building an entity system
        1. Use of the entity system
        2. Advantages of the entity system approach
      5. Building the game logic
        1. Building our components
        2. Creating the different systems
        3. The level class
        4. The game class
        5. The Team GUI class
      6. Summary
    15. 8. Build a Real-time Tower Defense Game from Scratch – Part 2, Networking
      1. Network architectures
        1. Peer-to-peer architecture
        2. Client-server architecture
          1. Client
          2. Server
      2. Network communication using sockets
        1. UDP
        2. TCP
        3. Selector
        4. The Connection class
          1. The goal of the Connection class
      3. Creating a communication protocol
        1. Using the sf::Packet class
        2. RPC-like protocol
        3. The NetworkEvent class
      4. Modifying our game
        1. Server
          1. Building the Server entry point
          2. Reacting to players' actions during a match
          3. Synchronization between clients and the server
        2. The Client class
          1. Connection with the server
          2. The Level class
      5. Adding data persistence to the game
        1. What is ORM?
        2. Using cpp-ORM
        3. Turning our object persistent
          1. Saving an object in a database
          2. Loading an object from the database
      6. Summary
    16. Index