Ejemplo n.º 1
0
            private void generateIntersectionsOnCircle(int count, float radius)
            {
                var angleBetweenIntersections = 360.Degrees() / count;
                var levelRadius = radius * Constants.Game.World.HexagonWidth.U();

                var startAngle = Direction2.FromDegrees(StaticRandom.Float(360));

                var angleVariance = angleBetweenIntersections.Radians * 0.3f;

                for (var i = 0; i < count; i++)
                {
                    var angle = startAngle + angleBetweenIntersections * i
                                + StaticRandom.Float(-angleVariance, angleVariance).Radians();
                    var point = new Position2() + angle.Vector
                                * (levelRadius * StaticRandom.Float(0.8f, 1));
                    intersections.Add(point);
                }
            }
Ejemplo n.º 2
0
        public HitResult?TryHit(Ray ray)
        {
            var start     = ray.Start.NumericValue;
            var direction = ray.Direction.NumericValue;

            var topLeft     = this.TopLeft.NumericValue;
            var bottomRight = (this.TopLeft + this.Size).NumericValue;

            HitResult?result = null;

            var bestF = 1f;

            if (direction.X != 0)
            {
                { // left
                    var f = (topLeft.X - start.X) / direction.X;

                    if (f >= 0 && f < bestF)
                    {
                        var y = start.Y + direction.Y * f;

                        if (y >= topLeft.Y && y <= bottomRight.Y)
                        {
                            bestF  = f;
                            result = new HitResult(new Position2(topLeft.X, y), Direction2.FromDegrees(180), f,
                                                   start.X > topLeft.X);
                        }
                    }
                }
                { // right
                    var f = (bottomRight.X - start.X) / direction.X;

                    if (f >= 0 && f < bestF)
                    {
                        var y = start.Y + direction.Y * f;

                        if (y >= topLeft.Y && y <= bottomRight.Y)
                        {
                            bestF  = f;
                            result = new HitResult(new Position2(bottomRight.X, y), Direction2.FromDegrees(0), f,
                                                   start.X < bottomRight.X);
                        }
                    }
                }
            }

            if (direction.Y != 0)
            {
                { // top
                    var f = (topLeft.Y - start.Y) / direction.Y;

                    if (f >= 0 && f < bestF)
                    {
                        var x = start.X + direction.X * f;

                        if (x >= topLeft.X && x <= bottomRight.X)
                        {
                            bestF  = f;
                            result = new HitResult(new Position2(x, topLeft.Y), Direction2.FromDegrees(270), f,
                                                   start.Y > topLeft.Y);
                        }
                    }
                }
                { // bottom
                    var f = (bottomRight.Y - start.Y) / direction.Y;

                    if (f >= 0 && f < bestF)
                    {
                        var x = start.X + direction.X * f;

                        if (x >= topLeft.X && x <= bottomRight.X)
                        {
                            bestF  = f;
                            result = new HitResult(new Position2(x, bottomRight.Y), Direction2.FromDegrees(90), f,
                                                   start.Y < bottomRight.Y);
                        }
                    }
                }
            }

            return(result);
        }