示例#1
0
        public static void FireRocket(Car sender)
        {
            Rocket tempRocket = new Rocket();
            if (sender.LastFire >= tempRocket.ReloadTime)
            {
                tempRocket.Initialize();
                tempRocket.LoadContent();

                rockets.Add(tempRocket);
                rockets[rockets.Count - 1].Fire(sender);

                //Set the last fire to 0
                sender.LastFire = 0;
            }
        }
示例#2
0
        public void HitRocket(Rocket rocket)
        {
            Vector2 momentum;

            //First, I want the angle of impact from both cars
            float dx = rocket.Position.X - position.X;
            float dy = rocket.Position.Y - position.Y;

            float angleOfImpact = (float)Math.Atan(dy / dx);

            //If dx is lower than 0, the tanges returns the angle on the wrong side of the
            //Unit circle, this needs to be corrected
            if (dx < 0)
            {
                angleOfImpact += (float)Math.PI;
            }

            //Set the range of the angle between 0 and 2*PI
            while (angleOfImpact > 2 * Math.PI)
            {
                angleOfImpact -= 2 * (float)Math.PI;
            }

            while (angleOfImpact < 0)
            {
                angleOfImpact += 2 * (float)Math.PI;
            }

            momentum = new Vector2((1f - (rocket.ExplosionBounds.Radius / rocket.DamageRange)) * -(float)Math.Cos(angleOfImpact) * 15, (1f - (rocket.ExplosionBounds.Radius / rocket.DamageRange)) * -(float)Math.Sin(angleOfImpact) * 15);

            speed = 0;
            TakeMomentum(momentum);
        }