Пример #1
0
 public override void Update(GameTime gameTime)
 {
     if (Sound != null && SoundInstance == null)
     {
         SoundInstance = Sound.Play();
     }
 }
Пример #2
0
        public CorpseViewModel(Game game,
                               IActorGraphics actorGraphics,
                               Vector2 position,
                               Microsoft.Xna.Framework.Audio.SoundEffectInstance soundEffectInstance)
        {
            _actorGraphics       = actorGraphics ?? throw new ArgumentNullException(nameof(actorGraphics));
            _soundEffectInstance = soundEffectInstance;
            var shadowTexture = game.Content.Load <Texture2D>("Sprites/game-objects/simple-object-shadow");

            _rootSprite = new SpriteContainer
            {
                Position = position
            };

            var shadowSprite = new Sprite(shadowTexture)
            {
                Position = new Vector2(0, 0),
                Origin   = new Vector2(0.5f, 0.5f),
                Color    = new Color(Color.White, 0.5f)
            };

            _rootSprite.AddChild(shadowSprite);

            _actorGraphics.ShowOutlined   = false;
            _actorGraphics.ShowHitlighted = false;
            _rootSprite.AddChild(_actorGraphics.RootSprite);
        }
        public override void NPCLoot()
        {
            Microsoft.Xna.Framework.Audio.SoundEffectInstance snd = Main.PlaySound(SoundID.DD2_WyvernDeath, (int)npc.Center.X, (int)npc.Center.Y);
            if (snd != null)
            {
                snd.Pitch = -0.50f;
            }

            if (Main.rand.Next(100) == 0)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.LizardEgg);
            }
            if (Main.rand.Next(5) == 0 && SGAWorld.downedMurk > 1)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Biomass"), Main.rand.Next(1, 12));
            }
        }
Пример #4
0
        public override void AI()
        {
            Player player = Main.player[projectile.owner];

            #region Active check
            // This is the "active check", makes sure the minion is alive while the player is alive, and despawns if not
            if (player.dead || !player.active)
            {
                player.ClearBuff(Rotting_Worm_Staff.buffID);
            }
            if (player.HasBuff(Rotting_Worm_Staff.buffID))
            {
                projectile.timeLeft = 2;
            }
            #endregion

            #region General behavior
            Vector2 idlePosition = player.Top;
            idlePosition.X -= 48f * player.direction;

            // Teleport to player if distance is too big
            Vector2 vectorToIdlePosition   = idlePosition - projectile.Center;
            float   distanceToIdlePosition = vectorToIdlePosition.Length();
            if (Main.myPlayer == player.whoAmI && distanceToIdlePosition > 2000f)
            {
                // Whenever you deal with non-regular events that change the behavior or position drastically, make sure to only run the code on the owner of the projectile,
                // and then set netUpdate to true
                projectile.position  = idlePosition;
                projectile.velocity *= 0.1f;
                projectile.netUpdate = true;
            }

            // If your minion is flying, you want to do this independently of any conditions
            float overlapVelocity = 0.04f;
            for (int i = 0; i < Main.maxProjectiles; i++)
            {
                // Fix overlap with other minions
                Projectile other = Main.projectile[i];
                if (i != projectile.whoAmI && other.active && other.owner == projectile.owner && Math.Abs(projectile.position.X - other.position.X) + Math.Abs(projectile.position.Y - other.position.Y) < projectile.width)
                {
                    if (projectile.position.X < other.position.X)
                    {
                        projectile.velocity.X -= overlapVelocity;
                    }
                    else
                    {
                        projectile.velocity.X += overlapVelocity;
                    }

                    if (projectile.position.Y < other.position.Y)
                    {
                        projectile.velocity.Y -= overlapVelocity;
                    }
                    else
                    {
                        projectile.velocity.Y += overlapVelocity;
                    }
                }
            }
            #endregion

            #region Find target
            // Starting search distance
            float   targetDist   = 700f;
            float   targetAngle  = -2;
            Vector2 targetCenter = projectile.position;
            int     target       = -1;
            bool    foundTarget  = false;

            if (player.HasMinionAttackTargetNPC)
            {
                NPC   npc     = Main.npc[player.MinionAttackTargetNPC];
                float between = Vector2.Distance(npc.Center, projectile.Center);
                if (between < 2000f)
                {
                    targetDist   = between;
                    targetCenter = npc.Center;
                    target       = player.MinionAttackTargetNPC;
                    foundTarget  = true;
                }
            }
            if (!foundTarget)
            {
                for (int i = 0; i < Main.maxNPCs; i++)
                {
                    NPC npc = Main.npc[i];
                    if (npc.CanBeChasedBy())
                    {
                        Vector2 diff = projectile.Center - projectile.Center;
                        float   dist = diff.Length();
                        if (dist > targetDist)
                        {
                            continue;
                        }
                        float dot     = NormDot(diff, projectile.velocity);
                        bool  inRange = dist < targetDist;
                        //bool jumpOfHight = (npc.Bottom.Y-projectile.Top.Y)<160;
                        if (((dot > targetAngle && inRange) || !foundTarget))
                        {
                            targetDist   = dist;
                            targetAngle  = dot;
                            targetCenter = npc.height / (float)npc.width > 1 ? npc.Top + new Vector2(0, 8) : npc.Center;
                            target       = npc.whoAmI;
                            foundTarget  = true;
                        }
                    }
                }
            }

            projectile.friendly = foundTarget;
            #endregion

            #region Movement
            bool leap = false;
            if (foundTarget || distanceToIdlePosition <= 600f)
            {
                if (Collision.CanHitLine(projectile.position, projectile.width, projectile.height, projectile.position + projectile.velocity * 4, projectile.width, projectile.height))
                {
                    if (projectile.localAI[2] <= 0)
                    {
                        leap = true;
                    }
                    projectile.localAI[2] = 5;
                }
            }
            if (distanceToIdlePosition > 900f)
            {
                projectile.localAI[2] = 0;
            }
            // Default movement parameters (here for attacking)
            float speed        = 8f + (targetCenter.Y < projectile.Center.Y?(projectile.Center.Y - targetCenter.Y) / 32f:0);
            float turnSpeed    = 2f;
            float currentSpeed = projectile.velocity.Length();
            if (foundTarget)
            {
                if ((int)Math.Ceiling(targetAngle) == -1)
                {
                    targetCenter.Y -= 16;
                }
            }
            else
            {
                if (distanceToIdlePosition > 600f)
                {
                    speed = 16f;
                }
                else if (distanceToIdlePosition <= 120f)
                {
                    speed = 4f;
                }
            }
            if (projectile.localAI[2] > 0)
            {
                projectile.velocity.Y += 0.3f;
                turnSpeed              = 0.1f;
                projectile.localAI[2]--;
                if (leap)
                {
                    turnSpeed       = 10f;
                    targetCenter.Y -= 64 * NormDot(projectile.velocity, foundTarget ? targetCenter - projectile.Center : vectorToIdlePosition);
                }
            }
            else
            {
                LinearSmoothing(ref currentSpeed, speed, currentSpeed < 1?1:0.1f);
            }
            Vector2 direction = foundTarget?targetCenter - projectile.Center:vectorToIdlePosition;
            direction.Normalize();
            projectile.velocity = Vector2.Normalize(projectile.velocity + direction * turnSpeed) * currentSpeed;
            if (projectile.localAI[2] <= 0 && (++projectile.frameCounter) * currentSpeed > 60)
            {
                Microsoft.Xna.Framework.Audio.SoundEffectInstance se = Main.PlaySound(new Terraria.Audio.LegacySoundStyle(15, 1), projectile.Center);
                if (!(se is null))
                {
                    se.Pitch *= 2f;
                }
                projectile.frameCounter = 0;
            }
            #endregion

            #region Worminess
            projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2;
            OriginPlayer originPlayer = player.GetModPlayer <OriginPlayer>();
            if (projectile.localAI[0] == 0f)
            {
                //if(originPlayer.wormHeadIndex==-1) {
                projectile.velocity.Y += 6;
                projectile.localAI[3]  = projectile.whoAmI;
                int current = 0;
                int last    = projectile.whoAmI;
                int type    = Rotting_Worm_Body.ID;
                //body
                current = Projectile.NewProjectile(projectile.Center, Vector2.Zero, type, projectile.damage, projectile.knockBack, projectile.owner);
                Main.projectile[current].localAI[3] = projectile.whoAmI;
                Main.projectile[current].localAI[1] = last;
                Main.projectile[last].localAI[0]    = current;
                last = current;
                //tail
                current = Projectile.NewProjectile(projectile.Center, Vector2.Zero, Rotting_Worm_Tail.ID, projectile.damage, projectile.knockBack, projectile.owner);
                Main.projectile[current].localAI[3] = projectile.whoAmI;
                Main.projectile[current].localAI[1] = last;
                Main.projectile[last].localAI[0]    = current;

                /*} else {
                 *  Projectile segment = Main.projectile[originPlayer.wormHeadIndex];
                 *  int i = 0;
                 *  while(segment.type==Rotting_Worm_Staff.projectileID||segment.type==Rotting_Worm_Body.ID) {
                 *      segment.damage++;
                 *      if(i++>4)break;
                 *      segment.whoAmI+=0;
                 *      segment = Main.projectile[(int)segment.localAI[0]];
                 *  }
                 *  if(segment.type==Rotting_Worm_Tail.ID) {
                 *      float[] segmentAI = new float[4] { projectile.whoAmI, segment.localAI[1], segment.localAI[2], segment.localAI[3]  };
                 *      segment.SetToType(Rotting_Worm_Body.ID);
                 *      segment.localAI = segmentAI;
                 *      projectile.SetToType(Rotting_Worm_Tail.ID);
                 *      projectile.localAI = new float[4] { 0, segment.whoAmI, 0, segmentAI[3]  };
                 *  }
                 * }*/
            }/* else {
              * originPlayer.wormHeadIndex = projectile.whoAmI;
              * }*/
            #endregion
        }
Пример #5
0
 public void Apply3D(Microsoft.Xna.Framework.Audio.SoundEffectInstance inst)
 {
     Emitter3D.Forward = VM.Listener.Forward;
     inst.Volume       = 1f;
     inst.Apply3D(VM.Listener, Emitter3D);
 }
Пример #6
0
        public void Update(float pSeconds)
        {
            Particles.ParticleManager.Instance().Update(pSeconds);

            Vector2 collisionNormal;

            for (int tankIndex = 0; tankIndex < m_Tanks.Count; tankIndex++)
            {
                List <Bullet> bulletList = m_Tanks[tankIndex].GetBulletList();
                for (int i = bulletList.Count - 1; i >= 0; --i)
                {
                    bool collided = false;
                    bulletList[i].Update(pSeconds);
                    for (int tankIndex2 = 0; tankIndex2 < m_Tanks.Count; tankIndex2++)
                    {
                        if (tankIndex == tankIndex2)
                        {
                            continue;
                        }
                        if (bulletList[i].Collide(m_Tanks[tankIndex2], out collisionNormal))
                        {
                            ExplosionInitialisationPolicy explosion = new ExplosionInitialisationPolicy(bulletList[i].Position, collisionNormal, m_Tanks[tankIndex].Colour());
                            Particles.ParticleManager.Instance().InitialiseParticles(explosion, 100);
                            m_Tanks[tankIndex2].TakeDamage();
                            int    clang     = rand.Next(1, 4);
                            string tankClang = "Sounds/Tank_Clang" + clang;
                            Microsoft.Xna.Framework.Audio.SoundEffectInstance tankClangSound = Tankontroller.Instance().GetSoundManager().GetSoundEffectInstance(tankClang);
                            tankClangSound.Play();
                            collided = true;
                            break;
                        }
                    }
                    foreach (RectWall wall in Walls)
                    {
                        if (wall.Collide(bulletList[i], out collisionNormal))
                        {
                            ExplosionInitialisationPolicy explosion = new ExplosionInitialisationPolicy(bulletList[i].Position, collisionNormal, m_Tanks[tankIndex].Colour());
                            Particles.ParticleManager.Instance().InitialiseParticles(explosion, 100);
                            collided = true;
                            break;
                        }
                    }
                    if (collided)
                    {
                        bulletList.RemoveAt(i);
                    }
                }
            }

            foreach (RectWall w in Walls)
            {
                foreach (Tank t in m_Tanks)
                {
                    if (w.Collide(t))
                    {
                        t.PutBack();
                    }
                }
            }

            for (int i = 0; i < m_Tanks.Count; i++)
            {
                for (int j = i + 1; j < m_Tanks.Count; j++)
                {
                    if (m_Tanks[i].Collide(m_Tanks[j]))
                    {
                        m_Tanks[i].PutBack();
                        m_Tanks[j].PutBack();
                    }
                }
            }
        }
Пример #7
0
 /// <summary>
 /// Requeue each item after it's done playing
 /// </summary>
 /// <param name="sfx"></param>
 private void AudioManager_OnQueuedFinished(Microsoft.Xna.Framework.Audio.SoundEffectInstance sfx)
 {
     this.AudioManager.QueuePlay(sfx);
 }