Book Image

SFML Blueprints

Book Image

SFML Blueprints

Overview of this book

Table of Contents (15 chapters)
SFML Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Building a generic Tile Map


For our project, we need something that will manage the map. In fact, the map is nothing but a big grid. The cells can be of any shape (square, hexagonal, and so on). The only restriction is that all the cells of a single map should have the same geometry.

Moreover, each cell can contain several objects, possibly of different types. For example, a cell can contain some background texture for the ground, a tree, and a bird. Because SFML doesn't use a z buffer with sprites (also called a depth buffer), we need to simulate it by hand. This is called the Painter's Algorithm. Its principle is very simple; draw everything but by depth order, starting with the most distant. It's how a tradition art painter would paint.

All this information brings us to the following structure:

  • A Map class must be of a specific geometry and must contain any number of layers sorted by their z buffer.

  • A Layer contains only a specific type. It also has a z buffer and stores a list of content...