Beispiel #1
0
 /// <summary>
 /// Code to run each tick.
 /// </summary>
 private void Tick()
 {
     SY            = Vector2.Distance(origin.Position2D, target.Position2D);
     RotationAngle = RotationHelper.AngleFromDirection(Vector2.Normalize(target.Position2D - origin.Position2D));
     Position2D    = origin.Position2D - ((origin.Position2D - target.Position2D) * 0.5f);
     if (!(GameSetup.Player.isBoarded || GameSetup.Player.isBoarding))
     {
         Kill();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Constructor for Arrow
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="Target"></param>
        public Arrow(Vector2 origin, Vector2 Target)
        {
            target = Target;

            GM.engineM.AddSprite(this);
            Frame.Define(Tex.SingleWhitePixel);
            SX    = 2;
            Wash  = Color.Beige;
            Alpha = 0.75f;

            SY            = Vector2.Distance(origin, target);
            RotationAngle = RotationHelper.AngleFromDirection(Vector2.Normalize(target - origin));
            Position2D    = origin - ((origin - target) * 0.5f);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor for hitbox
        /// </summary>
        /// <param name="hitBoxOwner">Parent of the hitbox</param>
        /// <param name="offsetFromOwner">Offset from owner centre when facing up - this can never be zero!</param>
        /// <param name="dimensions">Height and Width of hitbox</param>
        /// <param name="damageMultiplier">Damage taken is multiplied by this amount</param>
        /// <param name="type">Type of damage taken by hitbox - 0 hull, 1 sail</param>
        public HitBox(Sprite hitBoxOwner, Vector2 offsetFromOwner, Vector2 dimensions, float damageMultiplier, int type)
        {
            //Init values
            damageMul  = damageMultiplier;
            damageType = type;
            health     = 100;
            owner      = hitBoxOwner;

            offsetVector    = new Vector2(offsetFromOwner.X, -offsetFromOwner.Y);
            offsetMagnitude = offsetVector.Length();
            offsetVector.Normalize();
            offsetAngle = RotationHelper.AngleFromDirection(offsetVector);

            GM.engineM.AddSprite(this);
            Frame.Define(Tex.SingleWhitePixel);
            SpriteHelper.ScaleToThisSize(this, dimensions.X, dimensions.Y);

            if (owner is HitBox)
            {
                isParent         = false;
                CollisionActive  = true;
                CollisionPrimary = true;
                Visible          = false;

                //Debug
                CollisionBoxVisible = true;
                Visible             = true;
            }
            else
            {
                isParent         = true;
                CollisionActive  = false;
                CollisionPrimary = false;
                Visible          = true;
                Wash             = Color.Red;
                Alpha            = 0.75f;
                WashCollision    = Color.Red;
                CreateCollisionArea(10);
            }

            GM.eventM.AddTimer(tiBurnTick = new Event(1, "Burn Tick"));
            PrologueCallBack += Hit;
            UpdateCallBack   += Tick;
        }
Beispiel #4
0
        /// <summary>
        /// Check for keypresses used to end game
        /// </summary>
        public override void Tick()
        {
            //Point to opponent if off screen
            if (opponent.Position2D.X < playerView.ViewPortOutline.Left || opponent.Position2D.X > playerView.ViewPortOutline.Right || opponent.Position2D.Y < playerView.ViewPortOutline.Top || opponent.Position2D.Y > playerView.ViewPortOutline.Bottom)
            {
                Vector2 arrowDir = opponent.Position2D - player.Position2D;
                arrowDir.Normalize();

                opponentArrow.Visible       = true;
                opponentArrow.Position2D    = arrowDir * 200 + player.Position2D;
                opponentArrow.RotationAngle = RotationHelper.AngleFromDirection(arrowDir);
                GM.textM.Draw(FontBank.arcadePixel,
                              Convert.ToString((int)(Vector2.Distance(opponent.Position2D, player.Position2D))) + "m",
                              (PointHelper.Vector2FromPoint(GM.screenSize.Center) + arrowDir * 200).X - 50,
                              (PointHelper.Vector2FromPoint(GM.screenSize.Center) + arrowDir * 200).Y - 50);
            }
            else
            {
                opponentArrow.Visible = false;
            }

            if (GM.inputM.KeyPressed(Keys.Escape))
            {
                BackToTitle("Press 1 to start.");
            }

            //Boarding
            if (boardingInProgress)
            {
                if (GM.eventM.Elapsed(tiOneSecond))
                {
                    OneSecond();
                }
                crewDisplayPlayer.Visible     = true;
                crewDisplayBackground.Visible = true;
                GM.textM.Draw(FontBank.arcadePixel, "Boarding", GM.screenSize.Center.X, GM.screenSize.Center.Y - 200);
                crewDisplayPlayer.SX = ((float)player.CrewNum / (player.CrewNum + opponent.CrewNum)) * 100f;
            }
            else
            {
                crewDisplayPlayer.Visible     = false;
                crewDisplayBackground.Visible = false;
            }
        }
Beispiel #5
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 #6
0
        /// <summary>
        /// Code to run each tick
        /// </summary>
        private void Tick()
        {
            //Run code in this function every second
            if (GM.eventM.Elapsed(tiOneSecond))
            {
                OneSecond();
            }

            //Kill if no crew
            if (crewNum <= 0)
            {
                Kill();
            }

            //Keep rotation angle between -180 and 180 degrees
            if (RotationAngle < -180)
            {
                RotationAngle += 360;
            }
            else if (RotationAngle > 180)
            {
                RotationAngle -= 360;
            }

            //Stop reload timers once reload is complete or if repairing
            if (GM.eventM.Elapsed(tiReloadRight) || IsRepairing)
            {
                tiReloadRight.Paused = true;
                if (!IsRepairing)
                {
                    rightLoaded = true;
                }
            }
            if (GM.eventM.Elapsed(tiReloadLeft) || IsRepairing)
            {
                tiReloadLeft.Paused = true;
                if (!IsRepairing)
                {
                    leftLoaded = true;
                }
            }

            //Checking for collisions
            if (hasCollided)
            {
                hasCollided = false;
                Ship otherShip;
                if (isPlayer)
                {
                    otherShip = GameSetup.Opponent;
                }
                else
                {
                    otherShip = GameSetup.Player;
                }
                Vector2 velVector = Position2D - otherShip.Position2D;
                velVector.Normalize();
                //Multiply based on angle to velVector (reduce if sideways)
                float angleDifference = Math.Abs(RotationHelper.AngleFromDirection(velVector) - RotationAngle + 90);
                velVector /= angleDifference;

                Velocity2D += velVector * 30 * (Velocity2D - otherShip.Velocity2D);
            }
        }