1. Introduction
In the last tutorial we concluded with a simple script to create points in 3D space so you can build terrain. It looks great, but let's add some finer details like water and sand to make it look even better :)
Currently the terrain looks like this:
2. How do we render water and sand?
Most Developers typically do this based on height. If we have our origin at 0, 0, 0 we can assume at a certain height the water will stop. Sand will be slightly higher than the water, so we can assume that sand will be a few vertices higher than the water level.
3. How do we know what the water level is for each level?
In the folder we extracted in the previous tutorial, you will see a file called leveldata.xml
open this file and in the xml tag LevelInfo, you will see an attribute called WaterLevel.
This is how far up the water stops in the terrain mesh. Now that we have the water level, let's update our code to render different colors for water and sand.
248 is specific to df1 (ishalgen), it we take a look at lf1 (poeta) we can see the water level is only 100 which is different so make sure you read the level data file for each map before rendering water. I've hard coded 248 in for simplicity.
4. Updating our code to render colors.
The full code with this update can be found on my github in my signature.Code:water_level = 248 if z <= water_level: #render color blue elif z <= water_level + 2: #render sand color else: #render green for grass and hills.
5. The end result is great!
Below is the end result, it looks a lot better now. I rendered sand as red just for fun.
till next time, bye bye!







Reply With Quote![[Tutorial] Water levels and sand.](http://ragezone.com/hyper728.png)

