예제 #1
0
        // simple drawing of 1 pixel line using bresnenhams
        public static void DrawLine(this SpriteBatch @this, Vector2 start, int length, float angleInDegrees, Color Colour)
        {
            var texture = SpriteBatchExtensions.GetOnePixelTexture(@this.GraphicsDevice);

            var endVector = GeneralExtensions.UnitAngleVector(angleInDegrees, length);
            // negation of x was ngation of y not sure why it works.
            var endPoint = start + endVector;
            // create the list of points
            var lineData = Bresenham.GetLine(start.ToPoint(), endPoint.ToPoint());

            lineData.ToList().ForEach(a => @this.Draw(texture, a.ToVector2(), Color.White));
        }
예제 #2
0
        public override void FixedUpdate()
        {
            base.FixedUpdate();

            if (BeingDestroyed || Destroyed)
            {
                return;
            }

            if (hero != null)
            {
                line.Clear();
                Bresenham.GetLine(Transform.Position + middleOffset, hero.Transform.Position + new Vector2(0, -8), line);
                seesHero = Bresenham.CanLinePass(Transform.Position + middleOffset, hero.Transform.Position + new Vector2(0, -8), (x, y) => {
                    return(Scene.GridCollisionChecker.HasBlockingColliderAt(new Vector2(x / Config.GRID, y / Config.GRID), Direction.CENTER));
                });

                if (seesHero)
                {
                    //seesHero &= (CurrentFaceDirection == Direction.EAST && hero.Transform.X > Transform.X || CurrentFaceDirection == Direction.WEST && hero.Transform.X < Transform.X);
                    if (hero.Transform.X < Transform.X)
                    {
                        CurrentFaceDirection = Direction.WEST;
                    }
                    else
                    {
                        CurrentFaceDirection = Direction.EAST;
                    }
                }
            }
            else
            {
                seesHero = false;
            }

            if (seesHero)
            {
                sprite.Rotation = MathUtil.RadFromVectors(Transform.Position, hero.Transform.Position) - sprite.BaseRotation;
                Fire();
            }
        }