国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

SLG中搜索某個角色可移動區域的算法

2019-11-18 14:55:27
字體:
來源:轉載
供稿:網友

可根據地形的不同,以及角色能力的不同來判定可移動區域。例如騎士在平地上可以移動更大的范圍。

代碼如下:

 /**
  * 搜索可走區域
  * @param map 當前地圖表
  * @param row 行
  * @param col 列
  * @param locomotivity 該角色的默認移動力
  * @param direction 方向
  */
 public void scanMovableArea(byte map[][], int row, int col, int locomotivity, int direction){
  if(locomotivity > map[row][col])
   map[row][col] = (byte)locomotivity;
  else
   return;
  
  /** 向上判定 **/
  if(direction != 1){
   int loco1 = locomotivity - mapEXPendLocomotivity(row, col - 1);
   if(loco1 >=0)
    scanMovableArea(map, row, col - 1, loco1, 2);
  }
  
  /** 向下判定 **/
  if(direction != 2){
   int loco2 = locomotivity - mapExpendLocomotivity(row, col + 1);
   if(loco2 >= 0)
    scanMovableArea(map, row, col + 1, loco2, 1);
  }
  
  /** 向左判定 **/
  if(direction != 4){
   int loco3 = locomotivity - mapExpendLocomotivity(row - 1, col);
   if(loco3 >= 0)
    scanMovableArea(map, row - 1, col, loco3, 8);
  }
  
  /** 向右判定 **/
  if(direction != 8){
   int loco4 = locomotivity - mapExpendLocomotivity(row + 1, col);
   if(loco4 >= 0)
    scanMovableArea(map, row + 1, col, loco4, 4);
  }
 }

----------------------------------------------

 /**
  * 地形對移動力的消耗
  * @param row 行
  * @param col 列
  * @return 移動力消耗值
  */

public int mapExpendLocomotivity(int row, int col){

   //這里我就不一一實現了,有愛好的朋友可以自己擴展這個方法。

   //下面給個偽代碼

   //假如是草地

  if(gameMap[row][col] == GAME_MAP_GRASS){

    //假如是士兵


   if(type == SOLIDER){
    return 1;
    }
  }

   //超出邊界

  if(row < 0 col < 0 row > gameWidth col > gameHeight)

  {

      return 1000;

  }

  //具體的情況各位朋友可以根據自己的游戲來設計。

}

找到可以移動的區域后,就可以確定要移動的具體位置。這時候又要涉及到找路算法了。對于與A*算法(以前有一位同事寫過)。不過下次我會用遞歸算法來實現,速度更快,更簡單。



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 衢州市| 西丰县| 平山县| 卢氏县| 洞口县| 怀远县| 油尖旺区| 镇康县| 荆州市| 南木林县| 南漳县| 西和县| 盐城市| 多伦县| 安义县| 广宁县| 左贡县| 玛多县| 车险| 长白| 仁布县| 全南县| 申扎县| 贵港市| 新安县| 锡林浩特市| 嘉义县| 明水县| 英山县| 长白| 兴安盟| 辽宁省| 平陆县| 湘乡市| 冷水江市| 应城市| 杭锦后旗| 和静县| 新邵县| 汕头市| 道孚县|