Пример #1
0
        /// <summary>
        /// Called when level is loaded or entity is added to scene
        /// </summary>
        public override void OnLevelLoaded()
        {
            base.OnLevelLoaded();

            tankSound       = AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Tank Movement"), 0, 250, Position, true);
            destroyedSprite = MonoGearGame.GetResource <Texture2D>("Sprites/BrokenAbrams");
        }
Пример #2
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);

            Collider collider;
            var      pos   = Position;
            var      delta = Forward * Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

            Move(delta);

            bool hitTilemap;

            // Check if the sleep dart collides with anything
            if (Collider.CollidesAny(out collider, out hitTilemap, originCollider))
            {
                Position = pos;
                // Set the speed to 0
                Speed = 0.0f;
                // Check if the sleep dart collides with a guard
                if (collider != null && collider.Entity.Tag.Equals("Guard"))
                {
                    var guard = collider.Entity as Guard;
                    guard.Sleep();
                    var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/DartHit").CreateInstance();
                    sound.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume;
                    sound.Play();
                    MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/HurtSound").CreateInstance();
                    sound.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume;
                    sound.Play();
                    MonoGearGame.DestroyEntity(this);
                }
                // Disable the sleep dart
                Enabled = false;
            }
        }
Пример #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);

            // Check if the player is in range
            if (Vector2.Distance(Position, player.Position) < 20)
            {
                inRange = true;
            }
            else
            {
                inRange = false;
            }
            // Check if the interact button is pressed
            if (input.IsButtonPressed(Input.Button.Interact) && inRange)
            {
                hackingProgress += ProgressPerClick;
                var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Hacking_sound").CreateInstance();
                sound.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume;
                sound.Play();
            }
            // Check if the hacking progress is completed
            if (hackingProgress >= 100)
            {
                // Hack the pc
                HackPC();
                Enabled = false;
                if (Objective != null)
                {
                    // Complete the objective
                    GameUI.CompleteObjective(Objective);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Method that executes when the level is loaded.
        /// </summary>
        public override void OnLevelLoaded()
        {
            base.OnLevelLoaded();
            // Add a sound effect to the car
            carSound = AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Deja Vu"), 0.3f, 500, Position, true);

            destroyedSprite = MonoGearGame.GetResource <Texture2D>("Sprites/BrokenCar");
        }
Пример #5
0
        /// <summary>
        /// Method that executes when the level is loaded.
        /// </summary>
        public override void OnLevelLoaded()
        {
            base.OnLevelLoaded();
            birdSound        = AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Bird_sounds"), 1, 210, Position, true);
            birdSound.Volume = 0.2f;

            destroyedSprite = MonoGearGame.GetResource <Texture2D>("Sprites/DeadBird");
        }
Пример #6
0
 protected virtual void LoadContent()
 {
     instanceTexture = MonoGearGame.GetResource <Texture2D>(TextureAssetName);
     if (instanceTexture != null)
     {
         Size = new Vector2(instanceTexture.Bounds.Size.X, instanceTexture.Bounds.Size.Y);
     }
 }
Пример #7
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)
        {
            if (creditsMode)
            {
                // Fire at player jeep once
                if (Vector2.Distance(player.Position, Position) < 250)
                {
                    FireCannon();
                    creditsMode = false;
                }
            }

            // Input and movement handling
            base.Update(input, gameTime);

            if (destroyed)
            {
                AudioManager.StopPositional(tankSound);
            }


            float minVolume = 0.1f;

            if (Entered)
            {
                // Speed based sound
                tankSound.Position = Position;
                tankSound.Volume   = minVolume + (0.2f - minVolume) * Math.Abs(forwardSpeed) / Speed;

                // Player controlled cannon
                if (input.IsButtonPressed(Input.Button.Shoot) && lastShootTime + GunCycleTime <= (float)gameTime.TotalGameTime.TotalSeconds)
                {
                    lastShootTime = (float)gameTime.TotalGameTime.TotalSeconds;
                    FireCannon();
                }

                // Player controlled MG
                if (input.IsButtonPressed(Input.Button.Throw))
                {
                    var bullet = new Bullet(Collider);
                    bullet.Rotation = Rotation;

                    bullet.Position = Position + Forward * 18 + Right * 10;

                    MonoGearGame.SpawnLevelEntity(bullet);

                    var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Tank_gatling").CreateInstance();
                    sound.Volume = 0.5f * SettingsPage.Volume * SettingsPage.EffectVolume;
                    sound.Play();
                }
            }
            else
            {
                tankSound.Volume = minVolume;
            }
        }
Пример #8
0
        /// <summary>
        /// Method that draws the pc.
        /// </summary>
        /// <param name="spriteBatch">SpriteBatch</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            if (inRange && !hacked)
            {
                spriteBatch.DrawString(MonoGearGame.GetResource <SpriteFont>("Fonts/Arial"), "PRESS C TO HACK...", Position + new Vector2(-35, 16), Color.White);
                spriteBatch.DrawString(MonoGearGame.GetResource <SpriteFont>("Fonts/Arial"), "PROGRESS: " + hackingProgress.ToString() + "%", Position + new Vector2(-35, 24), Color.White);
            }
        }
Пример #9
0
        /// <summary>
        /// Method that loads the content.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            // Load sprite
            if (gameOverSprite == null)
            {
                gameOverSprite = MonoGearGame.GetResource <Texture2D>("Sprites/gameover");
            }
        }
Пример #10
0
        /// <summary>
        /// Method that executes when the level is loaded.
        /// </summary>
        public override void OnLevelLoaded()
        {
            base.OnLevelLoaded();
            // Find the player
            player = MonoGearGame.FindEntitiesWithTag("Player")[0] as Player;

            //Play the explotion sound on creation
            sound          = AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Explosion"), 1, 1200, Position, false);
            sound.Position = Position;
            sound.Volume   = 0.8f;
        }
Пример #11
0
 public void Sleep()
 {
     if (state != State.Sleeping)
     {
         Enabled               = false;
         Z                     = -1; // Display below player
         AnimationRunning      = false;
         AnimationCurrentFrame = 1;
         state                 = State.Sleeping;
         sound                 = AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/snoreWhistle"), 1, 150, Position, true);
         sound.Volume          = 0.2f;
     }
 }
Пример #12
0
        /// <summary>
        /// Method used to enable the gameover screen
        /// </summary>
        public void EnableGameOver()
        {
            // Find the player
            player         = MonoGearGame.FindEntitiesWithTag("Player")[0] as Player;
            gameOver       = true;
            Position       = player.Position;
            Visible        = true;
            player.Enabled = false;

            var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Wasted_sound").CreateInstance();

            sound.Volume = 0.5f * SettingsPage.Volume * SettingsPage.EffectVolume;
            sound.Play();
        }
Пример #13
0
        /// <summary>
        /// Method that executes when the level is loaded.
        /// </summary>
        public override void OnLevelLoaded()
        {
            base.OnLevelLoaded();

            player = MonoGearGame.FindEntitiesWithTag("Player")[0] as Player;

            if (props == null)
            {
                props = MonoGearGame.GetResource <Texture2D>("Sprites/Soisoisoisoisoisoisoisoisoisoisoisoisoisoisoisois");
            }
            heliSound        = AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Helicopter Sound Effect"), 1, 300, Position, true);
            heliSound.Volume = 0.1f;
            destoyedSprite   = MonoGearGame.GetResource <Texture2D>("Sprites/BrokenRoflcopter");
        }
Пример #14
0
        /// <summary>
        /// Adds a foreground layer.
        /// </summary>
        /// <param name="layer"></param>
        public void AddForegroundLayer(LevelOverlay layer)
        {
            if (layer.texture == null)
            {
                layer.texture = MonoGearGame.GetResource <Texture2D>(layer.textureName);
            }

            foregroundLayers.Add(layer);
            foregroundLayers.Sort(
                (a, b) =>
            {
                return(a.layer.CompareTo(b.layer));
            });
        }
Пример #15
0
        /// <summary>
        /// Fires tank main gun by spaning a missile
        /// </summary>
        public void FireCannon()
        {
            var missile = new Missile(MonoGearGame.FindEntitiesOfType <Player>()[0].Collider);

            missile.Rotation = Rotation;

            missile.Position = Position + Forward * 88;

            MonoGearGame.SpawnLevelEntity(missile);

            var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Tank_shot").CreateInstance();

            sound.Volume = 0.5f * SettingsPage.Volume * SettingsPage.EffectVolume;
            sound.Play();
        }
Пример #16
0
        /// <summary>
        /// Method that executes when the level is loaded.
        /// </summary>
        public override void OnLevelLoaded()
        {
            base.OnLevelLoaded();

            jeepSound        = AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Car"), 0, 300, Position, true);
            jeepSound.Volume = 0.1f;

            playerSprite    = MonoGearGame.GetResource <Texture2D>("Sprites/WillysPlayer");
            destroyedSprite = MonoGearGame.GetResource <Texture2D>("Sprites/BrokenWillys");
            jeepSprite      = MonoGearGame.GetResource <Texture2D>("Sprites/Willys");

            // Enter on level load, for example heli chase scene
            if (autoenter)
            {
                Enter();
            }
        }
Пример #17
0
        /// <summary>
        /// Alerts a guard to the specified position and changes state
        /// </summary>
        /// <param name="origin"></param>
        public async void Alert(Vector2 origin)
        {
            // Make sure the correct thing happens based on the current state
            if (!Enabled || state == State.ToAlert)
            {
                return;
            }

            if (state == State.Patrolling)
            {
                patrolPathIndex = currentPathIndex;
            }

            if (state != State.Alerted)
            {
                var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Guard_Alert_Sound").CreateInstance();
                sound.Volume = 0.4f * SettingsPage.Volume * SettingsPage.EffectVolume;
                sound.Play();
            }

            state = State.ToAlert;

            // Small delay before being alerted
            await Task.Delay(1000);

            // Find a path
            Task.Run(() =>
            {
                Pathfinding.FindPath(Position, origin, (path) =>
                {
                    currentPath      = path;
                    currentPathIndex = 0;
                    state            = path != null ? State.Alerted : State.Idle;
                    Random rand      = new Random();
                    int number       = rand.Next(0, 9);
                    if (number == 0)
                    {
                        var sound    = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Get_over_here").CreateInstance();
                        sound.Volume = 0.2f * SettingsPage.Volume * SettingsPage.EffectVolume;
                        sound.Play();
                    }
                });
            });
        }
Пример #18
0
        /// <summary>
        /// Loads content
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            if (deadSprite == null)
            {
                deadSprite = MonoGearGame.GetResource <Texture2D>("Sprites/Dead");
            }

            // Load sounds
            walkingSoundGrass        = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Running On Grass").CreateInstance();
            walkingSoundWater        = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Water_Drop_Sound").CreateInstance();
            walkingSoundStone        = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Concrete").CreateInstance();
            walkingSoundGrass.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume;
            walkingSoundWater.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume;
            walkingSoundStone.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume;

            // Default walking sound
            walkingSound = walkingSoundGrass;
        }
Пример #19
0
        /// <summary>
        /// Method that executes when the level is loaded.
        /// </summary>
        public override void OnLevelLoaded()
        {
            base.OnLevelLoaded();

            AudioManager.PlayGlobal(MonoGearGame.GetResource <SoundEffect>("Audio/Music/America_Horse_With_No_Name").CreateInstance());

            // Load all sprites
            wouter        = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/Wouter");
            manuel        = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/Manuel");
            bram          = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/Bram");
            danny         = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/Danny");
            tom           = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/Tom");
            thomas        = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/Thomas");
            madeby        = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/MadeBy");
            specialThanks = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/SpecialThanks");
            music         = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/Music");
            dejaVu        = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/DejaVu");
            america       = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/America");
            kevin         = MonoGearGame.GetResource <Texture2D>("Sprites/Credits/Kevin");
        }
Пример #20
0
        /// <summary>
        /// Called to load content
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            // Load sprites
            if (alertSprite == null)
            {
                alertSprite = MonoGearGame.GetResource <Texture2D>("Sprites/Alert");
            }
            if (searchSprite == null)
            {
                searchSprite = MonoGearGame.GetResource <Texture2D>("Sprites/Searching");
            }
            if (sleepSprite == null)
            {
                sleepSprite = MonoGearGame.GetResource <Texture2D>("Sprites/Sleeping");
            }
            if (fovSprite == null)
            {
                fovSprite = MonoGearGame.GetResource <Texture2D>("Sprites/fov100");
            }
        }
Пример #21
0
        /// <summary>
        /// Alerts a guard to the specified position and changes state.
        /// Will call Alert if the guard is already alerted.
        /// </summary>
        /// <param name="origin"></param>
        public async void Interest(Vector2 origin)
        {
            if (!Enabled || state == State.ToInterest)
            {
                return;
            }

            // Escalate to an alert if we're already alerted
            if (state == State.Alerted || state == State.ToAlert)
            {
                Alert(origin);
                return;
            }

            if (state == State.Patrolling)
            {
                patrolPathIndex = currentPathIndex;
            }

            if (state != State.Interested)
            {
                var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Guard_Alert_Sound").CreateInstance();
                sound.Volume = 0.4f * SettingsPage.Volume * SettingsPage.EffectVolume;
                sound.Play();
            }

            state = State.ToInterest;
            await Task.Delay(1000);

            Task.Run(() =>
            {
                Pathfinding.FindPath(Position, origin, (path) =>
                {
                    currentPath      = path;
                    currentPathIndex = 0;
                    state            = path != null ? State.Interested : State.Idle;
                });
            });
        }
Пример #22
0
        /// <summary>
        /// Draws the UI.
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            var rect = Camera.main.GetClippingRect();

            #region Draw Health and darts

            var pos = rect.Right - 100;
            for (int i = 0; i < player.Health; i++)
            {
                // Draw a hart
                spriteBatch.Draw(MonoGearGame.GetResource <Texture2D>("Sprites/Heart"), new Vector2(pos, rect.Bottom - 50), Color.White);
                pos += 15;
            }

            // Check if the player has six or less darts.
            if (player.DartCount <= 6)
            {
                pos = rect.Right - 100;
                for (int i = 0; i < player.DartCount; i++)
                {
                    // Draw a dart
                    spriteBatch.Draw(MonoGearGame.GetResource <Texture2D>("Sprites/SleepDart"), new Vector2(pos, rect.Bottom - 32), Color.White);
                    pos += 15;
                }
            }
            else
            {
                spriteBatch.DrawString(MonoGearGame.GetResource <SpriteFont>("Fonts/Arial"), "Darts: " + player.DartCount, new Vector2(rect.Right - 100, rect.Bottom - 32), Color.Red);
            }
            #endregion

            #region Draw Vehicle Health

            if (player.CurrentVehicle != null)
            {
                pos = rect.Right - 100;
                var rows         = Math.Ceiling(player.CurrentVehicle.Health / 25);
                var healthToDraw = player.CurrentVehicle.Health / 5;
                var h            = 5.0f;

                for (int j = 0; j < rows; j++)
                {
                    if (healthToDraw < 5)
                    {
                        h = healthToDraw;
                    }

                    for (int i = 0; i < h; i++)
                    {
                        // Draw a heart
                        spriteBatch.Draw(MonoGearGame.GetResource <Texture2D>("Sprites/Wrench"), new Vector2(pos, rect.Bottom - (70 + (j * 18))), Color.White);
                        pos += 15;
                    }
                    pos           = rect.Right - 100;
                    healthToDraw -= 5;
                }
            }

            #endregion

            #region Draw Objective

            // Check if there are any objectives
            if (objectives.Count > 0)
            {
                // Draw a string with the objective text
                spriteBatch.DrawString(MonoGearGame.GetResource <SpriteFont>("Fonts/Arial"), "Objective:", new Vector2(rect.Left + 16, rect.Top + 10), Color.LightGray);
                spriteBatch.DrawString(MonoGearGame.GetResource <SpriteFont>("Fonts/Arial"), objectives[0].ToString(), new Vector2(rect.Left + 16, rect.Top + 21), Color.LightGray);
            }
            else
            {
                // Draw a no objective string
                spriteBatch.DrawString(MonoGearGame.GetResource <SpriteFont>("Fonts/Arial"), "No objective", new Vector2(rect.Left + 16, rect.Top + 16), Color.LightGray);
            }

            #endregion
        }
Пример #23
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();
            }
        }
Пример #24
0
        /// <summary>
        /// Called once per frame
        /// </summary>
        /// <param name="input">input</param>
        /// <param name="gameTime">gametime</param>
        public override void Update(Input input, GameTime gameTime)
        {
            // Animation done by parent class
            base.Update(input, gameTime);

            // Movement delta
            var dx = 0.0f;
            var dy = 0.0f;

            // Use analog sticks or keyboard for movement depending on if we have a gamepad connected
            if (input.PadConnected())
            {
                var sticks = input.GetGamepadState().ThumbSticks;

                dx += sticks.Left.X * Speed;
                dy += sticks.Left.Y * Speed;
            }
            else
            {
                if (input.IsButtonDown(Input.Button.Left))
                {
                    dx -= Speed;
                }
                if (input.IsButtonDown(Input.Button.Right))
                {
                    dx += Speed;
                }
                if (input.IsButtonDown(Input.Button.Up))
                {
                    dy -= Speed;
                }
                if (input.IsButtonDown(Input.Button.Down))
                {
                    dy += Speed;
                }
            }

            // Sneak mode
            if (input.IsButtonDown(Input.Button.Sneak))
            {
                SneakMode = true;
                Speed     = 50;
            }
            else
            {
                SneakMode = false;
                Speed     = 100;
            }

            // Clamp movement speed
            var delta = new Vector2(dx, dy);

            if (delta.LengthSquared() > Speed * Speed)
            {
                delta.Normalize();
                delta *= Speed;
            }

            // Get correct tile sound
            var tilevalue = MonoGearGame.GetCurrentLevel().GetTile(Position)?.Sound;
            SoundEffectInstance tilesound;

            switch (tilevalue)
            {
            case Tile.TileSound.Grass:
                tilesound = walkingSoundGrass;
                break;

            case Tile.TileSound.Water:
                tilesound = walkingSoundWater;
                break;

            case Tile.TileSound.Concrete:
                tilesound = walkingSoundStone;
                break;

            default:
                tilesound = walkingSoundStone;
                break;
            }

            if (tilesound != null && tilesound != walkingSound)
            {
                // stop old sound
                walkingSound.Stop();
                walkingSound = tilesound;
            }

            if (delta.LengthSquared() > 0)
            {
                // Moving
                Rotation         = MathExtensions.VectorToAngle(delta);
                AnimationRunning = true;
                walkingSound.Play();
            }
            else
            {
                // Standing still
                SneakMode             = true;
                AnimationRunning      = false;
                AnimationCurrentFrame = 1;
                walkingSound.Stop();
            }

            // Sneaking is silent
            if (SneakMode)
            {
                walkingSound.Stop();
            }

            // Reduce delay per frame
            if (ThrowingDelay > 0)
            {
                ThrowingDelay -= 1;
            }


            // Throw rock
            if (input.IsButtonPressed(Input.Button.Throw))
            {
                if (ThrowingDelay <= 0)
                {
                    // Spawn rock and play sound
                    var rock = new Rock(MonoGearGame.FindEntitiesOfType <Player>()[0].Collider);
                    rock.Position = Position;
                    rock.Rotation = Rotation;
                    MonoGearGame.SpawnLevelEntity(rock);
                    ThrowingDelay = 45;
                    var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/StoneTrow_sound").CreateInstance();
                    sound.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume;
                    sound.Play();
                }
            }

            // Shoot sleep dart
            if (input.IsButtonPressed(Input.Button.Shoot))
            {
                if (DartCount > 0)
                {
                    // Spawn dart and play sound
                    var sleepDart = new SleepDart(MonoGearGame.FindEntitiesOfType <Player>()[0].Collider);
                    sleepDart.Position = Position;
                    sleepDart.Rotation = Rotation;
                    MonoGearGame.SpawnLevelEntity(sleepDart);
                    DartCount--;
                    var sound = MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Blowgun").CreateInstance();
                    sound.Volume = 1 * SettingsPage.Volume * SettingsPage.EffectVolume;
                    sound.Play();
                }
            }


            // Check collisions
            if (input.IsKeyDown(Keys.N))
            {
                // Noclip mode for debugging
                Position += delta * (float)gameTime.ElapsedGameTime.TotalSeconds * 10;
            }
            else
            {
                // Check collisions per axis
                var prevPos = Position;
                var deltaX  = new Vector2(delta.X, 0);
                var deltaY  = new Vector2(0, delta.Y);

                Position += deltaX * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (Collider.CollidesAny())
                {
                    // Reset if we hit anything
                    Position = prevPos;
                }
                prevPos   = Position;
                Position += deltaY * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (Collider.CollidesAny())
                {
                    // Reset if we hit anything
                    Position = prevPos;
                }
            }

            // Camera tracks player
            Camera.main.Position = new Vector2(Position.X, Position.Y);
        }
Пример #25
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;
            }
        }
Пример #26
0
        /// <summary>
        /// Loads a level from filename.
        /// </summary>
        /// <param name="resource">The level file name</param>
        /// <returns>Level</returns>
        public static Level LoadLevel(string resource)
        {
            var level = new Level();

            // Run in task because TmxMap needs IO and we can only do that in tasks
            Task.Run(() =>
            {
                // Load data
                var map      = new TmxMap(Path.Combine("Content/Levels", resource + ".tmx"));
                level.Name   = resource;
                level.Width  = map.Width;
                level.Height = map.Height;

                // Get tileset data
                var tileset      = map.Tilesets[0];
                level.TileHeight = tileset.TileHeight;
                level.TileWidth  = tileset.TileWidth;

                // Build dictionary with tile indexes and tile objects
                var tilesetDict = new Dictionary <int, Tile>();
                tilesetDict.Add(0, null);                       // 0 means no tile

                // Load texture
                var tilesetTexture = MonoGearGame.GetResource <Texture2D>(Path.Combine("Levels\\Tilesets", Path.GetFileNameWithoutExtension(tileset.Image.Source)));

                // Create tile objects from tileset data and texture
                int rows  = (int)tileset.TileCount / (int)tileset.Columns;
                bool done = false;
                for (int x = 0; x < tileset.Columns && !done; x++)
                {
                    for (int y = 0; y < rows; y++)
                    {
                        // Check if we are finished with the tiles
                        if (x + y * tileset.Columns > tileset.TileCount)
                        {
                            done = true;
                            break;
                        }

                        // Create new tile
                        Tile tile               = new Tile(tilesetTexture);
                        tile.textureRect.X      = x * tileset.TileWidth;
                        tile.textureRect.Y      = y * tileset.TileHeight;
                        tile.textureRect.Width  = tileset.TileWidth;
                        tile.textureRect.Height = tileset.TileHeight;

                        // Tile index stored for debugging
                        int index      = x + y * (int)tileset.Columns;
                        tile.tilesetId = index;

                        // Load custom tile properties
                        TmxTilesetTile tileData;
                        if (tileset.Tiles.TryGetValue(index, out tileData))
                        {
                            Debug.WriteLine("Loading custom properties for tile " + index);

                            // Load solid
                            string solid;
                            if (tileData.Properties.TryGetValue("solid", out solid))
                            {
                                if (solid == "true")
                                {
                                    tile.Walkable = false;
                                }
                                else
                                {
                                    Debug.WriteLine("Tile is not solid but has the property?");
                                }
                            }

                            // Tile walk sound
                            string sound;
                            if (tileData.Properties.TryGetValue("sound", out sound))
                            {
                                Tile.TileSound soundEnum;
                                if (Enum.TryParse(sound, out soundEnum))
                                {
                                    tile.Sound = soundEnum;
                                }
                                else
                                {
                                    Debug.WriteLine("Unknown TileSound value " + sound);
                                }
                            }
                        }

                        // Add tile to dictionary for later use
                        tilesetDict.Add(tileset.FirstGid + index, tile);
                    }
                }

                // Create combined layer tiles
                level.combinedLayer.tiles = new Tile[map.Width * map.Height];

                // Layers get stored bottom to top, we need top to bottom
                var reversedLayers = map.Layers.Reverse();
                foreach (var layer in reversedLayers)
                {
                    Debug.WriteLine("Loading layer: " + layer.Name);

                    // Add layer
                    var levelLayer   = new LevelLayer();
                    levelLayer.tiles = new Tile[map.Width * map.Height];

                    for (int tileIndex = 0; tileIndex < map.Width * map.Height; tileIndex++)
                    {
                        levelLayer.tiles[tileIndex] = tilesetDict[layer.Tiles[tileIndex].Gid];

                        // Update top layer if:
                        // level layer has a tile AND
                        // top layer is walkable but level is not OR
                        // top layer has no tile
                        if (levelLayer.tiles[tileIndex] != null &&
                            (level.combinedLayer.tiles[tileIndex] == null ||
                             (level.combinedLayer.tiles[tileIndex].Walkable && levelLayer.tiles[tileIndex].Walkable == false)))
                        {
                            level.combinedLayer.tiles[tileIndex] = levelLayer.tiles[tileIndex];
                        }
                    }

                    // Add layer to level
                    level.tileLayers.Add(levelLayer);
                }

                level.tileLayers.Reverse();             // Sort them bottom to top again

                // Load objects
                var groups = map.ObjectGroups;

                // Dictionaries used to link entities together by name
                var guardPaths      = new Dictionary <Guard, string>();
                var carPaths        = new Dictionary <Car, string>();
                var paths           = new Dictionary <string, List <Vector2> >();
                var consoles        = new Dictionary <string, PC>();
                var cameraConsole   = new Dictionary <CCTV, string>();
                var objectives      = new Dictionary <string, Objective>(); // Remains during gameplay due to some triggers needing it
                var pcWithObjective = new Dictionary <PC, string>();
                var driveObjective  = new Dictionary <DrivableVehicle, string>();

                // Loop trough all objects
                foreach (var objectGroup in groups)
                {
                    foreach (var obj in objectGroup.Objects)
                    {
                        // Small fix for spawn position with some entities
                        var halfTileOffset = -new Vector2(-level.TileWidth, level.TileHeight) / 2;

                        // Check type and create appropriate objects and entities
                        WorldEntity entity = null;
                        if (obj.Type == "spawnpoint")
                        {
                            entity          = new SpawnPoint(new Vector2((float)obj.X, (float)obj.Y) + halfTileOffset);
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);
                        }
                        else if (obj.Type == "guard")
                        {
                            entity          = new Guard();
                            entity.Position = new Vector2((float)obj.X, (float)obj.Y) + halfTileOffset;
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);

                            string path;
                            if (obj.Properties.TryGetValue("patrolpath", out path))
                            {
                                guardPaths.Add(entity as Guard, path);
                            }
                        }
                        else if (obj.Type == "car")
                        {
                            entity          = new Car(new Vector2((float)obj.X, (float)obj.Y) + halfTileOffset, null, "Sprites/Car");
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);

                            string path;
                            if (obj.Properties.TryGetValue("path", out path))
                            {
                                carPaths.Add(entity as Car, path);
                            }
                        }
                        else if (obj.Type == "bird")
                        {
                            entity = new Bird()
                            {
                                YResetValue = level.Height * level.TileHeight + 200
                            };
                            entity.Position = new Vector2((float)obj.X, (float)obj.Y) + halfTileOffset;
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);
                        }
                        else if (obj.Type == "helicopter")
                        {
                            entity          = new Helicopter();
                            entity.Position = new Vector2((float)obj.X, (float)obj.Y) + halfTileOffset;
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);

                            string objective;
                            if (obj.Properties.TryGetValue("objective", out objective))
                            {
                                driveObjective.Add(entity as DrivableVehicle, objective);
                            }
                        }
                        else if (obj.Type == "jeep")
                        {
                            entity          = new Jeep();
                            entity.Position = new Vector2((float)obj.X, (float)obj.Y) + halfTileOffset;
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);

                            string objective;
                            if (obj.Properties.TryGetValue("objective", out objective))
                            {
                                driveObjective.Add(entity as DrivableVehicle, objective);
                            }
                            string autoEnter;
                            if (obj.Properties.TryGetValue("autoenter", out autoEnter))
                            {
                                (entity as Jeep).autoenter = true;
                            }
                            string creditmode;
                            if (obj.Properties.TryGetValue("creditmode", out creditmode))
                            {
                                (entity as Jeep).creditsMode = true;
                            }
                        }
                        else if (obj.Type == "tank")
                        {
                            entity          = new Tank();
                            entity.Position = new Vector2((float)obj.X, (float)obj.Y) + halfTileOffset;
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);

                            string objective;
                            if (obj.Properties.TryGetValue("objective", out objective))
                            {
                                driveObjective.Add(entity as DrivableVehicle, objective);
                            }
                            string creditmode;
                            if (obj.Properties.TryGetValue("creditmode", out creditmode))
                            {
                                (entity as Tank).creditsMode = true;
                            }
                        }
                        else if (obj.Type == "objective")
                        {
                            string description;
                            string index;

                            if (obj.Properties.TryGetValue("description", out description))
                            {
                                if (obj.Properties.TryGetValue("index", out index))
                                {
                                    int ind       = Int32.Parse(index);
                                    bool newIndex = true;

                                    foreach (var item in objectives)
                                    {
                                        if (item.Value.Index == ind)
                                        {
                                            newIndex = false;
                                        }
                                    }
                                    if (newIndex)
                                    {
                                        entity = new Objective(description, ind);
                                        objectives.Add(obj.Name, entity as Objective);
                                    }
                                }
                            }
                        }
                        else if (obj.Type == "cctv")
                        {
                            entity          = new CCTV();
                            entity.Position = new Vector2((float)obj.X, (float)obj.Y) + halfTileOffset;
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);

                            string console;
                            if (obj.Properties.TryGetValue("pc", out console))
                            {
                                cameraConsole.Add(entity as CCTV, console);
                            }
                        }
                        else if (obj.Type == "pc")
                        {
                            entity          = new PC();
                            entity.Position = new Vector2((float)obj.X, (float)obj.Y);
                            entity.Rotation = MathHelper.ToRadians((float)obj.Rotation);

                            string objective;
                            if (obj.Properties.TryGetValue("objective", out objective))
                            {
                                pcWithObjective.Add(entity as PC, objective);
                            }

                            if (!consoles.ContainsKey(obj.Name))
                            {
                                consoles[obj.Name] = entity as PC;
                            }
                            else
                            {
                                Debug.WriteLine("Duplicate PC name " + obj.Name);
                            }
                        }
                        else if (obj.Type == "audio")
                        {
                            // Global audio
                            string audio;
                            string loop;
                            string volume;
                            bool willWork = true;

                            if (!obj.Properties.TryGetValue("source", out audio))
                            {
                                willWork = false;
                            }
                            if (!obj.Properties.TryGetValue("loop", out loop))
                            {
                                loop = "true";
                            }
                            if (!obj.Properties.TryGetValue("volume", out volume))
                            {
                                volume = "1";
                            }

                            if (willWork)
                            {
                                var soundEffect      = MonoGearGame.GetResource <SoundEffect>(audio).CreateInstance();
                                soundEffect.IsLooped = (loop == "true");
                                soundEffect.Volume   = float.Parse(volume) * SettingsPage.Volume * SettingsPage.EffectVolume;
                                AudioManager.PlayGlobal(soundEffect);
                                Debug.WriteLine("Added audio " + audio);
                                Debug.WriteLine("With Volume " + soundEffect.Volume);
                            }
                            else
                            {
                                Debug.WriteLine("Could not add audio" + audio);
                            }
                        }
                        else if (obj.Type == "audiosource")
                        {
                            // Positional audio
                            string audio;
                            string range;
                            string volume;

                            if (obj.Properties.TryGetValue("source", out audio))
                            {
                                if (!obj.Properties.TryGetValue("range", out range))
                                {
                                    range = "100";
                                }
                                if (!obj.Properties.TryGetValue("volume", out volume))
                                {
                                    volume = "1";
                                }
                                AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>(audio), float.Parse(volume), float.Parse(range), new Vector2((float)obj.X, (float)obj.Y), true);
                            }
                        }
                        else if (obj.Type == "trigger")
                        {
                            string action;
                            if (obj.Properties.TryGetValue("action", out action))
                            {
                                Action <Collider, IEnumerable <Collider>, IEnumerable <Collider> > actionL = null;
                                if (action == "nextlevel")
                                {
                                    // Action for going to a next level
                                    actionL = (self, previous, current) =>
                                    {
                                        foreach (var col in current)
                                        {
                                            var vehicle = col.Entity as DrivableVehicle;
                                            if (col.Entity.Tag == "Player" || (vehicle != null && vehicle.Entered))
                                            {
                                                if (vehicle != null && vehicle.Entered)
                                                {
                                                    vehicle.Exit();
                                                }
                                                MonoGearGame.NextLevel();
                                            }
                                        }
                                    };
                                }
                                else if (action == "alert")
                                {
                                    // Action for alerting all guards to the players position
                                    actionL = (self, previous, current) =>
                                    {
                                        foreach (var col in current)
                                        {
                                            var vehicle = col.Entity as DrivableVehicle;
                                            if ((col.Entity.Tag == "Player" || (vehicle != null && vehicle.Entered)) && !previous.Contains(col))
                                            {
                                                var guards = MonoGearGame.FindEntitiesOfType <Guard>();
                                                foreach (var guard in guards)
                                                {
                                                    guard.Alert(col.Entity.Position);
                                                }
                                            }
                                        }
                                    };
                                }
                                else if (action == "objective")
                                {
                                    // Action for clearing an objective
                                    string objective;
                                    if (obj.Properties.TryGetValue("objective", out objective))
                                    {
                                        actionL = (self, previous, current) =>
                                        {
                                            foreach (var col in current)
                                            {
                                                var vehicle = col.Entity as DrivableVehicle;
                                                if (col.Entity.Tag == "Player" || (vehicle != null && vehicle.Entered))
                                                {
                                                    Objective ob;
                                                    if (objectives.TryGetValue(objective, out ob))
                                                    {
                                                        GameUI.CompleteObjective(ob);
                                                    }
                                                    else
                                                    {
                                                        Debug.WriteLine("Trgger could not find objective: " + objectives);
                                                    }
                                                }
                                            }
                                        };
                                    }
                                }
                                else
                                {
                                    Debug.WriteLine("Trigger " + obj.Name + " with unknown action " + action);
                                }

                                if (actionL != null)
                                {
                                    var size = new Vector2((float)obj.Width, (float)obj.Height);
                                    entity   = new WorldBoxTrigger(new Vector2((float)obj.X, (float)obj.Y) + size / 2,
                                                                   size,
                                                                   actionL);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("Trigger " + obj.Name + " with no action!");
                            }
                        }
                        else if (obj.Type == "path")
                        {
                            // A patrol path
                            if (!paths.ContainsKey(obj.Name))
                            {
                                paths[obj.Name] = new List <Vector2>();
                                foreach (var point in obj.Points)
                                {
                                    paths[obj.Name].Add(new Vector2((float)point.X + (float)obj.X, (float)point.Y + (float)obj.Y));
                                }
                            }
                            else
                            {
                                Debug.WriteLine("Duplicate path name " + obj.Name);
                            }
                        }

                        if (entity != null)
                        {
                            // Set tag
                            string tag;
                            if (obj.Properties.TryGetValue("tag", out tag))
                            {
                                entity.Tag = tag;
                            }

                            level.AddEntity(entity);
                        }
                    }
                }

                // Assing guard patrol paths
                foreach (var guardPath in guardPaths)
                {
                    List <Vector2> path;
                    if (paths.TryGetValue(guardPath.Value, out path))
                    {
                        guardPath.Key.PatrolPath = path;
                    }
                    else
                    {
                        Debug.WriteLine("Guard requested unknown path " + guardPath.Value);
                    }
                }

                // Assing car paths
                foreach (var carPath in carPaths)
                {
                    List <Vector2> path;
                    if (paths.TryGetValue(carPath.Value, out path))
                    {
                        carPath.Key.SetPath(path);
                    }
                    else
                    {
                        Debug.WriteLine("Car requested unknown path " + carPath.Value);
                    }
                }

                // Assing PC/CCTV
                foreach (var kvPair in cameraConsole)
                {
                    PC pc;
                    if (consoles.TryGetValue(kvPair.Value, out pc))
                    {
                        pc.AddCCTV(kvPair.Key);
                    }
                    else
                    {
                        Debug.WriteLine("CCTV requested unknown PC " + kvPair.Value);
                    }
                }

                // Assing PC/Objective
                foreach (var pc in pcWithObjective)
                {
                    Objective ob;
                    if (objectives.TryGetValue(pc.Value, out ob))
                    {
                        pc.Key.Objective = ob;
                    }
                    else
                    {
                        Debug.WriteLine("PC could not find objective: " + pc.Value);
                    }
                }

                // Assing drive/Objective
                foreach (var drive in driveObjective)
                {
                    Objective ob;
                    if (objectives.TryGetValue(drive.Value, out ob))
                    {
                        drive.Key.objective = ob;
                    }
                    else
                    {
                        Debug.WriteLine("PC could not find objective: " + drive.Value);
                    }
                }
            }).Wait();
            return(level);
        }
Пример #27
0
 /// <summary>
 /// Method that executes when the level is loaded.
 /// </summary>
 public override void OnLevelLoaded()
 {
     base.OnLevelLoaded();
     boatSound      = AudioManager.AddPositionalAudio(MonoGearGame.GetResource <SoundEffect>("Audio/AudioFX/Car_sound"), 0, 300, Position, true);
     destoyedSprite = MonoGearGame.GetResource <Texture2D>("Sprites/BrokenWillys");
 }