1

I'm looking at creating a basic side-scroller using OpenGL and C++, however I'm having trouble tackling a few basic conceptual issues, namely:

  1. Dividing the window into easy "blocks" (some sort of grid system). On what level would I want to do this? (The OpenGL viewport size, or through some abstraction that ensures working with multiples of x?)

  2. Storing the data for all these "blocks" to allow for collision detection and some special effects. What's a sensible way of going about this - I was thinking along the lines of a multi-dimensional array of objects (which contain information such as the tile type), but this doesn't seem like a very elegant or efficient solution.

  • This is probably way too broad of a question for SO. There are plenty of tutorial style books for this at your local bookstore or library. Way back when I did this with DirectX7 with such a book as a complete newbie. – AJG85 Oct 11 '11 at 20:07

2 Answers2

1

Usually, it isn't the window (ie. viewport) which is divided into a grid but rather the "gameplay area". Pick a good size according to the style of your art (something like 64px - you might want to select a size that is a power of two for technical reasons) and create tiles of that size for your game (stored and loaded as a 1D array)

Then, these tiles are referenced (by an offset) in a tilemap, which actually describes what your level looks like. Each tile can also have extra metadata for handling collisions and game events. You might want to use an existing map format and toolset to save time, like Mappy.

aviraldg
  • 9,531
  • 6
  • 41
  • 56
  • Mappy is great for a tile grid engine. For a side scroller he would be better off with a single background texture and overlaying sprites and moving a view rect over the game area to determine what parts of background and what sprites to draw. – AJG85 Oct 11 '11 at 20:13
0

Tips:
Think of the display and the data separately (lookup Model-View-Controller).

How you store the data depends on how it's going to be accessed, not on how it's going to be displayed. Think of it from the computers point of view!

Hint, it's often easiest to work in a one dimensional storage of the data and work out where along it the next point up/down is than work in 2d.

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263