logo资料库

SDL Game Development.pdf

第1页 / 共256页
第2页 / 共256页
第3页 / 共256页
第4页 / 共256页
第5页 / 共256页
第6页 / 共256页
第7页 / 共256页
第8页 / 共256页
资料共256页,剩余部分请下载后查看
Cover
Copyright
Credits
About the Author
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 1: Getting Started with SDL
Why use SDL?
What is new in SDL 2.0?
Migrating SDL 1.2 extensions
Setting up SDL in Visual C++ Express 2010
Using Mercurial to get SDL 2.0 on Windows
Cloning and building the latest SDL 2.0 repository
I have the library; now what?
Hello SDL
An overview of Hello SDL
SDL initialization flags
SDL renderer flags
What makes up a game
Breaking up the Hello SDL code
What does this code do?
The Game class
Fullscreen SDL
Summary
Chapter 2: Drawing in SDL
Basic SDL drawing
Getting some images
Creating an SDL texture
Source and destination rectangles
Animating a sprite sheet
Flipping images
Installing SDL_image
Using SDL_image
Tying it into the framework
Creating the texture manager
Using texture manager as a singleton
Summary
Chapter 3: Working with Game Objects
Using inheritance
Implementing polymorphism
Using abstract base classes
Should we always use inheritance?
Could the same thing be achieved with a simpler solution?
Derived classes should model the "is a" relationship
Possible performance penalties
Putting it all together
Summary
Chapter 4: Exploring Movement and Input Handling
Setting up game objects for movement
What is a vector?
Some common operations
Addition of two vectors
Multiply by a scalar number
Subtraction of two vectors
Divide by a scalar number
Normalizing a vector
Adding the Vector2D class
Adding velocity
Adding acceleration
Creating fixed frames per second
Input handling
Creating our input handler class
Handling joystick/gamepad input
SDL joystick events
Initializing joysticks
Listening for and handling axis movement
Dealing with joystick button input
Handling mouse events
Using mouse button events
Handling mouse motion events
Implementing keyboard input
Wrapping things up
Summary
Chapter 5: Handling Game States
A simple way for switching states
Implementing finite state machines
A base class for game states
Implementing FSM
Implementing menu states
Function pointers and callback functions
Implementing the temporary play state
Pausing the game
Creating the game over state
Summary
Chapter 6: Data-driven Design
Loading XML files
Basic XML structure
Implementing Object Factories
Using Distributed Factories
Fitting the factory into the framework
Parsing states from an XML file
Loading the menu state from an XML file
Loading other states from an XML file
Loading the play state
Loading the pause state
Loading the game over state
Summary
Chapter 7: Creating and Displaying Tile Maps
What is a tile map?
Getting familiar with the Tiled application
Parsing and drawing a tile map
Creating the TileLayer class
Creating the LevelParser class
Parsing tilesets
Parsing a tile layer
Drawing the map
Scrolling a tile map
Parsing object layers
Developing the ObjectLayer class
Summary
Chapter 8: Creating Alien Attack
Using the SDL_mixer extension for sound
Creating the SoundManager class
Setting up the basic game objects
GameObject revamped
SDLGameObject is now ShooterObject
Player inherits from ShooterObject
Lots of enemy types
Adding a scrolling background
Handling bullets
Two types of bullets
The BulletHandler class
Dealing with collisions
Creating a CollisionManager class
Possible improvements
Summary
Chapter 9: Creating Conan the Caveman
Setting up the basic game objects
No more bullets or bullet collisions
Game objects and map collisions
ShooterObject is now PlatformerObject
The Camera class
Camera-controlled map
The Player class
Possible additions
Summary
Index
SDL Game Development Discover how to leverage the power of SDL 2.0 to create awesome games in C++ Shaun Ross Mitchell BIRMINGHAM - MUMBAI
SDL Game Development Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2013 Production Reference: 1170613 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-682-1 www.packtpub.com Cover Image by Shaun Mitchell (shaunmitchell84@googlemail.com)
Credits Author Shaun Ross Mitchell Project Coordinator Hardik Patel Reviewers Luka Horvat Mårten Möller Acquisition Editor Edward Gordon Lead Technical Editor Savio Jose Chalini Snega Victor Technical Editors Jeeten Handu Kaustubh S. Mayekar Anita Nayak Proofreader Bernadette Watkins Indexer Rekha Nair Graphics Ronak Dhruv Production Coordinator Prachali Bhiwandkar Cover Work Prachali Bhiwandkar
About the Author Shaun Mitchell is a developer at a high profile online gaming company. He holds a BSc in Game Programming and Development from Qantm College / SAE Institute London. Shaun is also a moderator and active member of the programming community. I would like to thank Jason Colman, my university lecturer, whose knowledge and insight into C++ and game programming has been the foundation of my skillset. I would also like to thank the community for the interesting discussions and topics to hone my skills with. Thank you to John Bayly for the background image on the front cover. Many thanks to my family for their continued support and importantly, a huge thank you to my girlfriend, Emma, who tirelessly proofread my chapters while also keeping me running on a generous amount of caffeine.
About the Reviewers Luka Horvat is an enthusiastic software and game developer who got fascinated by computer science in his early years. He chose to study his passion while working on many different projects and technologies. Throughout the years he gained a lot of knowledge and experience, and he wanted to share that with others. He is proficient in many different programming languages, with C++ as his main one; and is passionate about game development. So he started teaching it and currently manages different courses for in this area. He continues to pursue his career in computer science by working on a wide variety of projects and sharing them with others. I would like to thank my friends and family who helped me produce this book. Mårten Möller is an independent game developer who has previously worked at Imperial Game Studios. I would like to thank my family and friends. All of you are amazing.
www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub. com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
分享到:
收藏