Friday 8 March 2013

Let's get started!

Immediately after it was decided I would be focusing on dungeon generation I whipped up some code in what I'd call a mix of php and C++ (prior to writing this code i was doing a lot of php coding for my Application Development module so it was just in the back of my mind). My immediate thought is that I wanted to create a script that would produce a progressive increase in X and Y values that i could then transform some kind of prefabrication by to position 'Rooms' along my dungeon path.

The script I made would initialise a pair of variables and progressively increment or decrement either one of them but never both (this would cause a diagonal movement along a pair of axis, which I didn't want) after deciding which value (X or Y) to alter the script would then add the value to an array. This would continue under the constraint "while(X != gridSize)" this just gave the script an ending point, eventually gridSize could be any number you or I wanted.

The first 'room' to be placed into the array would start at the co-ordinates; (0,0-gridSize)  to do this I initialised the Y variable with a 0-gridSize random number generator attached to it. The next form of randomisation involves deciding whether additional room values are an increment for X or an increment/decrement to Y (There is no decrement on X because I don't want the path to go back on it's self at this moment). I did this by creating 2 addition variables initialised with a random generator between 0-100(Xvar and Yvar). I then create an if statement to decide whether X will be incremented "(If Xvar <= 25)" else increment Y (if Yvar <= 50) else decrement Y. Adjusting the numbers in the if statement will ultimately change the shape of the dungeon.

At this time i had no way of graphically representing anything i'd done so until then i spent time getting familiar with Unity3D, a few tutorials later i managed to represent the values in my array by drawing cubes into the engine then transforming their X and Z locations by the X and Y values in my array respectively.

This is what i got :)




No comments:

Post a Comment