C # development Wpf/silverlight animation and games series Tutorials (Game Course): (35)

Source: Internet
Author: User
Tags split silverlight

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();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.