Example #1
0
        public void AddStars(Random r, int nos, InfinityPlayer player)
        {
            // flo
            NumberofStars = nos;

            for (int i = 0; i < NumberofStars; i++)
            {
                var pos = Size * new Vector(r.NextDouble(), r.NextDouble());
                var add = true;

                // check if star is behind planet
                foreach (Tile tile in Neighbors)
                {
                    foreach (Planet planet in tile.Planets)
                    {
                        if ((tile.Position + planet.Position - Position - pos).Length <= planet.Radius)
                        {
                            add = false;
                            break;
                        }
                    }
                }

                if (add)
                {
                    Star newStar = new Star(pos);
                    Stars.Add(newStar);
                }
            }
        }
Example #2
0
 public void DiscoverPlanets(InfinityPlayer player)
 {
     foreach (Tile tile in Neighbors)
     {
         foreach (Planet planet in tile.Planets)
         {
             planet.Explore(tile.Position, player);
         }
     }
 }
Example #3
0
 public void DiscoverStars(InfinityPlayer player)
 {
     foreach (Tile tile in Neighbors)
     {
         foreach (Star star in tile.Stars)
         {
             if ((tile.Position + star.Position - player.Position).Length < player.View)
             {
                 star.IsDiscovered = true;
             }
         }
     }
 }
Example #4
0
        public void Explore(Vector posTile, InfinityPlayer player)
        {
            var p  = player.Position - posTile;
            var v  = player.View;
            var pp = Position - p;
            var d  = pp.Length;

            if (d < v + Radius && !IsFullyDiscovered)
            {
                var a  = (Radius * Radius - v * v + d * d) / (2 * d);
                var p2 = Position - a * pp / d;
                var h  = Math.Sqrt(Radius * Radius - a * a);

                var x1 = p2.X + h * (p.Y - Position.Y) / d - Position.X;
                var x2 = p2.X - h * (p.Y - Position.Y) / d - Position.X;
                var y1 = p2.Y - h * (p.X - Position.X) / d - Position.Y;
                var y2 = p2.Y + h * (p.X - Position.X) / d - Position.Y;

                var alpha1 = Math.Atan2(y1, x1);
                var alpha2 = Math.Atan2(y2, x2);

                if (alpha1 < alpha2)
                {
                    Alphas = Merge(Alphas, new Interval(alpha1, alpha2));
                }
                if (alpha1 > alpha2)
                {
                    Alphas = Merge(Alphas, new Interval(alpha1, Math.PI));
                    Alphas = Merge(Alphas, new Interval(-Math.PI, alpha2));
                }

                if (Alphas.Count == 1 && Alphas[0].A == -Math.PI && Alphas[0].B == Math.PI)
                {
                    IsFullyDiscovered = true;
                }
            }
        }