Beispiel #1
0
        /// <summary>
        /// Creates particles when deleted
        /// </summary>
        private void Death()
        {
            if (splash)
            {
                int maxParts = 8;
                int minParts = 4;

                if (shotType == 3)
                {
                    maxParts = 2; minParts = 1;
                }

                for (int i = 0; i <= GM.r.FloatBetween(minParts, maxParts); i++)
                {
                    float          spawnRot = RotationAngle + GM.r.FloatBetween(-15, 15);
                    Vector3        spawnVel = RotationHelper.Direction3DFromAngle(spawnRot, 0) * 200;
                    FadingParticle splash   = new FadingParticle(Position2D, spawnVel, spawnRot, 0.25f);
                    splash.Wash = Color.Aqua;
                    splash.SX   = 1f;
                    splash.SY   = 5f;
                }

                for (int i = 0; i <= GM.r.FloatBetween(0, 5); i++)
                {
                    float          spawnRot = -RotationAngle + GM.r.FloatBetween(-20, 20);
                    Vector3        spawnVel = RotationHelper.Direction3DFromAngle(spawnRot, 0) * -10;
                    FadingParticle splash   = new FadingParticle(Position2D, spawnVel, spawnRot, 0.1f);
                    splash.Wash = Color.Aqua;
                    splash.SX   = 1f;
                    splash.SY   = 2.5f;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructor for smoke particle
        /// </summary>
        /// <param name="spawnPos"></param>
        /// <param name="spawnVel"></param>
        /// <param name="spawnAngle"></param>
        /// <param name="lifetime">Minimum lifetime for particle in seconds</param>
        public FadingParticle(Vector2 spawnPos, Vector3 spawnVel, float spawnAngle, float lifetime)
        {
            //Init values
            GM.eventM.AddEvent(tiLifetime = new Event(lifetime + GM.r.FloatBetween(0, 0.1f), "Lifetime Counter"));
            GM.engineM.AddSprite(this);
            Frame.Define(Tex.SingleWhitePixel);
            ScaleBoth = 10;
            Wash      = Color.WhiteSmoke;
            Velocity  = spawnVel;
            float   rotRan   = GM.r.FloatBetween(-10f, 10f);
            Vector3 spawnRot = RotationHelper.Direction3DFromAngle(spawnAngle, 0);

            RotationHelper.FaceDirection(this, spawnRot, DirectionAccuracy.free, rotRan);
            Position2D = spawnPos;
            float xRan = GM.r.FloatBetween(-10f, 10f);
            float yRan = GM.r.FloatBetween(-10f, 10f);

            Position2D += new Vector2(xRan, yRan);

            UpdateCallBack += LifeCountdown;
        }
Beispiel #3
0
        /// <summary>
        /// Code to run upon hitting a sprite
        /// </summary>
        /// <param name="hit">The sprite collided with</param>
        private void Hit(Sprite hit)
        {
            if (hit is HitBox && GM.r.FloatBetween(0, 1) > 0.75)
            {
                HitBox hitBox = (HitBox)hit;
                //If the HitBox is a child, get its owner
                if (hitBox.Owner is HitBox)
                {
                    hitBox = (HitBox)hitBox.Owner;
                }
                //Check if the HitBox's ship is the ship that fired this CannonBall
                if (hitBox.Owner == owner)
                {
                    CollisionAbandonResponse = true;
                }
                else
                {
                    Ship ship = (Ship)hitBox.Owner;

                    //Debris
                    for (int i = 0; i <= GM.r.FloatBetween(0, 5); i++)
                    {
                        //float spawnRot = RotationAngle + 90 + GM.r.FloatBetween(-20, 20);
                        float          spawnRot = RotationHelper.AngleFromDirection(RotationHelper.MyDirection(this, 0)) + GM.r.FloatBetween(-40, 40);
                        Vector3        spawnVel = RotationHelper.Direction3DFromAngle(spawnRot, 0) * -200;
                        FadingParticle debris   = new FadingParticle(Position2D, spawnVel, spawnRot, 0.1f);
                        debris.Wash = Color.Brown;
                        debris.SX   = 3f + GM.r.FloatBetween(-2f, 2f);
                        debris.SY   = 3f + GM.r.FloatBetween(-2f, 2f);
                    }

                    if (hitBox.DamageType == 0) //Hull
                    {
                        if (shotType == 0)      //Ball
                        {
                            hitBox.Health -= (int)(10 * hitBox.DamageMul);
                            if (GM.r.FloatBetween(0, 1) > 0.5)
                            {
                                ship.CrewNum -= 1;
                            }
                        }
                        else if (shotType == 2)//Carcass
                        {
                            hitBox.Health -= (int)(2.5f * hitBox.DamageMul);
                            if (GM.r.FloatBetween(0, 1) > 0.80)
                            {
                                hitBox.IsBurning = true;
                            }
                            if (GM.r.FloatBetween(0, 1) > 0.5)
                            {
                                ship.CrewNum -= 1;
                            }
                        }
                        else if (shotType == 4 && GM.r.FloatBetween(0, 1) > 0.5f)//Grapple
                        {
                            Ship firedFrom = (Ship)owner;
                            if (!firedFrom.isBoarding && !firedFrom.isBoarded)
                            {
                                firedFrom.Board(ship);
                            }
                        }
                        else
                        {
                            hitBox.Health -= (int)(1 * hitBox.DamageMul);
                        }
                        if (shotType == 3 && GM.r.FloatBetween(0, 1) > 0.4f) //Grape
                        {
                            ship.CrewNum -= (int)GM.r.FloatBetween(1, 2);
                        }
                    }
                    else if (hitBox.DamageType == 1) //Sail
                    {
                        if (shotType == 1)           //Bar
                        {
                            hitBox.Health -= (int)(25 * hitBox.DamageMul);
                        }
                        else if (shotType == 2)//Carcass
                        {
                            hitBox.Health -= (int)(5 * hitBox.DamageMul);
                            if (GM.r.FloatBetween(0, 1) > 0.5)
                            {
                                hitBox.IsBurning = true;
                            }
                        }
                        else
                        {
                            //CollisionAbandonResponse = true;
                            hitBox.Health -= 1;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Code to run each second
        /// </summary>
        internal void OneSecond()
        {
            //Repairing
            if (IsRepairing)
            {
                float repairAmount = crewNum;

                //Spread repair amount amongst each part
                HitBox[] repairArray = new HitBox[7];
                int      repairNum   = 0;
                for (int i = 0; i <= 6; i++)
                {
                    if (hitBoxArray[i].Health < 100 && ((hitBoxArray[i].DamageType == 0 && hullRepMats > 0) || (hitBoxArray[i].DamageType == 1 && sailRepMats > 0)) || hitBoxArray[i].IsBurning)
                    {
                        repairArray[repairNum] = hitBoxArray[i];
                        repairNum++;
                    }
                }
                if (repairNum == 0)
                {
                    if (!rightLoaded)
                    {
                        tiReloadRight.Paused = false;
                    }
                    if (!leftLoaded)
                    {
                        tiReloadLeft.Paused = false;
                    }
                    IsRepairing = false;
                }
                else
                {
                    float repairPerPart = (repairAmount * 0.025f) / repairNum;
                    for (int i = 0; i < repairNum; i++)
                    {
                        repairArray[i].Health += repairPerPart;
                        if (repairArray[i].Health > 100)
                        {
                            repairArray[i].Health = 100;
                        }

                        if (repairArray[i].IsBurning && GM.r.FloatBetween(0, 1) > 0.9 * (0.9 - GameSetup.WeatherController.RainAmount))
                        {
                            repairArray[i].IsBurning = false;
                        }

                        if (repairArray[i].DamageType == 0)
                        {
                            hullRepMats -= (repairPerPart * 0.5f);
                        }
                        else
                        {
                            sailRepMats -= (repairPerPart * (3 / 2));
                        }
                    }
                }
            }

            //Calculations for sinking
            float hullHealthMissing = 0;

            for (int i = 0; i <= 3; i++)
            {
                hullHealthMissing += (100 - hitBoxArray[i].Health);
            }
            sinkAmount += (int)(hullHealthMissing * 0.15);
            if (GameSetup.WeatherController.RainAmount > 0.75f)
            {
                sinkAmount -= 4;
            }
            else
            {
                sinkAmount -= 6;
            }
            if (sinkAmount >= 1000)
            {
                //Splash
                for (int i = 0; i <= GM.r.FloatBetween(200, 400); i++)
                {
                    float          spawnRot = GM.r.FloatBetween(0, 360);
                    Vector3        spawnVel = RotationHelper.Direction3DFromAngle(spawnRot, 0) * 200;
                    FadingParticle splash   = new FadingParticle(Position2D, spawnVel, spawnRot, 0.25f);
                    splash.Wash = Color.Aqua;
                    splash.SX   = 1f;
                    splash.SY   = 5f;
                }
                Kill();
            }

            //Calculations for sail damage speed multiplier
            sailDamageSpeedMul = 0;
            for (int i = 4; i <= 6; i++)
            {
                sailDamageSpeedMul += hitBoxArray[i].Health;
            }
            sailDamageSpeedMul *= 0.003f;

            //Boarding checks
            if (isBoarded && isCuttingRopes)
            {
                if (GM.r.FloatBetween(0, 1) > 0.75f)
                {
                    isCuttingRopes = false;
                    isBoarded      = false;
                    GameSetup.BoardingInProgress = false;
                    if (isPlayer)
                    {
                        GameSetup.Opponent.isBoarding = false;
                    }
                    else
                    {
                        GameSetup.Player.isBoarding = false;
                    }
                }
            }
        }