SFML Game Development By Example

Book description

Create and develop exciting games from start to finish using SFML

About This Book

  • Familiarize yourself with the SFML library and explore additional game development techniques
  • Craft, shape, and improve your games with SFML and common game design elements
  • A practical guide that will teach you how to use utilize the SFML library to build your own, fully functional applications

Who This Book Is For

This book is intended for game development enthusiasts with at least decent knowledge of the C++ programming language and an optional background in game design.

What You Will Learn

  • Create and open a window by using SFML
  • Utilize, manage, and apply all of the features and properties of the SFML library
  • Employ some basic game development techniques to make your game tick
  • Build your own code base to make your game more robust and flexible
  • Apply common game development and programming patterns to solve design problems
  • Handle your visual and auditory resources properly
  • Construct a robust system for user input and interfacing
  • Develop and provide networking capabilities to your game

In Detail

Simple and Fast Multimedia Library (SFML) is a simple interface comprising five modules, namely, the audio, graphics, network, system, and window modules, which help to develop cross-platform media applications. By utilizing the SFML library, you are provided with the ability to craft games quickly and easily, without going through an extensive learning curve. This effectively serves as a confidence booster, as well as a way to delve into the game development process itself, before having to worry about more advanced topics such as ?rendering pipelines? or ?shaders.?

With just an investment of moderate C++ knowledge, this book will guide you all the way through the journey of game development.

The book starts by building a clone of the classical snake game where you will learn how to open a window and render a basic sprite, write well-structured code to implement the design of the game, and use the AABB bounding box collision concept.

The next game is a simple platformer with enemies, obstacles and a few different stages. Here, we will be creating states that will provide custom application flow and explore the most common yet often overlooked design patterns used in game development.

Last but not the least, we will create a small RPG game where we will be using common game design patterns, multiple GUI. elements, advanced graphical features, and sounds and music features. We will also be implementing networking features that will allow other players to join and play together.

By the end of the book, you will be an expert in using the SFML library to its full potential.

Style and approach

An elaborate take on the game development process in a way that compliments the reader's existing knowledge, this book provides plenty of examples and is kind to the uninitiated. Each chapter builds upon the knowledge gained from the previous one and offers clarifications on common issues while still remaining within the scope of its own subject and retaining clarity.

Table of contents

  1. SFML Game Development By Example
    1. Table of Contents
    2. SFML Game Development By Example
    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. It's Alive! It's Alive! – Setup and First Program
      1. What is SFML?
      2. SFML licensing
      3. Resources and installation
        1. Setting up a Microsoft Visual Studio project
      4. Opening a window
      5. Basics of SFML drawing
      6. Drawing images in SFML
        1. What is a sprite?
      7. Common mistakes
      8. Summary
    9. 2. Give It Some Structure – Building the Game Framework
      1. Graduating to ravioli
      2. Implementing the window class
      3. Building the game class
        1. Putting our code to work
      4. Hardware and execution time
        1. Controlling the frame-rate
      5. Using the SFML clock
      6. Fixed time-step
      7. Common mistakes
      8. Summary
    10. 3. Get Your Hands Dirty – What You Need to Know
      1. Introducing snake
      2. Game design decisions
      3. Implementing the snake structure
      4. The snake class
      5. The World class
      6. Time to integrate
      7. Hunting bugs
      8. Fixing bugs
      9. Going the extra mile
      10. Common mistakes
      11. Summary
    11. 4. Grab That Joystick – Input and Event Management
      1. Retrieving peripheral input
        1. Checking for mouse input
        2. Plug in your controller
        3. Understanding the sf::Event
      2. Introducing the event manager
      3. Standard function wrapper
      4. Building the event manager
        1. Implementing the event manager
      5. Integrating the Event Manager class
      6. Moving a sprite revisited
      7. Principles of use
      8. Common mistakes
      9. Summary
    12. 5. Can I Pause This? – Application States
      1. What is a state?
      2. The most simplistic approach
      3. Introducing the state pattern
        1. Defining common types
        2. The state manager class
          1. Defining the state manager class
          2. Implementing the state manager
      4. Improving the Event Manager class
      5. Incorporating the state manager
      6. Creating the intro state
        1. Implementing the intro state
      7. The main menu state
      8. A sample game state
      9. The means to pause
      10. Common mistakes
      11. Summary
    13. 6. Set It in Motion! – Animating and Moving around Your World
      1. Use of copyrighted resources
      2. Finding and using the current directory
      3. Using the SFML views
        1. Preparing application states for views
      4. Automated resource management
        1. Designing a resource manager
        2. Implementing the texture manager
      5. Introducing sprite sheets
        1. Implementing a sprite sheet class
        2. The base animation class
          1. Implementing the base animation class
        3. Directional animation
        4. Loading the sprite sheet files
      6. Summary
    14. 7. Rediscovering Fire – Common Game Design Elements
      1. The game map
        1. What is a tile?
      2. Building the game world
        1. The flyweight pattern
        2. Designing the map class
      3. The parent of all world objects
        1. Creating the base entity class
          1. Collisions and bounding boxes
        2. Implementing the base entity class
        3. Entity-on-tile collisions
      4. Entity storage and management
        1. Implementing the entity manager
      5. Using entities to build characters
        1. Implementing the character class
        2. Creating the player
      6. Adding enemies
      7. Loading entities from the map file
      8. Final editions to our code base
        1. Changes to the shared context
        2. Putting all the pieces together
      9. Summary
    15. 8. The More You Know – Common Game Programming Patterns
      1. Use of copyrighted resources
      2. What is a programming pattern?
      3. The entity component system
        1. What is a component?
        2. The position component
        3. The bitmask
      4. Managing entities
        1. Implementing the entity manager
          1. The factory pattern
      5. Designing the systems
        1. Entity events
          1. Entity event queue
        2. The base system
          1. Implementing the base system
        3. Handling messages
          1. The observer pattern
        4. The message handler class
      6. Managing systems
        1. Implementing the system manager
      7. Implementing the rendering system
        1. The sprite sheet component
        2. The renderer
      8. Putting the ECS to work
      9. The new and improved map
        1. Adjusting the Map class
      10. Summary
    16. 9. A Breath of Fresh Air – Entity Component System Continued
      1. Adding entity movement
        1. The movement system
        2. Implementing states
          1. The state system
        3. The entity controller
      2. Animating the entities
      3. Handling collisions
        1. The collision system
          1. Implementing the collision system
      4. Summary
    17. 10. Can I Click This? – GUI Fundamentals
      1. Use of copyrighted resources
      2. What is a GUI?
        1. GUI style
      3. Expansion of utility functions
      4. Font management
      5. The core of all elements
        1. Implementing the GUI element class
      6. Defining GUI events
      7. The interface class
        1. Implementing the interface class
      8. Summary
    18. 11. Don't Touch the Red Button! – Implementing the GUI
      1. The GUI manager
        1. Implementing the GUI manager
      2. The label element
      3. The text field element
      4. The scrollbar element
      5. Integrating the GUI system
      6. Expanding the event manager
      7. Re-implementing the main menu
      8. Summary
    19. 12. Can You Hear Me Now? – Sound and Music
      1. Use of copyrighted resources
      2. Preparing the project for sound
      3. Basics of SFML sound
        1. Playing sounds
        2. Playing music
      4. Sound spatialization
        1. Placing sounds in space
      5. Audio manager
      6. Defining sound properties
      7. Managing sounds
        1. Implementing the sound manager
      8. Adding support for sound
        1. Animation system hooks
        2. Entity component system expansion
      9. The sound emitter component
      10. The sound listener component
      11. Implementing the sound system
      12. Integrating our code
      13. Summary
    20. 13. We Have Contact! – Networking Basics
      1. Basics of networking
        1. SFML networking
          1. TCP sockets
          2. Handling multiple connections
          3. TCP protocol specifics
          4. User datagram protocol
        2. Alternative to sending raw data
          1. SFML packets
        3. Non-blocking sockets
      2. Letting the traffic flow
      3. Multi-threading
        1. Shared data protection
      4. Creating a simple communication protocol
        1. Keeping a UDP connection alive
      5. Designing the client class
      6. Implementing the client
      7. The server class
      8. Implementing server
      9. A simple chat application
      10. The chat client
      11. Summary
    21. 14. Come Play with Us! – Multiplayer Subtleties
      1. Use of copyrighted resources
      2. Shared code
        1. Additional components
      3. Building our game server
        1. Additions to the entity component system
          1. Implementing combat
        2. Server action timing
        3. Server network system
          1. Implementing the network system
        4. Server entity and system management
        5. Main server class
        6. Implementing the world class
        7. Server entry point
      4. Developing the game client
        1. Entity component system expansions
        2. Network class and interpolation
        3. Implementing the client network class
        4. Client entity and system management
        5. Putting the pieces into place
        6. Main menu adjustments
      5. Summary
    22. Index

Product information

  • Title: SFML Game Development By Example
  • Author(s): Raimondas Pupius
  • Release date: December 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781785287343