Exemplo n.º 1
0
        public static double GetLength(Pnt p1, Pnt p2)
        {
            double dx = p2.x - p1.x;
            double dy = p2.y - p1.y;

            return(Math.Sqrt(dx * dx + dy * dy));
        }
Exemplo n.º 2
0
 public Food(Pnt point, double meat, double herb, double water)
 {
     this.point = point;
     this.meat  = meat;
     this.herb  = herb;
     this.water = water;
 }
Exemplo n.º 3
0
        public void FoodTick(double time)
        {
            double realTime = time;

            time += bufferedTime;

            double totalFertility = area * fertility / 1000;

            if (totalFertility * time < 1)
            {
                bufferedTime = time;
                return;
            }

            bufferedTime = 0;

            lock (food)
            {
                if (food.Count >= maxFoodCount)
                {
                    return;
                }

                int count = (int)(totalFertility * time);
                for (int i = 0; i < count; i++)
                {
                    Pnt point = new Pnt(rnd.Next((int)leftLifeBorder, (int)rightLifeBorder), rnd.Next((int)topLifeBorder, (int)bottomLifeBorder));
                    food.Add(new Food(point, rnd.NextDouble(), rnd.NextDouble(), rnd.NextDouble()));
                }
            }
        }
Exemplo n.º 4
0
        private bool pointInTriangle(Pnt pt, Pnt v1, Pnt v2, Pnt v3)
        {
            bool b1, b2, b3;

            b1 = sign(pt, v1, v2) < 0;
            b2 = sign(pt, v2, v3) < 0;
            if (b1 != b2)
            {
                return(false);
            }
            b3 = sign(pt, v3, v1) < 0;
            return(b2 == b3);
        }
Exemplo n.º 5
0
 public void updatePoints()
 {
     centerP    = new Pnt(x, y);
     farCenterP =
         new Vector(moveVector.alpha, viewDepth * radius)
         .setStart(x, y)
         .getEnd();
     leftP =
         new Vector(moveVector.alpha - Math.PI / 2, viewWidth / 2 * radius) //rotate to -90 degrees
         .setStart(farCenterP)
         .getEnd();
     rightP =
         new Vector(moveVector.alpha + Math.PI / 2, viewWidth / 2 * radius) //rotate to 90 degrees
         .setStart(farCenterP)
         .getEnd();
 }
Exemplo n.º 6
0
 public Vector setStart(Pnt point)
 {
     return(move(point.x - x1, point.y - y1));
 }
Exemplo n.º 7
0
 public Vector(Pnt p1, Pnt p2)
     : this(p1.x, p1.y, p2.x, p2.y)
 {
 }
Exemplo n.º 8
0
 private double sign(Pnt p1, Pnt p2, Pnt p3)
 {
     return((p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y));
 }