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 Game Development

Book Description

If you’ve got a firm grasp of C++ with a secret hankering to create a great game, this book is for you. Every practical aspect of programming an interactive game world is here – the only real limit is your imagination.

  • Develop a complete game throughout the book
  • Learn how to use modern C++11 style to create a full featured game and support for all major operating systems
  • Fully network your game for awesome multiplayer action
  • Step-by-step guide to developing your game using C++ and SFML

In Detail

Game development comprises the combination of many different aspects such as game logics, graphics, audio, user input, physics and much more. SFML is an Open Source C++ library designed to make game development more accessible, exposing multimedia components to the user through a simple, yet powerful interface.

If you are a C++ programmer with a stack of ideas in your head and seeking a platform for implementation, your search ends here.

Starting with nothing more than a blank screen, SFML Game Development will provide you with all the guidance you need to create your first fully featured 2D game using SFML 2.0. By the end, you'll have learned the basic principles of game development, including advanced topics such as how to network your game, how to utilize particle systems and much more.

SFML Game Development starts with an overview of windows, graphics, and user inputs. After this brief introduction, you will start to get to grips with SFML by building up a world of different game objects, and implementing more and more gameplay features. Eventually, you’ll be handling advanced visual effects, audio effects and network programming like an old pro. New concepts are discussed, while the code steadily develops.

SFML Game Development will get you started with animations, particle effects and shaders. As well as these fundamental game aspects, we’re also covering network programming to the extent where you’ll be able to support the game running from two different machines. The most important part, the gameplay implementation with enemies and missiles, will make up the core of our top-scrolling airplane shoot' em-up game!

You will learn everything you need in SFML Game Development in order to start with game development and come closer to creating your own game.

Table of Contents

  1. SFML Game Development
    1. Table of Contents
    2. SFML Game Development
    3. Credits
    4. Foreword
    5. About the Authors
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    8. 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
    9. 1. Making a Game Tick
      1. Introducing SFML
        1. Downloading and installation
        2. A minimal example
      2. A few notes on C++
      3. Developing the first game
        1. The Game class
      4. Game loops and frames
        1. Input over several frames
        2. Vector algebra
        3. Frame-independent movement
        4. Fixed time steps
        5. Other techniques related to frame rates
      5. Displaying sprites on the screen
        1. File paths and working directories
        2. Real-time rendering
        3. Adapting the code
      6. Summary
    10. 2. Keeping Track of Your Textures – Resource Management
      1. Defining resources
      2. Resources in SFML
        1. Textures
        2. Images
        3. Fonts
        4. Shaders
        5. Sound buffers
        6. Music
      3. A typical use case
        1. Graphics
        2. Audio
        3. Acquiring, releasing, and accessing resources
      4. An automated approach
        1. Finding an appropriate container
        2. Loading from files
        3. Accessing the textures
      5. Error handling
        1. Boolean return values
        2. Throwing exceptions
        3. Assertions
      6. Generalizing the approach
        1. Compatibility with sf::Music
        2. A special case – sf::Shader
      7. Summary
    11. 3. Forge of the Gods – Shaping Our World
      1. Entities
        1. Aircraft
        2. Alternative entity designs
      2. Rendering the scene
        1. Relative coordinates
        2. SFML and transforms
        3. Scene graphs
        4. Scene nodes
        5. Node insertion and removal
        6. Making scene nodes drawable
        7. Drawing entities
        8. Connecting entities with resources
        9. Aligning the origin
        10. Scene layers
      3. Updating the scene
        1. One step back – absolute transforms
      4. The view
        1. Viewport
        2. View optimizations
        3. Resolution and aspect ratio
        4. View scrolling
        5. Zoom and rotation
      5. Landscape rendering
        1. SpriteNode
        2. Landscape texture
        3. Texture repeating
      6. Composing our world
        1. World initialization
        2. Loading the textures
        3. Building the scene
        4. Update and draw
      7. Integrating the Game class
        1. The run() method
      8. Summary
    12. 4. Command and Control – Input Handling
      1. Polling events
        1. Window events
        2. Joystick events
        3. Keyboard events
        4. Mouse events
      2. Getting the input state in real time
        1. Events and real-time input – when to use which
        2. Delta movement from the mouse
      3. Playing nice with your application neighborhood
      4. A command-based communication system
        1. Introducing commands
        2. Receiver categories
        3. Command execution
        4. Command queues
        5. Handling player input
        6. Commands in a nutshell
        7. Implementing the game logic
        8. A general-purpose communication mechanism
      5. Customizing key bindings
        1. Why a player is not an entity
      6. Summary
    13. 5. Diverting the Game Flow – State Stack
      1. Defining a state
      2. The state stack
        1. Adding states to StateStack
        2. Handling updates, input, and drawing
          1. Input
          2. Update
          3. Draw
        3. Delayed pop/push operations
      3. The state context
      4. Integrating the stack in the Application class
      5. Navigating between states
        1. Creating the game state
        2. The title screen
        3. Main menu
        4. Pausing the game
      6. The loading screen – sample
        1. Progress bar
        2. ParallelTask
        3. Thread
        4. Concurrency
        5. Task implementation
      7. Summary
    14. 6. Waiting and Maintenance Area – Menus
      1. The GUI hierarchy, the Java way
      2. Updating the menu
      3. The promised key bindings
      4. Summary
    15. 7. Warfare Unleashed – Implementing Gameplay
      1. Equipping the entities
        1. Introducing hitpoints
        2. Storing entity attributes in data tables
        3. Displaying text
      2. Creating enemies
        1. Movement patterns
        2. Spawning enemies
      3. Adding projectiles
        1. Firing bullets and missiles
        2. Homing missiles
      4. Picking up some goodies
      5. Collision detection and response
        1. Finding the collision pairs
        2. Reacting to collisions
        3. An outlook on optimizations
      6. An interacting world
        1. Cleaning everything up
        2. Out of view, out of the world
        3. The final update
      7. Victory and defeat
      8. Summary
    16. 8. Every Pixel Counts – Adding Visual Effects
      1. Defining texture atlases
        1. Adapting the game code
      2. Low-level rendering
        1. OpenGL and graphics cards
        2. Understanding render targets
        3. Texture mapping
        4. Vertex arrays
      3. Particle systems
        1. Particles and particle types
        2. Particle nodes
        3. Emitter nodes
        4. Affectors
        5. Embedding particles in the world
      4. Animated sprites
        1. The Eagle has rolled!
      5. Post effects and shaders
        1. Fullscreen post effects
        2. Shaders
        3. The bloom effect
      6. Summary
    17. 9. Cranking Up the Bass – Music and Sound Effects
      1. Music themes
        1. Loading and playing
        2. Use case – In-game themes
      2. Sound effects
        1. Loading, inserting, and playing
        2. Removing sounds
        3. Use case – GUI sounds
      3. Sounds in 3D space
        1. The listener
        2. Attenuation factor and minimum distance
        3. Positioning the listener
        4. Playing spatial sounds
        5. Use case – In-game sound effects
      4. Summary
    18. 10. Company Atop the Clouds – Co-op Multiplayer
      1. Playing multiplayer games
      2. Interacting with sockets
        1. TCP
        2. UDP
        3. Socket selectors
        4. Custom protocols
      3. Data transport
      4. Network architectures
        1. Peer-to-peer
        2. Client-server architecture
          1. Authoritative servers
      5. Creating the structure for multiplayer
      6. Working with the Server
        1. Server thread
        2. Server loop
        3. Peers and aircraft
        4. Hot Seat
        5. Accepting new clients
        6. Handling disconnections
        7. Incoming packets
        8. Studying our protocol
        9. Understanding the ticks and updates
          1. Synchronization issues
      7. Taking a peek in the other end – the client
        1. Client packets
        2. Transmitting game actions via network nodes
        3. The new pause state
        4. Settings
        5. The new Player class
      8. Latency
        1. Latency versus bandwidth
        2. View scrolling compensation
        3. Aircraft interpolation
      9. Cheating prevention
      10. Summary
    19. Index