NSFU Logo
RSS Twitter Facebook

Cutting things up

By: KJ Tags: , , ,
Grid System

Cutting things up - grids.

So my next step in this project is to start cutting things up and that means, grids! I put a lot of thought in to this, since a good grid system could make my life a lot easier down the line. It needed to be able to split up any space, provide the cell(s) that an object is present in, track the type of object that is in a cell and allow updating the grid for a change in the position of an object.

The last part of this was the trickiest. I added a property to my Sprite object called “Type”. It’s a byte that can be used to track the type an object is. For example, different kinds of land can be represented by different bytes (water = 0, land = 1, pavement = 2), where different buildings can be represented by ranges in the same byte set, or can be set to similiar bytes in a seperate grid. For my plans I figured that, for a planet, I could overlay two different grid systems. One grid would manage land while the other would manage buildings.

In the solar system perspective (will be explained later), planets can be represented by the byte range 0-10, while different objects can be anything else. Having a system like this should make it easy to implement the A* pathfinding algorithm quickly, but have it be flexible for different scenarios.

Now that I have the grids, it is time to start building a planet!