コード例 #1
0
 public void TurnWind(WindTurnType wt, float[,] Elevation, float seaLevel)
 {
     if (wt == WindTurnType.None)
     {
         // do nothing
     }
     else if (wt == WindTurnType.RandomWalk)
     {
         int r = UnityEngine.Random.Range(-1, 1);
         velocity = new Vec(velocity.x, r);
     }
     else if (wt == WindTurnType.TerrainBased)
     {
         if (Elevation[approxMapLoc.x, approxMapLoc.y] > seaLevel)
         {
             velocity.x -= deltaHeight;
             velocity.y -= deltaHeight;
             Vec    lVec    = velocity.GetRotatedVector(-90);
             Vec    rVec    = velocity.GetRotatedVector(90);
             MapLoc lMapLoc = new MapLoc((int)(Math.Max(1, actualMapLoc.x + lVec.x)), (int)Math.Max(1, actualMapLoc.y + lVec.y));
             MapLoc rMapLoc = new MapLoc((int)(Math.Max(1, actualMapLoc.x + rVec.x)), (int)Math.Max(1, actualMapLoc.y + rVec.y));
             try
             {
                 float fDiff = Elevation[lMapLoc.x, lMapLoc.y] - Elevation[rMapLoc.x, rMapLoc.y];
                 velocity.x += lMapLoc.x * fDiff;
                 velocity.y += lMapLoc.y * fDiff;
             }
             catch
             {
                 // ¯\_(ツ)_/¯
             }
         }
     }
 }