34,79 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 372
Veröffentlichungsjahr: 2013
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 authors, 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-684-5
www.packtpub.com
Cover Image by Vivek Sinha (<[email protected]>)
Authors
Artur Moreira
Henrik Vogelius Hansson
Jan Haller
Reviewers
Brandon DeRosier
Karol Gasiński
Eyal Kalderon
Acquisition Editor
Edward Gordon
Lead Technical Editor
Mayur Hule
Technical Editors
Sanhita Sawant
Priya Singh
Nitee Shetty
Dennis John
Project Coordinator
Amey Sawant
Proofreaders
Dan McMahon
Stephen Swaney
Indexer
Monica Ajmera Mehta
Graphics
Ronak Dhruv
Abhinash Sahu
Production Coordinator
Pooja Chiplunkar
Cover Work
Pooja Chiplunkar
I'm really honored to write the first words of this book, the very first one about SFML. When I started to write this library, in 2006, I couldn't imagine that it would become so much popular. Around 100,000 visitors per month, 100 new forum posts everyday... this is huge! And this is just the beginning; with the release of SFML 2.0, the library makes an important step forward. While SFML 1 is a constantly evolving (understand "unstable") API, SFML 2.0 is meant to be a robust, stable, and mature foundation for the future. And hopefully a solid base for more and more great games.
Increasing popularity also means more effort from the authors to provide complete and quality documentation. Sadly, this is often overlooked by developers.
Although I do my best to provide detailed tutorials for SFML, they are nothing more than an improved API documentation. Users often ask me where they can find a more complete guide to start programming games with SFML. And until today, I had nowhere to direct them to. But Artur, Henrik, and Jan did a great job to fill this hole. They have gathered their wisdom and experience into a unique book that covers the basics of game programming, as well as everything that SFML has to offer—from audio to network, through advanced graphics. What I really appreciate about this book is that it is written with the same philosophy that is behind SFML: good design, simplicity, and modern code.
I hope you will enjoy reading this book as much as I did and find what you're looking for; whether you're a beginner who wants to learn game programming with SFML, or a more experienced programmer who wants to improve his design and technical skills. And don't hesitate to come to the SFML forum if you have questions or comments. I, the authors of this book, and all the community will be glad to answer you.
Laurent Gomila
Author of SFML
Software Engineer, Tegesoft, France
Artur Moreira is a game development enthusiast who ultimately aims to start a new game development company in his home country. He has been programming games and game-related software for over 4 years. Most of the effort in that time was put in creating an open source game-making library with lots of flexibility and portability. The library is called Nephilim and is known for supporting all major desktop and mobile operating systems, making game development fully cross-platform and fast. Alongside this big project, he keeps making his own prototypes and games for educational and commercial purposes.
Aside from the programming, he also puts some focus in creative areas such as 3D modeling, digital painting, and music composing.
I would like to thank, first of all, my girlfriend for her patience and unconditional support every single time the writing was taking all of my time and energy. Also, I can't be thankful enough for the support of my parents and sisters, along with all the closest relatives, whose support is ever-present and always helpful. On the technical side, I would like to directly thank Jan Haller and Henrik Vogelius Hansson, the co-authors of the book, for their remarkable collaboration, skill, and teamwork. It's been always a pleasure to work with them.
Henrik Vogelius Hansson has always been in love with both games and programming. He started his education fairly early and continued on into the indie scene with Defrost Games and their game Project Temporality. The next company that hired him was Paradox Development Studio where he got to work on titles such as Crusader Kings 2.
Beside the game companies, Henrik has also been very active in the SFML community and has even provided a binding for Ruby called rbSFML.
I would like to thank my co-authors, Jan and Artur, for the amazing cooperation and great times. I am also very happy and would like to thank my family that encouraged me to pursue this line of work. Also special thanks to my grandmother.
Jan Haller is a Master's degree student of Electrical Engineering and Information Technology. In his free time, he occasionally develops games in C++. He is also interested in the creation of graphics and 3D models.
In 2008, Jan stumbled upon SFML. Since then, he has used the library for many of his works. One of his bigger projects was a 2D Jump'n'Run game, where the character has to find its way through different levels, defeating enemies and collecting various items. During the years, Jan has actively participated in the SFML community, getting a lot of insights into the development of SFML 2. He has also written a C++ library called Thor, which extends SFML by ready-to-use features such as particle systems or animations.
I would like to thank Laurent Gomila for the passion and huge efforts he invested into the Simple and Fast Multimedia Library. It has always been interesting to discuss with him about the library and its development process. I would also like to thank my co-authors, Artur Moreira and Henrik Vogelius Hansson, who have been a very nice team to work with.
Brandon DeRosier is a free software supporter, software engineer, and a hobbyist game developer living in the Greater Boston area. Driven by an early interest in programming, he took to the reverse engineering of his favorite games of his childhood; he would later write several small augmentation tools to run alongside these games. Over time, he developed his skills as a programmer—as well as an interest in music composition, animation, and interactive media. Currently, he is directing these skills and interests towards game design.
As a member of the Free Software Foundation, he understands that the concealing of source code is unethical and regressive; dedicated to the digital rights of users everywhere, he has actively participated in the development and distribution of free software.
Brandon is currently pursuing a Bachelor of Science degree in Computer Science at Wentworth Institute of Technology in Boston and takes pride in helping others learn. Occasionally, he gives lectures in classes and clubs, with hopes of encouraging interest in interactive media development with frameworks such as SFML and LWJGL.
I'd like to thank my partner, Yamilah Atallah, for brainstorming game ideas with me, coming up with meaningful concepts and wonderful designs, and changing my life in so many positive ways; with this support, my interest in game development has grown.
Karol Gasiński is a programmer, entrepreneur, and traveler living in Poland, Europe. He works as a Graphic Software Engineer at an Intel Research & Development facility, and has worked on 6 generations of Intel graphic cards. As a member of KHRONOS group, Karol contributes to the development of OpenGL and OpenGL ES Specifications—the industry standard for high-performance graphics.
Outside of his work, Karol's biggest passion is game development and low-level programming. He has been associated with the games industry for over 6 years. In the past, he has worked on mobile versions of games such as Medieval Total War, Pro Evolution Soccer, and Silent Hill. Currently he is the founder and chairman of the Polish Conference on Computer Games Development—the biggest and fastest growing industry event in the country.
Karol gives lectures on most Polish conferences and events for game developers including WGK, GameDay, SWPC, the DigitalFrontier course, IGK, and others. You can also meet him on GDC Europe and GDC San Francisco, where each year he gathers inspiration for his new games.
Eyal Kalderon is a self-taught computer programmer and high school student. Having been introduced to the programming scene at a fairly young age, Eyal developed his early skills in Visual Basic and made a switch to C# early on. Eyal has made himself at home for several years now programming with C and C++ and using shell scripts to automate every task he finds boring. After trying SDL, Eyal switched to SFML in 2010, enjoyed it, and has been following its progress closely ever since.
Understanding the power of print, having gained much from the Internet and professional publications, Eyal chose to erect 'nullpwd' (nullpwd.wordpress.com) in March of 2010, a casual software-centered blog that acts as an unintimidating front for various software topics, such as programming, penetration systems, and the current happenings of the open source community.
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 <[email protected]> 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.
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.
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.
Welcome to the pages of SFML Game Development!
Whether you are just grabbing our book in a store, previewing it in your e-book reader, or you have already bought it—you have taken your first step in becoming a game developer by picking up this book.
Game development is a very interesting topic, as it combines many different fields such as software development, graphical design, music composition, and storytelling. Nowadays, there is an enormous variety of games available, yet developers never cease to be creative and to come up with innovations. This book conveys the process of game development in a way that covers state-of-the-art techniques, leaving you ready to implement your own ideas.
It does not matter if you are already an experienced developer or an ambitious newcomer to the field of making games. Although the book requires no previous knowledge on game development, we also teach valuable concepts and techniques that will help you grow as a game developer.
Throughout the book, we develop a 2D game with SFML. We focus on a top-scrolling aircraft shooter, where the player acts as a pilot and is confronted with various challenges. We begin with the bare bones of each element and continuously add functionality as we progress in the book. In every chapter, new features are introduced, and the code is updated accordingly. Therefore, you will not only see the concepts in theory, but also will have a direct implementation at hand, which you can investigate and extend the way you like.
That said, we would like to wish you a great journey through the chapters of this book. May it be a good experience in all its extent! Please enjoy!
Chapter 1, Making a Game Tick, introduces the SFML library and shows you basic concepts such as the game loop and rendering.
Chapter 2, Keeping Track of Your Textures – Resource Management, covers the loading and management of external resources such as images, fonts, and sounds.
Chapter 3, Forge of the Gods – Shaping Our World, builds up the framework of the game world and addresses the concept of scene graphs and game entities.
Chapter 4, Command and Control – Input Handling, shows how to react to user input from the keyboard, mouse, and joystick.
Chapter 5, Diverting the Game Flow – State Stack, covers switching between application states such as different menus, or between menus and the game itself.
Chapter 6, Waiting and Maintenance Area – Menus, introduces a simple graphical user interface in the menus.
Chapter 7, Warfare Unleashed – Implementing Gameplay, approaches actual gameplay mechanisms. Enemies, bullets, missiles, power-ups and collision detection are implemented.
Chapter 8, Every Pixel Counts – Adding Visual Effects, enhances the graphical appearance of the game by adding animations, particle systems, and shaders.
Chapter 9, Cranking Up the Bass – Music and Sound Effects, explains a way to integrate audio into the game.
Chapter 10, Company Atop The Clouds – Co-op Multiplayer, covers networking basics and a multiplayer implementation over the network.
Since this book is built around the SFML library, you need to download and install it. You can get SFML at www.sfml-dev.org; the first chapter gives a brief installation guide.
In case you decide to recompile SFML yourself, you will also require the cross-platform build tool CMake, which can be downloaded from www.cmake.org.
SFML Game Development is aimed at audiences of all ages who already know how to program in C++, at least to an intermediate level. It is optimal if the reader already has some experience in programming and knows the language well.
The ideal reader for such a book would be a person who is experienced in C++ and would now like to enter the world of game development in a simple yet serious way. However, if the reader already knows a good deal of it and still wants to read through the pages to see different approaches, or if he simply wants to learn more about SFML in a bigger practical example, we strongly encourage to read on!
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "To manage all these screens and transitions, we create the StateStack class."
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "It shows a background with a little information about the game, besides its title and then blinks a big old Press any key to continue message".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
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.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the erratasubmissionform link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
C++ is a very powerful, but also very complex programming language; even after years one never stops learning. We expect you to understand the basic language features (variables, data types, functions, classes, polymorphism, pointers, and templates), as well as the most important parts of the standard library (strings, streams, and the STL). If you feel unsure, we recommend reading a good C++ book, before or in parallel to this book, since SFML and our code sometimes uses advanced techniques. Game development is a difficult topic on its own; it is very frustrating if you additionally have to fight C++. Even if it takes some time to reasonably learn the programming language, it is a good investment, since it will save you days of tedious debugging.
You may have heard that in 2011, a new C++ standard was released, which introduced a lot of extremely useful features. We are going to use a few C++11 features in the book, and show how they can improve code. Each time we use a new C++11 technique, we will briefly explain it.
An issue that is widely underestimated, especially by beginners, is the importance of clean code. Before making a game, it is always a good idea to have a rough imagination of the game features and their implementation. It may help to draw sketches on a paper, in order to visualize contexts better. Also during development, it is crucial to keep an eye on the code design, and to refactor messy code where necessary.
Some key aspects of good code are as follows:
After this initial sermon, we hope that you have recognized how a well-structured code can keep up your motivation to develop, while on the other hand, a total mess is contra-productive and frustrating, when it comes to maintenance, debugging, or integration of new features. Don't be afraid if this advice sounds very abstract; you will automatically gain experience while developing projects.
By the way, the code we are going to develop during the chapters is available for download on the Packt Publishing website.
