Esempio n. 1
0
 private void StopSound()
 {
     if (Sound == null)
     {
         return;
     }
     Sound.Stopped = true;
     Sound         = null;
 }
Esempio n. 2
0
 private void LoopSound(string sound, float volume = 0.9f)
 {
     StopSoundLoop = false;
     if (Sound != null)
     {
         return;
     }
     Sound = Game.SoundEngine.Play(sound, Position, volume, true);
 }
Esempio n. 3
0
 public void MakeSound(SoundEngine.Sound sound, float volume, Vector2 position)
 {
     CallAll(x => {
         if (x is IEnemy && x is Entity)
         {
             ((IEnemy)x).HearSound(position, volume, this);
         }
     });
 }
Esempio n. 4
0
 public void PlaySound()
 {
     if (TimePerLetter == 0)
     {
         return;
     }
     if (CallSound.Stopped)
     {
         CallSound = Game.SoundEngine.Play("Player_WalkieTalk1", 1, false);
     }
 }
Esempio n. 5
0
        public override void Update(Chunk chunk)
        {
            if (FlyingSound == null)
            {
                FlyingSound = Game.SoundEngine.Play("Enemy_DroneFly", Position, 1, true);
            }

            if (PositionKnown > 0)
            {
                --PositionKnown;
            }

            float dt = Game1.DeltaT;

            Velocity = new Vector2();

            switch (State)
            {
            case AIState.Patrolling:
                if (MoveTo(WanderLocation, PatrolSpeed))
                {
                    Wait();
                }
                break;

            case AIState.Searching:
                if (MoveTo(WanderLocation, SearchSpeed))
                {
                    Velocity = new Vector2(0);
                    bool foundSearch = false;
                    for (int i = 0; i < WanderSearchAttempts; ++i)
                    {
                        if (FindWander(TargetLocation, PatrolRange, chunk))
                        {
                            foundSearch = true;
                            break;
                        }
                    }
                    if (!foundSearch)
                    {
                        if (Target(TargetLocation, chunk, AIState.Targeting))
                        {
                            FinishPath = () => { };
                        }
                    }
                }
                break;

            case AIState.CursorySearching:
                if (MoveTo(WanderLocation, PatrolSpeed))
                {
                    Velocity = new Vector2(0);
                    bool foundSearch = false;
                    for (int i = 0; i < WanderSearchAttempts; ++i)
                    {
                        if (FindWander(TargetLocation, PatrolRange, chunk))
                        {
                            foundSearch = true;
                            break;
                        }
                    }
                    if (!foundSearch)
                    {
                        if (Target(TargetLocation, chunk, AIState.Investigating))
                        {
                            FinishPath = () => { };
                        }
                    }
                }

                StateTimer -= dt;
                if (StateTimer <= 0)
                {
                    Return(chunk);
                }
                break;

            case AIState.Waiting:
                StateTimer += dt;
                if (StateTimer <= 0.05F * WaitTime)
                {
                }
                if (StateTimer <= 0.25F * WaitTime)
                {
                    Direction += dt * WaitAngularVelocity;
                }
                else if (StateTimer <= 0.3F * WaitTime)
                {
                }
                else if (StateTimer <= 0.7F * WaitTime)
                {
                    Direction -= dt * WaitAngularVelocity;
                }
                else if (StateTimer <= 0.75F * WaitTime)
                {
                }
                else if (StateTimer <= 0.95F * WaitTime)
                {
                    Direction += dt * WaitAngularVelocity;
                }
                else if (StateTimer <= WaitTime)
                {
                }
                else
                {
                    bool found = false;
                    for (int i = 0; i < WanderSearchAttempts; ++i)
                    {
                        if (FindWander(Spawn, PatrolRange, chunk))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        Return(chunk);
                    }
                    else
                    {
                        State = AIState.Patrolling;
                    }
                }
                break;

            case AIState.Targeting:
                Vector2 nextPos = NextNode < Path.Count - 1 ? Path[NextNode] : TargetLocation;
                if (MoveTo(nextPos, TargetSpeed))
                {
                    Velocity = new Vector2();
                    ++NextNode;

                    nextPos = NextNode < Path.Count - 1 ? Path[NextNode] : TargetLocation;

                    if (NextNode >= Path.Count)
                    {
                        Search(nextPos, chunk, float.PositiveInfinity);
                    }
                    else
                    {
                        MoveTo(nextPos, TargetSpeed);
                    }
                }
                break;

            case AIState.Investigating:
                if (MoveTo(Path[NextNode], SearchSpeed))
                {
                    Velocity = new Vector2();
                    ++NextNode;
                    if (NextNode >= Path.Count)
                    {
                        Search(Path[NextNode - 1], chunk, SearchTime, true);
                    }
                    else
                    {
                        MoveTo(Path[NextNode], SearchSpeed);
                    }
                }
                break;

            case AIState.Returning:
                if (MoveTo(Path[NextNode], PatrolSpeed))
                {
                    ++NextNode;
                    if (NextNode >= Path.Count)
                    {
                        Wait();
                    }
                }
                break;
            }

            if (Pathfinding != null)
            {
                if (Pathfinding.IsCompleted)
                {
                    var newPath = Pathfinding.Result;

                    Pathfinding.Dispose();
                    Pathfinding = null;

                    if (newPath.Count > 1)
                    {
                        Path = newPath;

                        TargetLocation = Path.Last();

                        NextNode = 1;
                    }

                    State = NextState;

                    FinishPath.Invoke();
                }
            }

            { // Kill if touched.
                if (!chunk.Level.Player.IsHiding &&
                    chunk.Level.Player.DeathTimer <= 0 &&
                    GetBoundingBox().Intersects(chunk.Level.Player.GetBoundingBox()))
                {
                    chunk.Level.Player.Kill();
                }
            }

            if (State == AIState.Targeting || State == AIState.Searching)
            {
                Sprite.Play("chase");
            }
            else
            {
                Sprite.Play("idle");
            }

            Position += dt * Velocity;
            ViewCone.UpdatePosition(Position);
            ViewCone.Middle = Direction;
            ViewCone.Update(chunk);

            AlertSignal.Update(dt);
            Sprite.Update(dt);

            FlyingSound.Position = Position;

            base.Update(chunk);
        }
Esempio n. 6
0
        public override void Update()
        {
            if (CallSound == null && TimePerLetter > 0)
            {
                CallSound = Game.SoundEngine.Play("Player_WalkieTalk1", 1, false);
            }

            if (TimeBeforeSkip > 0)
            {
                TimeBeforeSkip -= Game1.DeltaT;
            }
            if (CurLetters < CurMaxLetters)
            {
                LetterTimer += Game1.DeltaT;

                while (LetterTimer >= TimePerLetter && CurLetters < CurMaxLetters)
                {
                    LetterTimer -= TimePerLetter;
                    ++CurLetters;
                }

                if (CurLetters >= CurMaxLetters)
                {
                    CurLetters = CurMaxLetters;
                    if (TimePerLetter > 0)
                    {
                        TimeBeforeSkip = TimeBeforeSkipDuration;
                    }
                }

                if (CurLetters < Math.Max(CurMaxLetters - 5, 2))
                {
                    PlaySound();
                }
            }
            else
            {
                if (TimeBeforeSkip <= 0)
                {
                    CallSound.Stopped = true;
                }
            }

            if (Game.Controller.Call && !Game.Controller.Was.Call)
            {
                Game.SoundEngine.Play("Player_WalkieEnd");
                CallSound.Stopped = true;
                Level.ClosePopup();
                return;
            }

            if ((!Game.Controller.Advance && Game.Controller.Was.Advance))
            {
                if (CurLetters < CurMaxLetters)
                {
                    CurLetters        = CurMaxLetters;
                    CallSound.Stopped = true;
                }
                else if (TimeBeforeSkip > 0)
                {
                    TimeBeforeSkip = 0;
                }
                else if (CurLine + MaxLines < CurNumLines)
                {
                    CurLine += (int)Math.Floor(MaxLines);

                    CurMaxLetters = 0;
                    for (int i = 0; i < Math.Min(CurLine + Math.Floor(MaxLines), CurNumLines); ++i)
                    {
                        CurMaxLetters++;
                        CurMaxLetters += CurLines[i].Length;
                    }
                    CurMaxLetters--;

                    TextOffset = CurLine * SizePx;
                }
                else
                {
                    ++CurText;

                    if (CurText >= TextArray.Length)
                    {
                        CallSound.Stopped = true;
                        Game.SoundEngine.Play("Player_WalkieEnd");
                        Level.ClosePopup();
                    }
                    else
                    {
                        Game.SoundEngine.Play("UI_Button", 1);

                        PlaySound();

                        SetText(TextArray[CurText]);
                        CurLines    = Text.Split('\n', StringSplitOptions.RemoveEmptyEntries);
                        CurNumLines = CurLines.Length;
                        CurLine     = 0;
                        TextOffset  = 0;
                        CurLetters  = 1;
                        //CurMaxLetters = Text.Length;

                        CurMaxLetters = 0;
                        for (int i = 0; i < Math.Min(CurLine + Math.Floor(MaxLines), CurNumLines); ++i)
                        {
                            CurMaxLetters++;
                            CurMaxLetters += CurLines[i].Length;
                        }
                        CurMaxLetters--;
                        LetterTimer = 0;
                    }
                }
            }
        }