Beispiel #1
0
        private void Move()
        {
            //Trailing smoke particles
            if (tiLifetimeCounter.ElapsedSoFar > 0.5 - GM.r.FloatBetween(0.1f, 0.3f))
            {
                Vector2 offset = new Vector2(20 * RotationHelper.MyDirection(this, 180).X, 20 * RotationHelper.MyDirection(this, 180).Y);
                new SmokeParticle(Position2D + offset, Vector3.Zero, Vector2.Zero, 0.2f);
                GM.eventM.AddTimer(tiSmokeCounter = new Event(0.5f, "Smoke Counter"));
            }

            if (target.Dead)
            {
                RotationHelper.VelocityInCurrentDirection(this, speed, 0);
            }
            else
            {
                //turnDir = -1, anticlockwise; 0, none; 1, clockwise
                int turnDir = (int)RotationHelper.AngularDirectionTo(this, target.Position, 0, false);

                //Direction to add velocity to, additional angle is 90 * turnDir so -90 for anticlockwise, 90 for clockwise, straight ahead for none
                Vector3 velDir = RotationHelper.MyDirection(this, 90 * turnDir);

                Velocity  = RotationHelper.MyDirection(this, 0) * speed;
                Velocity += velDir * (turnAmount / 5);
                RotationHelper.FaceVelocity(this, DirectionAccuracy.free, false, 0);
            }
        }
Beispiel #2
0
        private void Move()
        {
            //Do this for first 0.5 seconds of life
            if (tiBirth.ElapsedSoFar < 0.5)
            {
                RotationHelper.VelocityInThisDirection(this, direction, 500);
            }
            //Then do this
            else
            {
                RotationVelocity = 45f;
            }

            //For shooting
            //Every 5 seconds
            if (tiBirth.ElapsedSoFar > 2.5)
            {
                if (GM.eventM.Elapsed(tiShootCooldown))
                {
                    Vector3 front3d  = Position + RotationHelper.MyDirection(this, 0);
                    Vector3 bottom3d = Position + RotationHelper.MyDirection(this, 180);
                    Vector2 front    = new Vector2(front3d.X, front3d.Y);
                    Vector2 bottom   = new Vector2(bottom3d.X, bottom3d.Y);


                    new Missile(Position2D, front, this, GameSetup.PlayerChar, 500, 500, 20, 20);
                    new Missile(Position2D, bottom, this, GameSetup.PlayerChar, 500, 500, 20, 20);
                    new Bullet(this, bottom, 1500f, 2);
                }
            }

            //Every 10 seconds
            if (tiBirth.ElapsedSoFar >= 10)
            {
                GM.eventM.AddEventRaiseOnce(tiBirth = new Event(10f, "Birth timer"));

                direction = Vector3.Zero;

                if (Position.X <= GM.screenSize.Center.X)
                {
                    direction.X += 1;
                }
                else
                {
                    direction.X -= 1;
                }
                if (Position.Y <= GM.screenSize.Center.Y)
                {
                    direction.Y += 1;
                }
                else
                {
                    direction.Y -= 1;
                }
                direction.Normalize();
            }
        }
Beispiel #3
0
        private void FireMissile(Sprite lockedSprite)
        {
            Sprite target = lockedSprite;

            Vector2 dir = new Vector2(RotationHelper.MyDirection(this, 0).X, RotationHelper.MyDirection(this, 0).Y);

            new Missile(Position2D + (24 * dir), dir, this, target, 750, 500, 20, 50);

            if (tiAltFireCooldown == null)
            {
                GM.eventM.AddTimer(tiAltFireCooldown = new Event(1, "Alternate Fire Cooldown"));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Constructor for bullet class
        /// </summary>
        /// <param name="player">The object that fired the bullet</param>
        /// <param name="fireAngle">2D vector to travel towards</param>
        /// <param name="bulletSpeed">Speed of bullet</param>
        /// <param name="bulletDamage">Damage on hit</param>
        public Bullet(Sprite player, Vector2 fireAngle, float bulletSpeed, int bulletDamage)
        {
            damage = bulletDamage;

            this.player = player;
            GM.engineM.AddSprite(this);
            Frame.Define(Tex.SingleWhitePixel);
            SX = 4;
            SY = 24;

            //Sound effects
            GM.audioM.PlayEffect("shoot");

            //get player attributes
            Wash = player.Wash;

            //set postion of bullet and give velocity
            X = player.Centre.X;
            Y = player.Centre.Y;

            //Set rotation at player
            Position2D = RotationHelper.RotateAround(player.Centre2D, player.Centre2D, 0);

            //Create direction vector and normalise
            Vector2 direction = fireAngle - Position2D;

            direction = Vector2.Normalize(direction);

            //Face direction vector
            RotationHelper.FaceDirection(this, direction, DirectionAccuracy.free, 0);
            RotationHelper.VelocityInCurrentDirection(this, bulletSpeed, 0);
            Position += RotationHelper.MyDirection(this, 0) * 32;

            //collision setup
            CollisionActive   = true;
            CollisionPrimary  = true;
            PrologueCallBack += Hit;
            EpilogueCallBack += AfterHit;
            Moving            = true;

            //kill after 5 seconds
            TimerInitialise();
            Timer.KillAfter(5f);
        }
Beispiel #5
0
        private void Move()
        {
            //For gunSprite
            Vector2 playerPos = GameSetup.PlayerChar.Position2D;
            Vector2 direction = playerPos - Position2D;

            direction = Vector2.Normalize(direction);
            RotationHelper.FaceDirection(gunSprite, direction, DirectionAccuracy.free, 0);
            gunSprite.Position2D = Position2D + (direction * 15);
            Vector2 currentPosition = Position2D;

            //For movement:
            float distanceFromPlayer = Vector2.Distance(Position2D, playerPos);

            if (distanceFromPlayer > 200)
            {
                //Move towards player
                RotationHelper.FacePosition(this, GameSetup.PlayerChar.Position, DirectionAccuracy.free, 0, false);
                RotationHelper.VelocityInCurrentDirection(this, 500, 0);
            }
            if (distanceFromPlayer < 400)
            {
                //Switch strafe direction after 2 seconds
                int dirMultiplier = 1;
                if (tiSwitchDirection.ElapsedSoFar > 2)
                {
                    dirMultiplier = -1;
                }
                RotationHelper.VelocityInThisDirection(this, RotationHelper.MyDirection(this, dirMultiplier * 60), 250);

                //For firing
                if (GM.eventM.Elapsed(tiShootCooldown))
                {
                    //create bullet and pass reference to player and angle
                    new Bullet(this, playerPos, 1000f, 10);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// act on key sets to move player and shoot
        /// </summary>
        private void Move()
        {
            //For gunSprite
            Vector2 aimPos    = GM.inputM.MouseLocation;
            Vector2 direction = aimPos - Position2D;

            direction = Vector2.Normalize(direction);
            RotationHelper.FaceDirection(gunSprite, direction, DirectionAccuracy.free, 0);
            gunSprite.Position2D = Position2D + (direction * 15);
            Vector2 currentPosition = Position2D;

            //For console
            if (GM.inputM.KeyPressed(Keys.C))
            {
                debugMode = true;
            }
            if (debugMode == true)
            {
                GM.textM.Draw(FontBank.arcadePixel, "Debug", GM.screenSize.Left + 175, GM.screenSize.Top + 40, TextAtt.TopLeft);

                if (GM.inputM.KeyPressed(Keys.F5))
                {
                    LaserEnemy laserEnemy = new LaserEnemy(GM.inputM.MouseLocation, false);
                }
                if (GM.inputM.KeyPressed(Keys.F12))
                {
                    GameSetup.EnemySpawnSystem.Kill();
                }
            }

            //For dodging
            Vector3 d = new Vector3(0, 0, 0);

            if (tiBoostDelay == null || tiBoostDelay.ElapsedSoFar > 0.25f)
            {
                if (GM.inputM.KeyDown(MoveLeft))
                {
                    d += Vector3.Left;
                }
                if (GM.inputM.KeyDown(MoveRight))
                {
                    d += Vector3.Right;
                }
                if (GM.inputM.KeyDown(Forward))
                {
                    d += Vector3.Down;
                }
                if (GM.inputM.KeyDown(Backward))
                {
                    d += Vector3.Up;
                }
                if (d == new Vector3(0, 0, 0))
                {
                    RotationHelper.FaceDirection(this, Vector3.Down, DirectionAccuracy.free, 0);
                }
                else
                {
                    RotationHelper.FaceDirection(this, d, DirectionAccuracy.free, 0);
                    RotationHelper.VelocityInCurrentDirection(this, 500, 0);
                }
            }

            //For directionSprite
            Vector3 dNorm = d;

            dNorm.Normalize();
            RotationHelper.FaceDirection(directionSprite, dNorm, DirectionAccuracy.free, 0);
            directionSprite.Position = Position + (dNorm * 20);

            //For firing
            if ((GM.inputM.KeyDown(Fire) || GM.inputM.MouseLeftButtonHeld()) && GM.eventM.Elapsed(tiFireCooldown))
            {
                //create bullet and pass reference to player and angle
                new Bullet(this, aimPos, 1500f, 10);
            }

            if (GM.inputM.KeyDown(SpecialFire) && (tiSpecialFireCooldown == null || GM.eventM.Elapsed(tiSpecialFireCooldown)))
            {
                for (int i = 0; i < 360; i += 5)
                {
                    Vector3 v3ShootAngle = RotationHelper.MyDirection(this, i);
                    Vector2 v2ShootAngle = new Vector2(v3ShootAngle.X, v3ShootAngle.Y);

                    RotationHelper.Direction2DFromAngle(i, 0);

                    //create bullet and pass reference to player and angle
                    new Bullet(this, Position2D + v2ShootAngle, 750, 50);
                }

                for (int i = 0; i < 360; i += 10)
                {
                    Vector3 v3ShootAngle = RotationHelper.MyDirection(this, i);
                    Vector2 v2ShootAngle = new Vector2(v3ShootAngle.X, v3ShootAngle.Y);

                    RotationHelper.Direction2DFromAngle(i, 0);

                    //create bullet and pass reference to player and angle
                    new Bullet(this, Position2D + v2ShootAngle, 500, 50);
                }

                if (tiSpecialFireCooldown == null)
                {
                    GM.eventM.AddTimer(tiSpecialFireCooldown = new Event(10f, "Special Fire Cooldown"));
                }
            }

            //For boosting
            if (GM.inputM.KeyPressed(Boost) && (tiBoostDelay == null || GM.eventM.Elapsed(tiBoostDelay)) && d != Vector3.Zero)
            {
                if (tiBoostDelay == null)
                {
                    GM.eventM.AddTimer(tiBoostDelay = new Event(0.5f, "dodge delay"));
                }

                //Raycasting to check for collisions and offset to avoid collision
                //Position += d * 100;
                //Ray findHits = new Ray(Position, d);

                Friction     = 0f;
                Velocity    += dNorm * 800;
                invulnerable = true;
                Wash         = Color.LightGreen;
            }

            //Resetting dodge delay for displaying
            if (tiBoostDelay != null && tiBoostDelay.ElapsedSoFar > 0.25f)
            {
                Friction     = 10f;
                invulnerable = false;
                Wash         = Color.LimeGreen;
            }

            //Locking sequence
            if (GM.inputM.MouseRightButtonPressed())
            {
                lockSprite.Visible = true;

                attack = null;
                float bestDistance = int.MaxValue;

                foreach (Sprite s in GM.engineM.SpriteList)
                {
                    if (s is Enemy)
                    {
                        if (attack == null || Vector2.DistanceSquared(aimPos, s.Centre2D) < bestDistance)
                        {
                            attack       = s;
                            bestDistance = Vector2.DistanceSquared(aimPos, s.Centre2D);
                        }
                    }
                }
                if (attack != null)
                {
                    lockSprite.Position2D = attack.Position2D;
                }
            }

            if (GM.inputM.MouseRightButtonHeld() && GM.eventM.Elapsed(tiLockingDelay) && attack != null)
            {
                GM.eventM.AddEventRaiseOnce(beepCountDown = new Event(0.25f, "Beep Countdown"));
                float graphicsLockAmount = lockAmount / 4;
                Color color = new Color();
                if (lockAmount < 1)
                {
                    lockAmount += tiLockingDelay.Interval * 4;
                    lockSprite.RotationAngle = 360 * graphicsLockAmount;
                    color.R = (byte)(250 * lockAmount);
                    color.B = (byte)(255 - color.R);
                }
                else
                {
                    lockSprite.RotationAngle = 0;
                    color.R = (byte)(255);
                    color.B = (byte)(0);
                }
                if (GM.eventM.Elapsed(beepCountDown))
                {
                    //Beep sound effect
                }

                lockSprite.Position2D = attack.Position2D;
                lockSprite.ScaleBoth  = 1.5f + (1 - lockAmount);
                lockSprite.Wash       = color;
            }

            if (GM.inputM.MouseRightButtonReleased())
            {
                if (lockAmount >= 1 && (tiAltFireCooldown == null || GM.eventM.Elapsed(tiAltFireCooldown)))
                {
                    FireMissile(attack);
                }
                lockSprite.Visible = false;
                lockAmount         = 0;
            }
        }
Beispiel #7
0
        private void Move()
        {
            //Do this for first 0.5 seconds of life
            if (tiBirth.ElapsedSoFar < 0.5)
            {
                RotationHelper.FaceDirection(this, direction, DirectionAccuracy.free, 10);
                RotationHelper.VelocityInCurrentDirection(this, 500, 0);
            }
            //Then do this
            else
            {
                if (tiBirth.ElapsedSoFar < 10)
                {
                    if (fourLasers)
                    {
                        RotationVelocity = 22.5f;
                    }
                    else
                    {
                        RotationVelocity = 45f;
                    }
                }
            }

            //For shooting
            //Every 5 seconds
            if (tiBirth.ElapsedSoFar > 5)
            {
                //1 laser
                laserTop.Position2D    = Position2D;
                laserTop.RotationAngle = RotationAngle;
                laserTop.Visible       = true;

                //4 lasers
                if (fourLasers)
                {
                    laserLeft.Position2D    = Position2D;
                    laserLeft.RotationAngle = RotationAngle + 90;
                    laserLeft.Visible       = true;
                }
            }

            //Every 5+1 seconds
            if (tiBirth.ElapsedSoFar > 6)
            {
                //1 laser
                laserTop.Wash = Color.Red;
                laserTop.SX   = 0.2f;

                //Checking for collisions
                Ray rayTop    = new Ray(Position, RotationHelper.MyDirection(this, 0));
                Ray rayBottom = new Ray(Position, RotationHelper.MyDirection(this, 180));

                BoundingSphere playerSphere = new BoundingSphere(GameSetup.PlayerChar.Position, (GameSetup.PlayerChar.Right - GameSetup.PlayerChar.Left));

                if ((rayTop.Intersects(playerSphere) != null || rayBottom.Intersects(playerSphere) != null) && GM.eventM.Elapsed(tiDamageCooldown))
                {
                    GameSetup.PlayerChar.Health -= 2;
                    if (GameSetup.PlayerChar.Health <= 0)
                    {
                        GameSetup.PlayerChar.Kill();
                    }
                }
                //4 lasers
                if (fourLasers)
                {
                    laserLeft.Wash = Color.Red;
                    laserLeft.SX   = 0.2f;

                    Ray rayLeft  = new Ray(Position, RotationHelper.MyDirection(this, 90));
                    Ray rayRight = new Ray(Position, RotationHelper.MyDirection(this, 270));

                    if ((rayLeft.Intersects(playerSphere) != null || rayRight.Intersects(playerSphere) != null) && GM.eventM.Elapsed(tiDamageCooldown))
                    {
                        GameSetup.PlayerChar.Health -= 2;
                        if (GameSetup.PlayerChar.Health <= 0)
                        {
                            GameSetup.PlayerChar.Kill();
                        }
                    }
                }
            }

            //Every 10 seconds
            if (tiBirth.ElapsedSoFar >= 10)
            {
                GM.eventM.AddEventRaiseOnce(tiBirth = new Event(10f, "Birth timer"));

                direction = Vector3.Zero;

                if (Position.X <= GM.screenSize.Center.X)
                {
                    direction.X += 1;
                }
                else
                {
                    direction.X -= 1;
                }
                if (Position.Y <= GM.screenSize.Center.Y)
                {
                    direction.Y += 1;
                }
                else
                {
                    direction.Y -= 1;
                }
                direction.Normalize();

                //1 laser
                laserTop.Wash    = Color.OrangeRed;
                laserTop.Visible = false;
                laserTop.SX      = 0.1f;

                //4 lasers
                if (fourLasers)
                {
                    laserLeft.Wash    = Color.OrangeRed;
                    laserLeft.Visible = false;
                    laserLeft.SX      = 0.1f;
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Constructor for CannonBall class
        /// </summary>
        /// <param name="owner">The ship that fired the CannonBall</param>
        /// <param name="fireFrom">2D position to fire from</param>
        /// <param name="fireDir">2D position to fire towards</param>
        /// <param name="type">Type of shot to use - 0 ball shot, 1 bar shot, 2 carcass shot, 3 grape shot, 4 grapple shot</param>
        public CannonBall(Sprite owner, Vector3 fireFrom, Vector3 fireDir, int type)
        {
            //Init values
            Position   = fireFrom;
            shotType   = type;
            this.owner = owner;
            GM.engineM.AddSprite(this);
            Friction = 0.25f;

            switch (type)
            {
            case 0:
                Frame.Define(GM.txSprite, new Rectangle(111, 160, 5, 5));
                break;

            case 1:
                Frame.Define(GM.txSprite, new Rectangle(121, 161, 7, 3));
                ScaleBoth = 1.25f;
                break;

            case 2:
                Frame.Define(GM.txSprite, new Rectangle(133, 160, 5, 7));
                break;

            case 3:
                Frame.Define(GM.txSprite, new Rectangle(143, 159, 2, 2));
                ScaleBoth = 3;
                break;

            case 4:
                Frame.Define(GM.txSprite, new Rectangle(133, 170, 5, 5));
                ScaleBoth = 1.5f;
                break;

            default:
                Frame.Define(Tex.Circle4by4);
                Wash = Color.DarkGray;
                break;
            }

            RotationHelper.FaceDirection(this, fireDir, DirectionAccuracy.free, 0);
            Position += RotationHelper.MyDirection(this, 0) * 50;

            //Collision setup
            CollisionActive   = true;
            CollisionPrimary  = true;
            PrologueCallBack += Hit;
            EpilogueCallBack += AfterHit;
            Moving            = true;

            //kill after a random time and delay firing
            TimerInitialise();
            fireDelay = GM.r.FloatBetween(0, 0.5f);
            if (type != 3 && type != 4)
            {
                Timer.ShowAfterKillAfter(fireDelay, GM.r.FloatBetween(0.5f, 0.7f));
            }
            else
            {
                Timer.ShowAfterKillAfter(fireDelay, GM.r.FloatBetween(0.2f, 0.4f));
            }

            velApplied      = false;
            UpdateCallBack += Tick;

            splash           = true;
            FuneralCallBack += Death;
        }
Beispiel #9
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 #10
0
        private void Move()
        {
            //Do this for first 0.5 seconds of life
            if (tiBirth.ElapsedSoFar < 0.5)
            {
                RotationHelper.VelocityInThisDirection(this, direction, 500);
            }
            //Then do this
            else
            {
                if (fourBeams)
                {
                    RotationVelocity = 22.5f;
                }
                else
                {
                    RotationVelocity = 45f;
                }
            }

            //For shooting
            //Every 5 seconds
            if (tiBirth.ElapsedSoFar > 2.5)
            {
                if (GM.eventM.Elapsed(tiShootCooldown))
                {
                    //1 laser
                    Vector3 front3d  = Position + RotationHelper.MyDirection(this, 0);
                    Vector3 bottom3d = Position + RotationHelper.MyDirection(this, 180);
                    Vector2 front    = new Vector2(front3d.X, front3d.Y);
                    Vector2 bottom   = new Vector2(bottom3d.X, bottom3d.Y);


                    new Bullet(this, front, 1500f, 2);
                    new Bullet(this, bottom, 1500f, 2);
                    //4 lasers
                    if (fourBeams)
                    {
                        Vector3 left3d  = Position + RotationHelper.MyDirection(this, 90);
                        Vector3 right3d = Position + RotationHelper.MyDirection(this, 270);
                        Vector2 left    = new Vector2(left3d.X, left3d.Y);
                        Vector2 right   = new Vector2(right3d.X, right3d.Y);

                        new Bullet(this, left, 1000f, 2);
                        new Bullet(this, right, 1000f, 2);
                    }
                }
            }

            //Every 10 seconds
            if (tiBirth.ElapsedSoFar >= 10)
            {
                GM.eventM.AddEventRaiseOnce(tiBirth = new Event(10f, "Birth timer"));

                direction = Vector3.Zero;

                if (Position.X <= GM.screenSize.Center.X)
                {
                    direction.X += 1;
                }
                else
                {
                    direction.X -= 1;
                }
                if (Position.Y <= GM.screenSize.Center.Y)
                {
                    direction.Y += 1;
                }
                else
                {
                    direction.Y -= 1;
                }
                direction.Normalize();
            }
        }
Beispiel #11
0
        /// <summary>
        /// Accelerates the ship towards point and keeps the ship from sliding sideways
        /// </summary>
        /// <param name="point">Point to move towards</param>
        internal void MoveToPoint(Point point)
        {
            Vector2 movePos = PointHelper.Vector2FromPoint(point);

            //Stop moving once close enough to movePos, or when boarding is in progress
            if ((Vector2.DistanceSquared(Position2D, movePos) + 5000 > Height * Height) && !isBoarded && !isBoarding)
            {
                if (isPlayer)
                {
                    moveLocSprite.Visible = true;
                }
                moveLocSprite.Position2D = movePos;

                //DEBUG
                //if (!isPlayer)
                //{
                //    moveLocSprite.Visible = true;
                //    moveLocSprite.Wash = Color.Red;
                //}


                if (sailAmount == 0)
                {
                    if (smoothRotationVelocity > 0)
                    {
                        smoothRotationVelocity -= 0.1f;
                        RotationVelocity        = smoothRotationVelocity;
                    }
                    if (smoothRotationVelocity < 0)
                    {
                        smoothRotationVelocity += 0.1f;
                        RotationVelocity        = smoothRotationVelocity;
                    }
                }
                else
                {
                    //Calculations for turning
                    int dirMul = (int)RotationHelper.AngularDirectionTo(this, new Vector3(movePos, 0), 0, false);
                    smoothRotationVelocity += 0.05f * dirMul;
                    if ((dirMul > 0 && smoothRotationVelocity > 5 * dirMul) || (dirMul < 0 && smoothRotationVelocity < 5 * dirMul))
                    {
                        smoothRotationVelocity = 5 * dirMul;
                    }
                    RotationVelocity = smoothRotationVelocity;

                    Vector3 currentVel = Velocity;
                    currentVel.Normalize();
                    currentVel = Position + currentVel;
                    float velOffsetAngle = RotationHelper.AngularDirectionTo(this, currentVel, 0, false);

                    //Calculations for wind speed multiplier
                    float velFromWindAngle = (RotationAngle - GameSetup.WeatherController.WindDir) % 360;
                    if (velFromWindAngle < 0) //Absolute value
                    {
                        velFromWindAngle = -velFromWindAngle;
                    }
                    if (velFromWindAngle > 180) //Keep between 0 and 180
                    {
                        velFromWindAngle = 360 - velFromWindAngle;
                    }//Create multiplier that's <1
                    velFromWindAngle = (1 / (velFromWindAngle + 100) * 50);

                    //Keep from sliding to the side
                    if (velOffsetAngle > 0)
                    {
                        Velocity += RotationHelper.MyDirection(this, -90) * 0.5f;
                    }
                    else
                    {
                        Velocity += RotationHelper.MyDirection(this, 90) * 0.5f;
                    }

                    //Add velocity
                    if (sailAmount == 1)
                    {
                        Velocity += RotationHelper.MyDirection(this, 0) * 0.1f * velFromWindAngle * sailDamageSpeedMul;
                    }
                    if (sailAmount == 2)
                    {
                        Velocity += RotationHelper.MyDirection(this, 0) * 0.2f * velFromWindAngle * sailDamageSpeedMul;//Sort this out so it doesnt divide by 0
                    }
                }
            }
            else if (isBoarding || isBoarded)
            {
                Ship target = GameSetup.Opponent;
                if (!isPlayer)
                {
                    target = GameSetup.Player;
                }

                float angleBetween = RotationAngle - target.RotationAngle;
                bool  opposite     = true;
                if (angleBetween > -90 && angleBetween < 90)
                {
                    opposite = false;
                }

                //Angle ships parallel to eachother.
                if (opposite &&
                    Vector2.DistanceSquared(hitBoxHullFront.Position2D, target.hitBoxHullBack.Position2D)
                    > Vector2.DistanceSquared(hitBoxHullBack.Position2D, target.hitBoxHullFront.Position2D))
                {
                    RotationVelocity = 2;
                }
                else if (!opposite &&
                         Vector2.DistanceSquared(hitBoxHullFront.Position2D, target.hitBoxHullFront.Position2D)
                         > Vector2.DistanceSquared(hitBoxHullBack.Position2D, target.hitBoxHullBack.Position2D))
                {
                    RotationVelocity = 2;
                }
                else
                {
                    RotationVelocity = -2;
                }

                //Move ships towards eachother
                if (Vector2.DistanceSquared(this.Position2D, target.Position2D) > 10000)
                {
                    Vector2 velDir = Vector2.Normalize(Position2D - target.Position2D);
                    Velocity2D -= 0.01f * velDir;
                }
                else
                {
                    GameSetup.BoardingInProgress = true;
                    Velocity2D = Vector2.Zero;
                }

                //DEBUG
                GM.textM.Draw(FontBank.arcadePixel, Convert.ToString(opposite), 200, 200);
            }
            else
            {
                if (!isPlayer)
                {
                    moveTargetReached = true;
                }
                else
                {
                    GameSetup.Player.MovePath.Dequeue();
                    GameSetup.Player.ArrowQueue.Dequeue();
                }
                moveLocSprite.Visible = false;
                RotationVelocity      = 0;
            }
        }
Beispiel #12
0
        /// <summary>
        /// Fire cannons
        /// </summary>
        /// <param name="right">If true fire from right side else left side</param><param name="type">Type of shot to use - 0 ball shot, 1 bar shot, 2 grape shot, 3 carcass shot, 4 grapple shot</param>
        internal void Fire(bool right, int type)
        {
            right = !right;
            bool hasAmmo = true;

            if ((right && rightLoaded) || (!right && leftLoaded) && !IsRepairing)
            {
                if (type == 0 && roundShotNum > 0)
                {
                    roundShotNum--;
                }
                else if (type == 1 && barShotNum > 0)
                {
                    barShotNum--;
                }
                else if (type == 2 && grapeShotNum > 0)
                {
                    grapeShotNum--;
                }
                else if (type == 3 && carcassShotNum > 0)
                {
                    carcassShotNum--;
                }
                else if (type == 4 && grappleShotNum > 0)
                {
                    grappleShotNum--;
                }
                else
                {
                    hasAmmo = false;
                }
            }
            else
            {
                hasAmmo = false;
            }
            if (hasAmmo)
            {
                Vector3 fireDir;
                Vector3 deckDir = Vector3.Zero;
                int     rightMul;

                if (right)
                {
                    rightMul = 1;
                }
                else
                {
                    rightMul = -1;
                }

                fireDir = RotationHelper.MyDirection(this, 90 * rightMul);
                deckDir = RotationHelper.MyDirection(this, 0);

                int multiply = 2;
                if (type == 3)
                {
                    multiply = 4;
                }
                if (type == 4)
                {
                    multiply = 1;
                }
                for (int i = 0; i < crewNum * 0.1f; i++)
                {
                    for (int i2 = 0; i2 < multiply; i2++)
                    {
                        new CannonBall(this, Position + (deckDir * i * 10) - (deckDir * 48), fireDir, type);
                    }
                }

                if (right == true)
                {
                    tiReloadRight.Paused = false;
                    rightLoaded          = false;
                }
                else
                {
                    tiReloadLeft.Paused = false;
                    leftLoaded          = false;
                }
            }
        }