首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

WPF/Silverlight 遊戲開發教程(三十五之一):地圖編輯器障礙物資料應用到遊戲專案

     編輯:關於C語言

以上節地圖為例,載入並繪製所有障礙物:

導出得 XML 障礙物資料:<Item ID="Obstruction" Value="240_0,241_0,238_1,239_1,240_1,236_2,237..." />

開啟遊戲專案 Config.xml,找到 <Map Sign="1"> 節點,加 Obstruction 屬性貼上 Value 值:

<Map Sign="1" Obstruction="240_0,241_0,238_1,239_1,240_1,236_2,237..." />

遊戲初始化讀取障礙物

byte[,] FixedObstruction = new byte[256, 256], VaryObstruction;

private void InitObstruction()
{
    for (int y = 0; y < FixedObstruction.GetUpperBound(1); y++)
        for (int x = 0; x < FixedObstruction.GetUpperBound(0); x++)
            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();
}

預設 1 可通行,0 障礙。解析 XML 資料標記障礙點,最後複製給動態陣列。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved