Monday 2 January 2012

Building my map

So I've cleaned up my 3D object loading and drawing code and created my own custom class called base3Dobject.

It holds the basic attributes requied, handles loading the content, alignment to world and drawing of the object.

I've also created a basic camera object to hold my world camera settings as this will be needed by all of my 3D objects.

Now I want to draw my building grid for the game's landscape.

The map is a simple grid of varying height buildings that the player will need to traverse and land on.

All I need to do is create a 2D array to hold the width and depth of the map (number of buildings wide by number of buildings deep) and for each building location (I'll call this the foundation position) I need to set the number of blocks high the building will be.

So now I have a 2D array of heights for each of my buildings.

I could just iterate this array every time I want to update or draw a building.

But that will mean I will need to dynamically generate objects on every iteration and have nested loops.

Now I don't want to be creating temp objects at run time because I know how the xbox garbage collector will behave (now!) So I need a pre defined array of blocks that is allocated in memory so it never needs to bother the garbage collector at run time.

Each block is a positioned 3D object of my cube model. Now all I need to do is loop through this array and update and draw each block in the set position.

I need to make sure the position of each block is offset accordingly so all the blocks don't draw on top of each other. This is easy by using the current width and depth of the foundation multiplied by the offset (the model width and depth) and then the same done to the randomly generated height.

So now when I run my game, I get a nice simple grid of buildings.

No comments:

Post a Comment