Book Image

SFML Game Development

By : Artur Moreira, Henrik Vogelius Hansson, Jan Haller, Henrik Valter Vogelius, SFML
Book Image

SFML Game Development

By: Artur Moreira, Henrik Vogelius Hansson, Jan Haller, Henrik Valter Vogelius, SFML

Overview of this book

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 (18 chapters)
SFML Game Development
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

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!

What this book covers

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.

What you need for this book

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.

Who this book is for

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!

Conventions

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:

namespace GUI
{
    class Component : public sf::Drawable,public sf::Transformable
   {
        public:
          typedef std::shared_ptr<Component> Ptr;

                          Component();

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

: mChildren()
, mSelectedChild(-1)
{
}

void Container::pack(std::shared_ptr<GUI::Component> component)
{

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".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

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 , 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.

Customer support

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.

Downloading the example code

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.

Errata

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 errata submission form 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

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 with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.