private void HurtBlip(Projectile projectile, RadarBlip blip)
        {
            #region See if a split should occur

            if (blip.CollisionStyle != CollisionStyle.Standard)
            {
                return;
            }

            if (!(blip is BallBlip))
            {
                return;
            }

            BallBlip castBlip = (BallBlip)blip;

            double ratio = projectile.Pain / castBlip.Ball.Mass;
            double rand = _rand.NextDouble();

            if (ratio < rand)
            {
                return;
            }

            #endregion

            #region Calculate Split Percents

            int numParts = 2 + _rand.Next(3);		// between 2 and 4 parts
            double[] splitPercents = new double[numParts];

            double remainder = 1d;

            for (int cntr = 0; cntr < numParts - 1; cntr++)
            {
                splitPercents[cntr] = _rand.NextDouble() * remainder;
                remainder -= splitPercents[cntr];
            }
            splitPercents[numParts - 1] = remainder;

            #endregion

            #region Build Objects

            _map.Remove(blip.Token);

            foreach (double percent in splitPercents)
            {
                double size = castBlip.Ball.Mass * percent;

                if (size < 20)
                {
                    continue;
                }

                Ball ball;
                if (castBlip.Ball is SolidBall)
                {
                    ball = new SolidBall(castBlip.Ball.Position.Clone(), castBlip.Ball.OriginalDirectionFacing.Clone(), size, size, castBlip.Ball.Elasticity, castBlip.Ball.KineticFriction, castBlip.Ball.StaticFriction, _boundryLower, _boundryUpper);
                }
                else
                {
                    ball = new Ball(castBlip.Ball.Position.Clone(), castBlip.Ball.OriginalDirectionFacing.Clone(), size, size, castBlip.Ball.Elasticity, castBlip.Ball.KineticFriction, castBlip.Ball.StaticFriction, _boundryLower, _boundryUpper);
                }

                ball.Velocity.StoreNewValues(castBlip.Ball.Velocity);

                //TODO:  Lay them out so they aren't touching each other.  The smallest ones should be closest
                // to the point of impact (maybe give them slightly tweaked velocities as well so they explode
                // outward)

                _map.Add(new BallBlip(ball, blip.CollisionStyle, blip.Qual, TokenGenerator.NextToken()));
            }

            #endregion
        }
예제 #2
0
        public void DrawProjectile(Projectile projectile, DrawMode drawMode, bool drawRed)
        {
            Color fillColor, penColor;
            int opacity = STANDARDBALLFILLOPACTIY;
            #region Figure out the color

            if (drawRed)
            {
                fillColor = REDCOLOR;
                penColor = _standardPenColor;
            }
            else if (projectile.State == ProjectileState.Flying)
            {
                fillColor = Color.Black;
                penColor = Color.White;
            }
            else if (projectile.State == ProjectileState.Exploding)
            {
                fillColor = Color.FromArgb(250, Color.DarkOrange);
                penColor = Color.Yellow;
                opacity = 64;
            }
            else if (projectile.State == ProjectileState.Dying)
            {
                return;
            }
            else
            {
                throw new ApplicationException("Unknown ProjectileState: " + projectile.State.ToString());
            }

            #endregion

            // Fill the circle
            using (Brush brush = new SolidBrush(Color.FromArgb(opacity, fillColor)))
            {
                _viewer.FillCircle(brush, projectile.Ball.Position, projectile.Ball.Radius);
            }

            #region Draw the edge

            switch (drawMode)
            {
                case DrawMode.Standard:
                    _viewer.DrawCircle(penColor, STANDARDOUTLINEWIDTH, projectile.Ball.Position, projectile.Ball.Radius);
                    break;

                case DrawMode.Selected:
                    _viewer.DrawCircle_Selected(projectile.Ball.Position, projectile.Ball.Radius);
                    break;
            }

            #endregion

            //TODO:  Show Stats
        }
예제 #3
0
        private bool Fire()
        {
            // Before I begin, try to grab some ammo
            //if(_useAmmoClip && _ammoClip.RemoveQuantity(_amtAmmoToPull, true) > 0)
            //{
            //    return false;
            //}

            // The ammo has been grabbed, bump the elapsed time structure
            _elapsedTime.InnerFiringRate = _firingModes[_activeFiringMode].InnerFiringRate;
            _elapsedTime.NumRoundsPerOuter++;

            // Fire each barrel
            foreach (Barrel barrel in _barrels)
            {
                #region Fire New Projectile

                // Create the position
                MyVector position = _ship.Ball.Position.Clone();
                if (barrel.Offset != null)
                {
                    position = _ship.Ball.Rotation.GetRotatedVector(barrel.Offset, true) + position;
                }

                // Create the direction facing
                DoubleVector dirFacing = _ship.Ball.DirectionFacing.Clone();
                if (barrel.Rotation != null)
                {
                    dirFacing = barrel.Rotation.GetRotatedVector(dirFacing, true);
                }

                // Make a ball
                Ball ball = null;
                if (_useBoundry)
                {
                    ball = new Ball(position, dirFacing, _projectileSettings.Radius, _projectileSettings.Mass, _boundryLower, _boundryUpper);
                }
                else
                {
                    ball = new Ball(position, dirFacing, _projectileSettings.Radius, _projectileSettings.Mass);
                }

                MyVector dirFacingUnit = dirFacing.Standard;
                dirFacingUnit.BecomeUnitVector();

                // Set the velocity
                ball.Velocity.StoreNewValues(dirFacingUnit * _projectileSettings.Speed);
                ball.Velocity.Add(_ship.Ball.Velocity);

                // Make a projectile
                Projectile projectile = new Projectile(ball, _ship.Token, _projectileSettings.IgnoreOtherProjectiles, _projectileSettings.Pain, _map, _projectileSettings.Qual, TokenGenerator.NextToken());

                // Set up explosion and fuse settings
                if (_projectileSettings.Explosion != null)
                {
                    projectile.SetExplosion(_projectileSettings.Explosion.Radius, _projectileSettings.Explosion.Duration, _projectileSettings.Explosion.Force);
                }
                if (_projectileSettings.Fuse != null)
                {
                    projectile.SetFuse(_projectileSettings.Fuse.Duration);
                }

                // Generate the kick
                if (_produceKick)
                {
                    #region Kick

                    MyVector kick = dirFacingUnit * _projectileSettings.Speed * (ball.Mass * -1d);

                    if (_ship.TorqueBall != null)
                    {
                        _ship.TorqueBall.ApplyExternalForce(ball.Position - _ship.Ball.Position, kick);
                    }
                    else
                    {
                        _ship.Ball.ExternalForce.Add(kick);
                    }

                    #endregion
                }

                // Hand the projectile to the map
                _map.Add(projectile);

                #endregion
            }

            // Exit function
            return true;
        }