Exemple #1
0
 /// <summary>
 /// Plays a music/ambience/etc. sound. The previously played music fades out.
 /// </summary>
 /// <param name="music">The sound resource to play.</param>
 /// <param name="volume">The playback volume of sound to play. Ranging from 0f to 1f.</param>
 /// <param name="fadeSeconds">The time this piece takes to fade in, and the previous piece to fade out.</param>
 /// <param name="looped">Wheter the piece should be looped or not.</param>
 public static void PlayMusic(ContentRef <Sound> music, float volume = 1f, float fadeSeconds = 1f, bool looped = true)
 {
     if (musicInstance != null && !musicInstance.Paused)
     {
         musicInstance.FadeOut(fadeSeconds);
     }
     musicInstance        = DualityApp.Sound.PlaySound(music);
     musicInstance.Looped = looped;
     musicInstance.BeginFadeIn(fadeSeconds);
 }
Exemple #2
0
 public override void OnDestroyed()
 {
     if (sound != null)
     {
         sound.FadeOut(0.8f);
         sound = null;
     }
 }
Exemple #3
0
 protected override void OnDeactivated(ShutdownContext context)
 {
     if (sound != null)
     {
         sound.FadeOut(0.8f);
         sound = null;
     }
 }
Exemple #4
0
        protected override void OnFixedUpdate(float timeMult)
        {
            OnUpdateHitbox();
            HandleBlinking(timeMult);

            if (frozenTimeLeft > 0)
            {
                frozenTimeLeft -= timeMult;
                return;
            }

            if (attackTime > 0f)
            {
                attackTime -= timeMult;
            }
            else
            {
                if (attacking)
                {
                    targetPos = originPos;

                    attackTime = 90f;
                    attacking  = false;

                    if (noise != null)
                    {
                        noise.FadeOut(1f);
                        noise = null;
                    }
                }
                else
                {
                    AttackNearestPlayer();
                }
            }

            anglePhase += timeMult * 0.05f;

            Vector3 speed = ((targetPos - lastPos) / 30f + lastSpeed * 1.4f) / 2.4f;

            lastPos.X += speed.X;
            lastPos.Y += speed.Y;
            lastSpeed  = speed;

            bool willFaceLeft = (speed.X < 0f);

            if (IsFacingLeft != willFaceLeft)
            {
                SetTransition(AnimState.TransitionTurn, false, delegate {
                    IsFacingLeft = willFaceLeft;
                });
            }

            Transform.Pos = lastPos + new Vector3(MathF.Cos(anglePhase) * 16f, MathF.Sin(anglePhase) * -16f, 0f);
        }
Exemple #5
0
 public override void OnHandleCollision(ActorBase other)
 {
     switch (other)
     {
     case Player player: {
         if (player.SetDizzyTime(180f))
         {
             SoundInstance sound = PlaySound("Dizzy");
             sound.Looped = true;
             sound.FadeOut(2.4f);
         }
         break;
     }
     }
 }
 static public void PlayMusic(ContentRef <Sound> musicRef)
 {
     if (musicSoundInstance == null)
     {
         musicSoundInstance        = DualityApp.Sound.PlaySound(musicRef);
         musicSoundInstance.Looped = true;
     }
     else if (musicSoundInstance.Sound != musicRef)
     {
         musicSoundInstance.FadeOut(2);
         musicSoundInstance        = DualityApp.Sound.PlaySound(musicRef);
         musicSoundInstance.Looped = true;
         musicSoundInstance.BeginFadeIn(2);
     }
 }
Exemple #7
0
 public static void FadeOutMusic()
 {
     if (sfx != null)
     {
         var sounds = DualityApp.Sound.Playing.ToArray();
         foreach (var sound in sounds)
         {
             sound.Looped = false;
             sound.FadeOut(1.5f);
         }
     }
     if (mus != null)
     {
         mus.FadeOut(1.5f);
     }
 }
Exemple #8
0
        protected override void OnUpdate()
        {
            base.OnUpdate();

            if (frozenTimeLeft > 0)
            {
                return;
            }

            canJump = false;

            Vector3 pos = Transform.Pos;

            if (attackCooldown < 0f)
            {
                attackCooldown = 40f;

                Vector3 targetPos;

                List <Player> players = api.Players;
                for (int i = 0; i < players.Count; i++)
                {
                    targetPos = players[i].Transform.Pos;
                    direction = (targetPos.Xy - pos.Xy);
                    float length = direction.Length;
                    if (length < 320f && targetPos.Y < api.WaterLevel)
                    {
                        direction.Normalize();

                        speedX       = speedY = 0f;
                        IsFacingLeft = (direction.X < 0f);
                        state        = StateAttacking;

                        idleTime       = MathF.Rnd.NextFloat(40f, 60f);
                        attackCooldown = MathF.Rnd.NextFloat(130f, 200f);

                        noise = PlaySound("Noise", 0.8f);
                        break;
                    }
                }
            }
            else
            {
                float timeMult = Time.TimeMult;

                if (state == StateAttacking)
                {
                    if (idleTime < 0f)
                    {
                        state = StateBraking;

                        if (noise != null)
                        {
                            noise.FadeOut(1f);
                            noise = null;
                        }
                    }
                    else
                    {
                        idleTime -= Time.TimeMult;

                        speedX += direction.X * 0.14f * timeMult;
                        speedY += direction.Y * 0.14f * timeMult;
                    }
                }
                else if (state == StateBraking)
                {
                    speedX *= 0.88f / timeMult;
                    speedY *= 0.88f / timeMult;

                    if (MathF.Abs(speedX) < 0.01f && MathF.Abs(speedY) < 0.01f)
                    {
                        state = StateIdle;
                    }
                }
                else
                {
                    if (idleTime < 0f)
                    {
                        float x = MathF.Rnd.NextFloat(-0.4f, 0.4f);
                        float y = MathF.Rnd.NextFloat(-2f, 2f);

                        speedX = (speedX + x) * 0.2f;
                        speedY = (speedY + y) * 0.2f;

                        idleTime = 20f;
                    }
                    else
                    {
                        idleTime -= timeMult;
                    }
                }

                // Can't fly into the water
                if (pos.Y > api.WaterLevel - 12f)
                {
                    speedY = -0.4f;
                    state  = StateIdle;

                    if (noise != null)
                    {
                        noise.FadeOut(0.4f);
                        noise = null;
                    }
                }

                attackCooldown -= timeMult;
            }
        }
        public void OnUpdate()
        {
            m_direction = -this.GameObj.Transform.Pos;
            this.GameObj.Transform.Angle = m_direction.Xy.Angle + MathF.RadAngle180;

            Vector3         moveDelta       = Time.TimeMult * m_direction * m_speed;
            LevelController levelController = this.GameObj.ParentScene.FindComponent <LevelController>();

            // Hovering animation
            {
                SpriteRenderer sprite = this.GameObj.GetComponent <SpriteRenderer>();
                if (this.initialSpriteRect == Rect.Empty)
                {
                    this.initialSpriteRect = sprite.Rect;
                }
                float hoverTimeOffset = (float)(this.GameObj.Id.GetHashCode() % 1000) / 1000.0f;
                sprite.Rect = new Rect(
                    this.initialSpriteRect.X,
                    this.initialSpriteRect.Y + 10.0f * (1.0f + MathF.Sin(2.0f * (float)Time.GameTimer.TotalSeconds + hoverTimeOffset)),
                    this.initialSpriteRect.W,
                    this.initialSpriteRect.H);
            }

            switch (m_shipState)
            {
            case ShipState.MoveToTarget:
                this.GameObj.Transform.MoveBy(moveDelta);
                if (IsInShootingRange())
                {
                    StartScanning();
                }
                break;

            case ShipState.ScanTarget:
                //Log.Game.Write("countdownTime: {0}, lastDelta: {1}", m_countdownToAttack, Time.LastDelta);
                if (m_beamSoundInstance == null || m_beamSoundInstance.Disposed)
                {
                    m_beamSoundInstance        = DualityApp.Sound.PlaySound(m_beamSound);
                    m_beamSoundInstance.Looped = true;
                    m_beamSoundInstance.Pitch  = MathF.Rnd.NextFloat(0.8f, 1.25f);
                }
                m_countdownToAttack -= Time.LastDelta / 1000;
                if (levelController == null || levelController.IsGameOver)
                {
                    m_beamSoundInstance.Volume = 0.1f + 0.1f * MathF.Clamp(1.0f - ((float)m_countdownToAttack / (float)m_scanDuration), 0.0f, 1.0f);
                }
                else
                {
                    m_beamSoundInstance.Volume = 0.5f + 0.5f * MathF.Clamp(1.0f - ((float)m_countdownToAttack / (float)m_scanDuration), 0.0f, 1.0f);
                }

                UpdateLineRenderer(false);
                if (m_countdownToAttack <= 0)
                {
                    //Log.Game.Write("distance: {0}", this.GameObj.Transform.Pos.LengthSquared);
                    Vector2 hitPos;
                    if (ScanPlanet(out hitPos))
                    {
                        m_hitPosition = new Vector3(hitPos.X, hitPos.Y, 0);
                        StartShooting();
                    }
                    else
                    {
                        StartLeaving();
                    }
                    m_beamSoundInstance.FadeOut(0.1f);
                }
                break;

            case ShipState.ShootTarget:
                if (m_target != null)
                {
                    if (levelController != null && !levelController.IsGameOver)
                    {
                        DualityApp.Sound.PlaySound(m_lockAcquiredSound);
                    }

                    Planet planetComp = m_target.GetComponent <Planet>();
                    if (planetComp != null)
                    {
                        planetComp.IncreaseDetectionCounter();
                    }
                }
                SpawnParticle();
                m_shipState = ShipState.LockPosition;
                break;

            case ShipState.LeaveTarget:
                this.GameObj.Transform.MoveBy(-moveDelta);
                if (IsOutsideRange())
                {
                    StartWaiting();
                }
                break;

            case ShipState.Waiting:
                m_countdownToAttack -= Time.LastDelta / 1000;
                if (m_countdownToAttack <= 0)
                {
                    StartMovingToTarget();
                }
                break;

            case ShipState.LockPosition:
                // occasionally spawn particles pulled towards the ship
                m_countdownToAttack -= Time.LastDelta / 1000;
                if (m_countdownToAttack <= 0)
                {
                    SpawnParticle();
                }
                break;

            default:
                break;
            }
        }