Step one in the programming tasks was to randomly generate the map. After creating some rough prefabs (red squares for mountains, yellow for desert and a small particle effect for the geysers) I got to coding.
The Node Class (above) holds all of the information about a particular square. My game controller creates a 2D array of nodes the length and width of the selected map. Using a nested for loop, each node in the array is then given a coord in world space (each prefab is 4 units across so the location is the Position in the array * 4)
Then the game runs passes to set 3 random squares to oil (but only if those squares are currently not defined, and not next to an oil square and not near the home areas in the middle of each side)
One quarter of the squares are then randomly turned into mountains (but again, not near the middle of each side)
The remaining undefined nodes are then set to desert.
I then run a function which runs through each node and creates the appropriate prefab (based on the nodes type) at the appropriate place (based on the nodes location)
This function will be greatly expanded to include randomly selected desert prefabs and intelligently selected mountain prefabs connecting to each other.
The prefabs are all stored in a second 2d array, allowing me to access them later when changing the prefabs to have pipes on them
Here is a quick preview of my early map
No comments:
Post a Comment