You are previewing SDL Game Development.
O'Reilly logo
SDL Game Development

Book Description

If you’re good with C++ and object oriented programming, this book utilizes your skills to create 2D games using the Simple DirectMedia Layer API. Practical tutorials include the development of two wickedly good games.

  • Create 2D reusable games using the new SDL 2.0 and C++ frameworks

  • Become proficient in speeding up development time

  • Create two fully-featured games with C++ which include a platform game and a 2D side scrolling shooter

  • An engaging and structured guide to develop your own game

  • In Detail

    SDL 2.0 is the latest release of the popular Simple DirectMedia Layer API, which is designed to make life easier for C++ developers, allowing you simple low-level access to various multiplatform audio, graphics, and input devices.

    SDL Game Development guides you through creating your first 2D game using SDL and C++. It takes a clear and practical approach to SDL game development, ensuring that the focus remains on creating awesome games.

    Starting with the installation and setup of SDL, you will quickly become familiar with useful SDL features, covering sprites, state management, and OOP, leading to a reusable framework that is extendable for your own games. SDL Game Development culminates in the development of two exciting action games that utilize the created framework along with tips to improve the framework.

    Table of Contents

    1. SDL Game Development
      1. Table of Contents
      2. SDL Game Development
      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. Getting Started with SDL
        1. Why use SDL?
          1. What is new in SDL 2.0?
          2. Migrating SDL 1.2 extensions
        2. Setting up SDL in Visual C++ Express 2010
          1. Using Mercurial to get SDL 2.0 on Windows
            1. Cloning and building the latest SDL 2.0 repository
          2. I have the library; now what?
        3. Hello SDL
          1. An overview of Hello SDL
          2. SDL initialization flags
          3. SDL renderer flags
        4. What makes up a game
          1. Breaking up the Hello SDL code
          2. What does this code do?
        5. The Game class
          1. Fullscreen SDL
        6. Summary
      9. 2. Drawing in SDL
        1. Basic SDL drawing
          1. Getting some images
          2. Creating an SDL texture
        2. Source and destination rectangles
          1. Animating a sprite sheet
          2. Flipping images
        3. Installing SDL_image
          1. Using SDL_image
        4. Tying it into the framework
          1. Creating the texture manager
          2. Using texture manager as a singleton
        5. Summary
      10. 3. Working with Game Objects
        1. Using inheritance
        2. Implementing polymorphism
        3. Using abstract base classes
        4. Should we always use inheritance?
          1. Could the same thing be achieved with a simpler solution?
          2. Derived classes should model the "is a" relationship
          3. Possible performance penalties
        5. Putting it all together
        6. Summary
      11. 4. Exploring Movement and Input Handling
        1. Setting up game objects for movement
          1. What is a vector?
          2. Some common operations
            1. Addition of two vectors
            2. Multiply by a scalar number
            3. Subtraction of two vectors
            4. Divide by a scalar number
            5. Normalizing a vector
          3. Adding the Vector2D class
          4. Adding velocity
          5. Adding acceleration
        2. Creating fixed frames per second
        3. Input handling
          1. Creating our input handler class
          2. Handling joystick/gamepad input
            1. SDL joystick events
            2. Initializing joysticks
          3. Listening for and handling axis movement
          4. Dealing with joystick button input
          5. Handling mouse events
            1. Using mouse button events
            2. Handling mouse motion events
          6. Implementing keyboard input
          7. Wrapping things up
        4. Summary
      12. 5. Handling Game States
        1. A simple way for switching states
        2. Implementing finite state machines
          1. A base class for game states
          2. Implementing FSM
        3. Implementing menu states
          1. Function pointers and callback functions
          2. Implementing the temporary play state
          3. Pausing the game
          4. Creating the game over state
        4. Summary
      13. 6. Data-driven Design
        1. Loading XML files
          1. Basic XML structure
        2. Implementing Object Factories
          1. Using Distributed Factories
        3. Fitting the factory into the framework
        4. Parsing states from an XML file
        5. Loading the menu state from an XML file
        6. Loading other states from an XML file
          1. Loading the play state
          2. Loading the pause state
          3. Loading the game over state
        7. Summary
      14. 7. Creating and Displaying Tile Maps
        1. What is a tile map?
        2. Getting familiar with the Tiled application
        3. Parsing and drawing a tile map
          1. Creating the TileLayer class
          2. Creating the LevelParser class
          3. Parsing tilesets
          4. Parsing a tile layer
          5. Drawing the map
        4. Scrolling a tile map
        5. Parsing object layers
          1. Developing the ObjectLayer class
        6. Summary
      15. 8. Creating Alien Attack
        1. Using the SDL_mixer extension for sound
          1. Creating the SoundManager class
        2. Setting up the basic game objects
          1. GameObject revamped
          2. SDLGameObject is now ShooterObject
          3. Player inherits from ShooterObject
          4. Lots of enemy types
          5. Adding a scrolling background
        3. Handling bullets
          1. Two types of bullets
          2. The BulletHandler class
        4. Dealing with collisions
          1. Creating a CollisionManager class
        5. Possible improvements
        6. Summary
      16. 9. Creating Conan the Caveman
        1. Setting up the basic game objects
          1. No more bullets or bullet collisions
          2. Game objects and map collisions
          3. ShooterObject is now PlatformerObject
          4. The Camera class
          5. Camera-controlled map
          6. The Player class
        2. Possible additions
        3. Summary
      17. Index