示例#1
0
        /// <summary>
        /// Method that updates the game
        /// </summary>
        /// <param name="input">Input</param>
        /// <param name="gameTime">GameTime</param>
        public override void Update(Input input, GameTime gameTime)
        {
            base.Update(input, gameTime);

            // Check if the car has a path
            if (currentPath != null && currentPathIndex >= 0)
            {
                // Check if the car hasn't finished its path yet
                if (currentPathIndex < currentPath.Count)
                {
                    var target = currentPath[currentPathIndex];
                    if (Vector2.DistanceSquared(Position, target) < 24)
                    {
                        currentPathIndex++;
                        if (LoopPath && currentPathIndex >= currentPath.Count)
                        {
                            currentPathIndex = 0;
                        }
                    }
                    else
                    {
                        Rotation = MathExtensions.VectorToAngle(target - Position);

                        var delta = MathExtensions.AngleToVector(Rotation) * speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        Move(delta);
                    }
                }
                else
                {
                    currentPathIndex = -1;
                }
            }
            // Set the sound of the car to the position of the car
            carSound.Position = Position;
        }
示例#2
0
        /// <summary>
        /// Called once per frame
        /// </summary>
        /// <param name="input"></param>
        /// <param name="gameTime"></param>
        public override void Update(Input input, GameTime gameTime)
        {
            base.Update(input, gameTime);

            // If sleeping, dont do anything
            if (state == State.Sleeping)
            {
                return;
            }

            // If in pursuit
            if (state == State.Pursuit)
            {
                // Keep the animation running
                AnimationRunning = true;
                var target = playerPos;
                if (Vector2.DistanceSquared(Position, target) > 90)
                {
                    // Move towards player
                    Rotation = MathExtensions.VectorToAngle(target - Position);

                    var delta = MathExtensions.AngleToVector(Rotation) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    delta         *= RunSpeed;
                    AnimationDelta = 0.05f;
                    Move(delta);
                }
            }
            // Follow current path
            else if (currentPath != null && currentPathIndex >= 0)
            {
                AnimationRunning = true;
                if (currentPathIndex < currentPath.Count)
                {
                    var target = currentPath[currentPathIndex];
                    if (Vector2.DistanceSquared(Position, target) < 8)
                    {
                        currentPathIndex++;
                        if (state == State.Patrolling)  // Loop path when patrolling
                        {
                            if (currentPathIndex >= currentPath.Count)
                            {
                                currentPathIndex = 0;
                            }
                        }
                    }
                    else
                    {
                        // Move down the path
                        Rotation = MathExtensions.VectorToAngle(target - Position);

                        var delta = MathExtensions.AngleToVector(Rotation) * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        if (state == State.Alerted || state == State.ToAlert)
                        {
                            delta         *= RunSpeed;
                            AnimationDelta = 0.05f;
                        }
                        else
                        {
                            delta         *= WalkSpeed;
                            AnimationDelta = 0.1f;
                        }
                        Move(delta);
                    }
                }
                else
                {
                    // Reached end of path or waiting for a new one
                    currentPathIndex = -1;

                    if (state == State.Alerted || state == State.Interested)
                    {
                        StartSearch(gameTime);
                    }
                    else if (state == State.ToPatrol)
                    {
                        currentPath      = PatrolPath;
                        currentPathIndex = patrolPathIndex;
                        state            = State.Patrolling;
                    }
                }
            }
            // State stuff
            if (state == State.Idle)
            {
                StartPatrol();

                AnimationRunning      = false;
                AnimationCurrentFrame = 1;
            }
            else if (state == State.Searching)
            {
                // Wait a little bit at the spot when 'searching'
                if (gameTime.TotalGameTime.TotalSeconds >= searchStartTime + searchTime)
                {
                    state = State.Idle;
                }
                else
                {
                    AnimationRunning      = false;
                    AnimationCurrentFrame = 1;
                }
            }

            // We can hear the player but not see him
            if (!CanSee(out playerPos) && CanHear(out playerPos))
            {
                Interest(playerPos);
            }

            if (CanSee(out playerPos))
            {
                // We can see the player
                AnimationRunning = false;
                RunSpeed         = 0;
                WalkSpeed        = 0;

                // If player is spotted in JamesBond difficulty, instant game over
                if (SettingsPage.Difficulty.Equals(DifficultyLevels.JamesBond))
                {
                    player.Health -= 50;
                }
                else
                {
                    // Else we start following the player
                    state = State.Pursuit;
                    if (CanSee(out playerPos))
                    {
                        // Start shooting if we can see the player
                        if (gameTime.TotalGameTime.TotalSeconds >= shootStartTime + shootTime)
                        {
                            var bullet = new Bullet(Collider);
                            bullet.Position = Position;
                            bullet.Rotation = Rotation;
                            bullet.Rotation = MathExtensions.VectorToAngle(playerPos - Position);
                            MonoGearGame.SpawnLevelEntity(bullet);
                            var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Gunshot").CreateInstance();
                            sound.Volume = 0.4f * SettingsPage.Volume * SettingsPage.EffectVolume;
                            sound.Play();
                            shootStartTime = (float)gameTime.TotalGameTime.TotalSeconds;
                        }
                    }
                }
            }
            else if (state == State.Pursuit)
            {
                AnimationRunning = true;
                WalkSpeed        = 35.0f;
                RunSpeed         = 90.0f;
                // Can't see player anymore, but we just followed him so go looking for him
                Alert(playerPos);
            }
            else
            {
                AnimationRunning = true;
                WalkSpeed        = 35.0f;
                RunSpeed         = 90.0f;
            }
        }
示例#3
0
        /// <summary>
        /// Method that updates the game
        /// </summary>
        /// <param name="input">Input</param>
        /// <param name="gameTime">GameTime</param>
        public override void Update(Input input, GameTime gameTime)
        {
            base.Update(input, gameTime);

            var target = player.Position;

            Rotation = MathExtensions.VectorToAngle(target - Position);
            var distance = Vector2.Distance(Position, target);

            if (distance > 260)
            {
                // Move towards player
                var delta = MathExtensions.AngleToVector(Rotation) * (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (distance > 400)
                {
                    delta *= speed;
                }
                else if (player.CurrentVehicle != null)
                {
                    delta *= player.CurrentVehicle.Speed + 15;
                }
                else
                {
                    delta *= player.Speed + 15;
                }

                Move(delta);
            }

            heliSound.Position = Position;
            // Check if the delay is greater than 0
            if (delay > 0)
            {
                delay -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            // Check if the delay is smaller than 0
            if (delay <= 0 && distance < 320)
            {
                var missile = new Missile(MonoGearGame.FindEntitiesOfType <Player>()[0].Collider);

                // Check what barrel to shoot from
                Vector2 vec = new Vector2(18, 0);
                if (barrelNr == 0)
                {
                    vec.Y = 24;
                }
                if (barrelNr == 1)
                {
                    vec.Y = -24;
                }
                if (barrelNr == 2)
                {
                    vec.Y = 18;
                }
                if (barrelNr == 3)
                {
                    vec.Y = -18;
                }

                missile.Position = Position + Forward * vec.X + Right * vec.Y;
                missile.Rotation = MathExtensions.VectorToAngle(player.Position - missile.Position);

                MonoGearGame.SpawnLevelEntity(missile);

                barrelNr++;
                if (barrelNr > 3)
                {
                    barrelNr = 0;
                }

                var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Helicopter_missile").CreateInstance();
                sound.Volume = 0.5f * SettingsPage.Volume * SettingsPage.EffectVolume;
                sound.Play();

                delay = 1f + 3.0f * (float)MathExtensions.Random.NextDouble();
            }
        }