Showing posts with label XNA. Show all posts
Showing posts with label XNA. Show all posts

Monday, November 14, 2011

Progress !

Nothing beat fresh new progress ! Phase one complete, I've got my zone. It's not great but it works. But images speaks better than words so here goes :

This is the first try at my basic grid. It's not beautiful yet but at least I can shove things in the screen now. It's made of two classes, a Zone which is a "manager" of Tiles. A manager is a kind of Overlord that watches over the Tiles and assigns them values and executes action. The update and draw method are found here :
What this does is create an array of Tiles and loops through them in the Draw() and Update() method.

The Initialize() method is used to create the instances of Tile and put them in the array. All of this is done by looping through the the rows and then the columns. It's fairly easy but simple once you get the gist of it.

Now I updated it a bit by adding a spritesheet instead of single sprites and the random generation of the map. The functions are found in pictures of course, below :

It loops through the tileValues array(which is the array of integer values representing which tiles to grab from the spritesheet) and puts a random value in it. Then when I draw the tiles, the manager goes through the values in the tileValues and tells the Tile to draw a specific rectangle from the spritesheet.

The result is then :
It's messy but it's cool, I've got a small spritesheet I used in a previous project. I added the cool functionality of randomly changing the map again when enter is pressed. Fun little feature. As always grab a peek at the source here.