/// <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); // Keep moving the missile forward var pos = Position; var delta = Forward * Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Move(delta); // If not exploded, kee[ counting down if (boemInSec > 0) { boemInSec -= (float)gameTime.ElapsedGameTime.TotalSeconds; } // If we hit anything or the timer runs out, EXPLODE if (Collider.CollidesAny() || boemInSec <= 0) { Position = pos; Speed = 0.0f; MonoGearGame.SpawnLevelEntity(new Explosion() { Position = this.Position }); MonoGearGame.DestroyEntity(this); } }
/// <summary> /// Method called every frame /// </summary> /// <param name="input">Input</param> /// <param name="gameTime">GameTime</param> public override void Update(Input input, GameTime gameTime) { if (creditsMode) { //One time changes if (MonoGearGame.FindEntitiesOfType <GameUI>()[0].Enabled) { // Disable UI, spawn credits and set other things MonoGearGame.FindEntitiesOfType <GameUI>()[0].Enabled = false; MonoGearGame.FindEntitiesOfType <GameUI>()[0].Visible = false; MonoGearGame.SpawnLevelEntity(new Credits()); instanceTexture = playerSprite; Health = 1; } // Move right on the screen Position += Speed * new Vector2(1, 0) * (float)gameTime.ElapsedGameTime.TotalSeconds; Rotation = MathHelper.ToRadians(90); forwardSpeed = Speed; jeepSound.Volume = 0; // Required for tank range detection player.Position = Position; // Camera tracking if (Position.X < 28000) { Camera.main.Position = Position; } return; } // Handles driving and input base.Update(input, gameTime); // Speed based volume float minVolume = 0.75f; if (Entered) { if (instanceTexture != playerSprite) { instanceTexture = playerSprite; } jeepSound.Volume = minVolume + (1.0f - minVolume) * Math.Abs(forwardSpeed) / Speed; } else { if (instanceTexture != jeepSprite) { instanceTexture = jeepSprite; } jeepSound.Volume = minVolume; } jeepSound.Position = Position; }
/// <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; } }
/// <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(); }
public override void Destroy() { // Throw the player out if (Entered) { Exit(); } instanceTexture = destroyedSprite; Enabled = false; destroyed = true; AudioManager.StopPositional(jeepSound); if (creditsMode) { // Car has exploded, show restart screen var go = new GameOver(); MonoGearGame.SpawnLevelEntity(go); Exit(); go.EnableGameOver(); player.Enabled = false; // Ensure camera doesn't snap to player next frame player.Visible = false; // Ensure player remains invisible } }
/// <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; } }
/// <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(); } }
/// <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); }