public virtual void Draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Draw(this.texture, new Vector2(MyMath.MetersToPixel(base.position.X), MyMath.MetersToPixel(base.position.Y)), null, Color.White, MathHelper.ToRadians(base.rotation), origin, scaleFactor, SpriteEffects.None, 0);
 }
Beispiel #2
0
 public void Draw(SpriteBatch spriteBach)
 {
     Primitive.DrawCircle(spriteBach, new Vector2(MyMath.MetersToPixel(position.X), MyMath.MetersToPixel(position.Y)), MyMath.MetersToPixel(radius), 20, this.color);
 }
 public void Draw(SpriteBatch spriteBach)
 {
     SetRotationFromMousePosition(Mouse.GetState().Position);
     spriteBach.Draw(this.texture, new Vector2(MyMath.MetersToPixel(base.position.X), MyMath.MetersToPixel(base.position.Y)), null, Color.White, base.rotation, origin, scaleFactor, SpriteEffects.None, 0);
 }
        private void SetRotationFromMousePosition(Point mousePosition)
        {
            Vector2 aux = new Vector2(mousePosition.X, mousePosition.Y) - new Vector2(MyMath.MetersToPixel(base.position.X), MyMath.MetersToPixel(base.position.Y));

            rotation = (float)Math.Atan2(aux.Y, aux.X);

            base.rotation = rotation;
        }
Beispiel #5
0
        public void Update()
        {
            base.CheckWindowCollisions();
            base.ApplyWindForce();

            if (MyMath.IsBallCollided(base.position, Game1.targetBall.position))
            {
                Game1.targetBall.ballState = BallState.MOVING;
                this.ballState             = BallState.MOVING;

                /*
                 * float collisionAngle = (float)Math.Atan2(position.Y - Game1.targetBall.position.Y, position.X - Game1.targetBall.position.X);
                 * Game1.targetBall.velocity.X = ((float)(MyMath.GetMagnitude(base.velocity) * Math.Cos(collisionAngle)));
                 * Game1.targetBall.velocity.Y = ((float)(MyMath.GetMagnitude(base.velocity) * Math.Cos(MathHelper.ToRadians(90) + collisionAngle)));
                 * base.velocity.X = (float)(MyMath.GetMagnitude(base.velocity) * Math.Sin(MathHelper.ToRadians(90) + collisionAngle));
                 * base.velocity.Y = (float)(MyMath.GetMagnitude(base.velocity) * Math.Sin(MathHelper.ToRadians(90) + collisionAngle));*/


                Game1.targetBall.velocity.X = (float)(base.velocity.X * Math.Cos(-Game1.mouseArrow.rotation));
                Game1.targetBall.velocity.Y = (float)(base.velocity.Y * Math.Sin(-Game1.mouseArrow.rotation));
                base.velocity.X             = (float)(base.velocity.X * Math.Cos(Game1.mouseArrow.rotation - MathHelper.ToRadians(90)));
                base.velocity.Y             = (float)(base.velocity.Y * Math.Sin(Game1.mouseArrow.rotation - MathHelper.ToRadians(90)));

                //Console.WriteLine("Colisiono con target");
            }

            if (MyMath.IsBallCollided(base.position, Game1.enemyBall.position))
            {
                Game1.enemyBall.ballState = BallState.MOVING;
                this.ballState            = BallState.MOVING;

                /*
                 * float collisionAngle = (float)Math.Atan2(position.Y - Game1.targetBall.position.Y, position.X - Game1.targetBall.position.X);
                 * Game1.enemyBall.velocity.X = ((float)(MyMath.GetMagnitude(base.velocity) * Math.Cos(collisionAngle)));
                 * Game1.enemyBall.velocity.Y = ((float)(MyMath.GetMagnitude(base.velocity) * Math.Cos(MathHelper.ToRadians(90) - collisionAngle)));
                 * base.velocity.X = (float)(MyMath.GetMagnitude(base.velocity) * Math.Sin(MathHelper.ToRadians(90) - collisionAngle));
                 * base.velocity.Y = (float)(MyMath.GetMagnitude(base.velocity) * Math.Sin(MathHelper.ToRadians(90) - collisionAngle));*/



                Game1.enemyBall.velocity.X = (float)(base.velocity.X * Math.Cos(-Game1.mouseArrow.rotation));
                Game1.enemyBall.velocity.Y = (float)(base.velocity.Y * Math.Sin(-Game1.mouseArrow.rotation));
                base.velocity.X            = (float)(base.velocity.X * Math.Cos(Game1.mouseArrow.rotation - MathHelper.ToRadians(90)));
                base.velocity.Y            = (float)(base.velocity.Y * Math.Sin(Game1.mouseArrow.rotation - MathHelper.ToRadians(90)));


                //Console.WriteLine("Colisionó con enemigo");
            }


            if (Game1.enemyBall.ballState == BallState.STATIC && Game1.targetBall.ballState == BallState.STATIC && MyMath.GetMagnitude(base.velocity) <= 0.005f && ballState == BallState.MOVING)
            {
                Console.WriteLine("Parar bola");
                ballState = BallState.STATIC;
                Game1.mouseArrow.UpdatePosition();
            }
        }