Example #1
0
        public override void Update(GameTime gameTime)
        {
            if (m_screen.IsActive)
            {
                m_killTime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            //if ((float)gameTime.TotalGameTime.TotalSeconds > m_killTime)
            if (m_killTime < 0.0f)
            {
                bDead = true;
                // Cue c = Game1.Audio.PlaySound("sfx_cannonball_hit_water");
                Cue c = Game1.Audio.GetCue("sfx_cannonball_hit_water");

                AudioListener al = new AudioListener();
                al.Position = new Vector3(m_screen.Player.Position, 0);
                al.Up       = Vector3.Backward;
                al.Forward  = Vector3.Up;

                AudioEmitter ae = new AudioEmitter();
                ae.Position = new Vector3(Position, 0);
                ae.Up       = Vector3.Backward;
                ae.Forward  = Vector3.Up;

                c.Apply3D(al, ae);
                Game1.Audio.PlayCue(c);
                c.SetVariable("Distance", (m_screen.Player.Position - Position).Length());

                Watersplash w = new Watersplash(Game);
                w.Initialize(10, Position, true);

                //Game1.Audio.SetParameter("sfx_cannonball_hit_water", "Distance", (m_screen.Player.Position - Position).Length());
            }



            m_obb.Orientation = Rotation;
            m_obb.Center      = Position;
            m_obb.CalculateAxis();

            for (Actor a = Actors.First.Value; a != null; a = a.NextActor)
            {
                if (a is PDVehicle)
                {
                    if (a != Owner)
                    {
                        if ((a as PDVehicle).Obb.TestOBBOBB(Obb))
                        {
                            SpriteEffect e = new EffectCannonFire(Game);
                            e.Initialize(10, Position, true);

                            bDead = true;

                            // Cue c = Game1.Audio.PlaySound("sfx_cannonball_hit");
                            Cue           c  = Game1.Audio.GetCue("sfx_cannonball_hit");
                            AudioListener al = new AudioListener();
                            al.Position = new Vector3(m_screen.Player.Position, 0);
                            al.Up       = Vector3.Backward;
                            al.Forward  = Vector3.Up;

                            AudioEmitter ae = new AudioEmitter();
                            ae.Position = new Vector3(Position, 0);
                            ae.Up       = Vector3.Backward;
                            ae.Forward  = Vector3.Up;

                            c.Apply3D(al, ae);
                            Game1.Audio.PlayCue(c);
                            c.SetVariable("Distance", (m_screen.Player.Position - Position).Length());
                            // Game1.Audio.SetParameter("sfx_cannonball_hit", "Distance", (m_screen.Player.Position - Position).Length());

                            // Damage target
                            (a as PDVehicle).Damage(Damage);
                        }
                    }
                }
            }

            base.Update(gameTime);
        }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            // Set the correct animation based on Velocity/Throttle & Rotation

            // Lean percentage that increases when you hold down turning and normalizes when you don't
            // The Lean percentage is adjusted by velocity/throttle so that you can't lean hard with low velocity

            if (m_health <= 0)
            {
                bDead = true;
                // Cue c = Game1.Audio.PlaySound("sfx_ship_sink");
                Cue           c  = Game1.Audio.GetCue("sfx_ship_sink");
                AudioListener al = new AudioListener();
                al.Position = new Vector3(m_screen.Player.Position, 0);
                al.Up       = Vector3.Backward;
                al.Forward  = Vector3.Up;

                AudioEmitter ae = new AudioEmitter();
                ae.Position = new Vector3(Position, 0);
                ae.Up       = Vector3.Backward;
                ae.Forward  = Vector3.Up;

                c.Apply3D(al, ae);
                Game1.Audio.PlayCue(c);


                c.SetVariable("Distance", (Screen.Player.Position - Position).Length());

                Wreckage w = new Wreckage(Game);
                w.Initialize(m_gold, Silk, Spices, Leather, Rum, Iron, Coal, Rope, Tools);
                w.Position = Position;

                for (int i = 0; i < 10; i++)
                {
                    EffectCannonFire a = new EffectCannonFire(Game);
                    a.Initialize(10, Position + new Vector2(Game1.Rand.Next(-40, 40), Game1.Rand.Next(-40, 40)), true);
                }

                for (int i = 0; i < 10; i++)
                {
                    Watersplash a = new Watersplash(Game);
                    a.Initialize(10, Position + new Vector2(Game1.Rand.Next(-40, 40), Game1.Rand.Next(-40, 40)), true);
                }

                int n = Game1.Rand.Next(0, GameplayScreen.m_waypoints.Length);

                int type = Game1.Rand.Next(0, 4);

                PDVehicle v = null;

                switch (type)
                {
                case 0:
                    v = new PDVBritish(Game, m_screen);
                    v.Initialize();
                    v.SetDefaultGraphics(ref GameplayScreen.m_tShipBritish);
                    break;

                case 1:
                    v = new PDVChinese(Game, m_screen);
                    v.Initialize();
                    v.SetDefaultGraphics(ref GameplayScreen.m_tShipChinese);
                    break;

                case 2:
                    v = new PDVPersian(Game, m_screen);
                    v.Initialize();
                    v.SetDefaultGraphics(ref GameplayScreen.m_tShipPersian);
                    break;

                case 3:
                    v = new PDVSpanish(Game, m_screen);
                    v.Initialize();
                    v.SetDefaultGraphics(ref GameplayScreen.m_tShipSpanish);
                    break;
                }

                v.Position         = GameplayScreen.m_waypoints[n];
                v.ThrottleMax      = 40;
                v.ThrottleDecrease = 100;
                v.bTurnInPlace     = true;


                return;
            }



            for (int i = 0; i < Screen.m_islands.Count; i++)
            {
                if (Screen.m_islands[i].Hitbox != null)
                {
                    for (int j = 0; j < Screen.m_islands[i].Hitbox.Length; j++)
                    {
                        if (Screen.m_islands[i].Hitbox[j].TestOBBOBB(Obb))
                        {
                            // Cue c = Game1.Audio.PlaySound("sfx_ship_collide");
                            Cue           c  = Game1.Audio.GetCue("sfx_ship_collide");
                            AudioListener al = new AudioListener();
                            al.Position = new Vector3(m_screen.Player.Position, 0);
                            al.Up       = Vector3.Backward;
                            al.Forward  = Vector3.Up;

                            AudioEmitter ae = new AudioEmitter();
                            ae.Position = new Vector3(Position, 0);
                            ae.Up       = Vector3.Backward;
                            ae.Forward  = Vector3.Up;

                            c.Apply3D(al, ae);
                            Game1.Audio.PlayCue(c);


                            c.SetVariable("Distance", (Screen.Player.Position - Position).Length());


                            Vector2 v = Obb.Center - Screen.m_islands[i].Hitbox[j].Center;
                            v.Normalize();

                            Heading  = v;
                            Rotation = (float)Math.Atan2(Heading.Y, Heading.X);
                            Throttle = 100;
                            break;
                        }
                    }
                }
            }



            // Throttle -= ThrottleDecrease * (float)gameTime.ElapsedGameTime.TotalSeconds * 0.25f;

            float velMod = 0.0f;

            if (Throttle > 0.001f)
            {
                velMod = Throttle / ThrottleMax;
            }

            m_leanValue = MathHelper.Clamp(m_leanValue * velMod, -1.0f, 1.0f);

            int index = (int)Math.Round(m_leanValue * 4.0f) + 4;

            if (m_gfx != null)
            {
                if ((m_gfx as Animation).ActiveAnimationSet.Name != m_animTable[index])
                {
                    int currentFrame = (m_gfx as Animation).ActiveAnimationSet.nActiveFrame;
                    (m_gfx as Animation).SetActiveSet(m_animTable[index], currentFrame);
                }
            }


            if (m_bFiring)
            {
                if (m_nextShot < gameTime.TotalGameTime.TotalSeconds)
                {
                    Fire(gameTime);
                    m_nextShot += m_tTimeBetweenShots;

                    if (m_cannonsReady <= 0)
                    {
                        m_bFiring = false;
                    }
                }
            }
            else
            {
                Reload(gameTime);
            }



            m_obb.Orientation = Rotation;
            m_obb.Center      = Position;
            m_obb.CalculateAxis();

            m_shadow.Position = Position;
            m_shadow.Rotation = Rotation;

            m_hpBar.Position = Position;
            m_hpBar.Update(gameTime);
            m_hpBar.Scale = new Vector2(m_health / m_maxHealth, 1);

            m_hpBarBG.Position = Position;

            m_hpBarBG.Update(gameTime);



            if (m_tNextWaterTrail < gameTime.TotalGameTime.TotalSeconds)
            {
                if (Throttle > 10.0f)
                {
                    EffectWaterTrail water = new EffectWaterTrail(Game);
                    water.Initialize((float)gameTime.TotalGameTime.TotalSeconds + 3.5f, Position + (Heading * 40), false);
                    water.Rotation = Rotation - MathHelper.PiOver2;

                    water = new EffectWaterTrail(Game);
                    water.Initialize((float)gameTime.TotalGameTime.TotalSeconds + 3.5f, Position + (Heading * 40), false);
                    water.Rotation = Rotation + MathHelper.PiOver2;

                    m_tNextWaterTrail = (float)gameTime.TotalGameTime.TotalSeconds + 0.1f;
                }
            }



            base.Update(gameTime);
        }