C # development Wpf/silverlight animation and games series Tutorials (Game Course): (35) The preliminary use of the map editor
In the last section we made the map editor, and initially realized the obstacle information in the export map and realized A * simulation search. So when we get the XML file that contains the information about the obstacles, how do we apply it to the example game in this tutorial?
As an example of the map in the above section, we first load the map through the editor and sketch all the obstacles on it:
Then click the Export Obstacle button and we will get an XML obstacle data file that contains information similar to the following:
<Item ID="Obstruction" Value="240_0,241_0,238_1,239_1,240_1,236_2,237……>
Next, open the Config.xml configuration file in the sample game project and find the <map sign= "1" > this represents the node on map 1th. Add a property named obstruction to this node and copy the value values from the data information XML file that you just exported to the obstruction attribute value, and the final modification results are as follows:
<Map Sign="1" Obstruction="240_0,241_0,238_1,239_1,240_1,236_2,237……>
After the obstacle is set, we also need to read it in the map obstacle initialization:
//障碍物固定值与变动值(二维矩阵)
byte[,] FixedObstruction = new byte[256, 256], VaryObstruction;
/// <summary>
/// 初始化障碍物
/// </summary>
private void InitObstruction() {
for (int y = 0; y < FixedObstruction.GetUpperBound(1); y++) {
for (int x = 0; x < FixedObstruction.GetUpperBound(0); x++) {
//设置默认值,可以通过的均在矩阵中用1表示
FixedObstruction[x, y] = 1;
}
}
string[] obstruction = Super.GetTreeNode(
Super.SystemConfig, "Map", "Sign", "1").Attribute("Obstruction").Value.Split(',');
string[] str;
for (int i = 0; i < obstruction.Count(); i++) {
str = obstruction[i].Split('_');
FixedObstruction[Convert.ToInt32(str[0]), Convert.ToInt32(str[1])] = 0;
}
VaryObstruction = (byte[,])FixedObstruction.Clone();
}