Beispiel #1
0
        /// <summary>
        /// creates the inner shell and fires it after the first explosion
        /// </summary>
        private void InnerShell()
        {
            //work out the new bullet angle
            // in the constructor we have a formula to work out the velocity from the angle
            // to find the angle we just reverse the formula
            // velocityY = Math.Sin(angleRadians) * -bulletPower
            // velocityY/-bulletPower = Math.Sin(angleRadians)
            // Math.Asin(velocityY/-bulletPower) = angleRadians
            //now we can get the radians on the angle for the bullet
            double newBulletAngle;
            // before arc sin can be done we need to find the current radian minus any whole rotations
            double fullRadiansCal = velocityY / bulletPower;

            //reduce the radians to find current heading
            while (fullRadiansCal > 1)
            {
                fullRadiansCal -= 1;
            }
            //work out radians angle for bullet
            newBulletAngle = -1 * Math.Asin(Math.Abs(fullRadiansCal));
            // use the radians to get the using the formula in the constructor
            // radians = (90 - angle) * (float)Math.PI / 180
            // radians/(Math.PI/180) = 90-angle
            // (radians/(Math.PI/180))-90 = -angle
            //-1 * ( (radians/ (Math.PI/180) ) -90 ) =  angle
            newBulletAngle = -1 * ((newBulletAngle / (Math.PI / 180)) - 90);

            int innerDamage     = 30;
            int innerRadius     = 3;
            int innerDestRadius = 4;
            int travelDist      = 3;

            bulletPower = bulletPower * 50; // gets the orginal power of the bullet
            //create explosion
            Explosion innerExplosion;

            innerExplosion = new Explosion(innerDamage,
                                           innerRadius,
                                           innerDestRadius);
            //create new bullet
            Bullet innerBullet;

            // check the velocity to see if the bullet was falling or rising
            newBulletAngle = (velocityY <= 0) ? (newBulletAngle *= -1f) : (newBulletAngle);
            // work out which way the bullet is travelling to adjust the next shots begining point
            if (bulletAngle > 0)
            {
                //bullet is travelling to the left , new bullet should appear to the left
                bulletX = bulletX + travelDist;
                bulletY = bulletY + travelDist;
            }
            if (bulletAngle < 0)
            {
                //bullet is travelling to the right , new should appear to the right
                bulletX = bulletX - travelDist;
                bulletY = bulletY - travelDist;
            }
            //check the angle isn't outside bounds -90 or 90
            //change back to limits of game
            newBulletAngle = (newBulletAngle < -90) ? (-90) : (newBulletAngle);
            newBulletAngle = (newBulletAngle > 90) ? (90) : (newBulletAngle);
            //create the inner shell with defined parameters
            innerBullet = new Bullet(bulletX,
                                     bulletY,
                                     (float)newBulletAngle,
                                     bulletPower,
                                     this.bulletGravity,
                                     innerExplosion,
                                     bulletOwner
                                     );
            //add the bullet into the battle environment
            currrentGame.AddEffect(innerBullet);
        }
Beispiel #2
0
        private float bulletPower;         // stores the power of the bullet

        /// <summary>
        /// creates a new bullet
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="angle"></param>
        /// <param name="power"></param>
        /// <param name="gravity"></param>
        /// <param name="explosion"></param>
        /// <param name="player"></param>
        public PierceBullet(float x, float y, float angle, float power, float gravity, Explosion explosion, GenericPlayer player)
        {
            // set default values of the new bullet
            bulletX         = x;
            bulletY         = y;
            bulletGravity   = gravity;
            bulletExplosion = explosion;
            bulletOwner     = player;
            // now work out how fast this bullet is moving
            // workout direction and quickness of bullet
            float angleRadians = (90 - angle) * (float)Math.PI / 180; // direction of bullet
            float magnitude    = power / 50;                          // movement vector of bullet

            // calculate velocity
            velocityX = (float)Math.Cos(angleRadians) * magnitude;
            velocityY = (float)Math.Sin(angleRadians) * -magnitude;
            //store bullet properties
            bulletAngle = angleRadians;
            bulletPower = magnitude;
        }