/// <summary> /// Test1: Minigun playback simulation from FSM. /// </summary> public void TestMinigunPlayback() { sndStart.Play(); while (sndStart.Playing()) { } sndFire.Play(); while (sndFire.Playing()) { } sndStop.Play(); while (sndStop.Playing()) { } sndStart.Play(); while (sndStart.Playing()) { } sndFire.Play(); while (sndFire.Playing()) { } // No more ammo sndAmmo.Play(); while (sndAmmo.Playing()) { } // Stop minigun sndStop.Play(); while (sndStop.Playing()) { } // Reload ammo sndReload.Play(); while (sndReload.Playing()) { } // More fun .... sndStart.Play(); while (sndStart.Playing()) { } sndFire.Play(); while (sndFire.Playing()) { } sndStop.Play(); while (sndStop.Playing()) { } }
/// <summary> /// Update the audio effects. /// </summary> private void UpdateAudio() { if (modelAnimationPart != null) { if (!meshSoundEfx.Playing()) { meshSoundEfx.Play(); } } }
/// <summary> /// Update the sound engine playbacks. /// </summary> public void Update() { // Refresh the music box state machine. if (currentStatus == MusicBoxStatus.Play && currentTrack.Playing() == false) { MusicBox(MusicBoxStatus.Play); } // Refresh all the loopable sounds. for (int i = 0; i < sounds.Count; i++) { if (sounds[i].Loop) { if (!sounds[i].Playing()) { sounds[i].Play(); } } } // Update the main engine. engine.Update(); }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { base.Update(gameTime); //GraphicalConsole.GetSingleton(game).WriteLine("" + (device.IsConnected ? true : false), 1); if (hasSpaceMouse) { int eps = 20;//30; mouseY = 50 * (float)gameTime.ElapsedGameTime.TotalSeconds * ((float)device.Sensor.Rotation.X * eps); mouseX = 50 * (float)gameTime.ElapsedGameTime.TotalSeconds * ((float)device.Sensor.Rotation.Z * eps); } else { mouseX = 50 * (float)gameTime.ElapsedGameTime.TotalSeconds * game.Input.MouseMovement.X; mouseY = 50 * (float)gameTime.ElapsedGameTime.TotalSeconds * game.Input.MouseMovement.Y; } #region Finsh if time remaining is zero // Temp fix because we have no finish yet. if (remainingTime > 0) { if (Helper.WaitFor("RemainingTime", TimeSpan.FromSeconds(1))) { remainingTime--; Helper.ResetWait("RemainingTime"); } // Play the hurry up sound if (remainingTime <= 10) { if (!hurryUpEfx.Playing()) { if (Helper.Lock("Hurry Up Intercom", TimeSpan.FromSeconds(10))) { Intercom.HurryUp(); } hurryUpEfx.Loop = true; hurryUpEfx.Play(); } } } else { hurryUpEfx.Loop = false; hurryUpEfx.Stop(); hurryUpEfx.Dispose(); game.Sounds.MusicBox(MusicBoxStatus.Pause); if (gameOverEfx.Playing() == false) { gameOverEfx.Play(); } if (Helper.WaitFor("FlagDisplayTime", TimeSpan.FromSeconds(4))) { game.Sounds.MusicBox(MusicBoxStatus.Play); Helper.ResetWait("FlagDisplayTime"); Explode(); game.GameStates.Gameplayed = true; } Finish(); return; } #endregion Finsh if time remaining is zero #region Game over and respawn time = gameTime; if (gameOver) { if (Helper.WaitFor("PlayerGameOver", TimeSpan.FromSeconds(4))) { Helper.ResetWait("PlayerGameOver"); this.Enabled = false; game.GameStates.Gameplayed = true; } //Finish(); return; } if (respawn) { if (Helper.WaitFor("PlayerRespawn", TimeSpan.FromSeconds(4))) { //Reset Helpers respawn = false; // (REPAWN NOW!) //canyonPosition++; health = 100; shield = 50; Model.AfterBurnerLength = minBooster; SetPositionInCanyon(canyonPosition); game.GameStates.Hud.DisplayScrollingText(lifes + " Lifes remaining!", gameTime); Visible = true; Weapons.WeaponsVisible = true; } else { return; } } #endregion Game over and respawn #region Speed management if (game.Input.IsKeyDown("Player1.Up") && fuel > 0) // do we have enough fuel ? { // Booster temperature control if (Helper.WaitFor("BoosterHeat", TimeSpan.FromSeconds(0.5f))) { if (boosterHeat == maxBoosterHeat) { if (Helper.WaitFor("Overheat", TimeSpan.FromSeconds(3))) { Helper.ResetWait("Overheat"); Explode(); } } else { boosterHeat += boosterHeatGap; } Helper.ResetWait("BoosterHeat"); } decay = 0; if (speed < MaxSpeed) { speed += SpeedGap; } if (Model.AfterBurnerLength < maxBooster) { Model.AfterBurnerLength += boosterGap; } // Fuel Check fuel -= (int)((speed / (MaxSpeed / 100)) * 0.02f); } else { // Booster temperature control if (Helper.WaitFor("BoosterHeat", TimeSpan.FromSeconds(2))) { if (boosterHeat > minBoosterHeat) { boosterHeat -= boosterHeatGap; } Helper.ResetWait("BoosterHeat"); } if (game.Input.IsKeyDown("Player1.Down")) //if (device.Sensor.Rotation.Z > 0) { if (speed > MinSpeed) { speed -= SpeedGap; } if (Model.AfterBurnerLength > minBooster) { Model.AfterBurnerLength -= boosterGap; } } else { if (speed > MinSpeed) { if (decay < MaxDecay) { decay += 0.05f; } speed -= (int)decay; if (Model.AfterBurnerLength > minBooster) { Model.AfterBurnerLength -= boosterGap; } } } } // Check for a negative fuel value and correct it: if (fuel < 0) { fuel = 0; } // Calculate new velocity Velocity = Vector3.Transform(new Vector3(0, 0, -speed), LocalRotation); #endregion Speed management #region Set the flight distance if (Helper.WaitFor("Distance", TimeSpan.FromSeconds(0.001f))) { distance += (double)(speed * 0.0006f); Helper.ResetWait("Distance"); } #endregion Set the flight distance #region Compute banking and drift // Get direction for driftig Vector3 direction = Velocity; Vector3 translationDirection = Vector3.Cross(this.UP, direction); // Handle inputs and compute drift if (game.Input.IsKeyDown("Player1.Left")) { translationDirection *= translationGap; Velocity += translationDirection; angHorz += driftFactor; } if (game.Input.IsKeyDown("Player1.Right")) { translationDirection *= -translationGap; Velocity += translationDirection; angHorz -= DriftFactor; } // Compute banking angle angHorz += -(float)Math.Atan(mouseX) * BankingFactor; angHorz -= angHorz * AutoLevel; angVert += -(float)Math.Atan(mouseY) * BankingFactor; angVert -= angVert * AutoLevel; angRoll += angHorz; angRoll *= RollFactor; #endregion Compute banking and drift #region Update model and camera view if (firstTime == 0) { // Banking Quaternion banking = Quaternion.CreateFromYawPitchRoll(angHorz, angVert, angRoll); // Rotation Vector3 up = Vector3.Transform(UP, Quaternion.Conjugate(LocalRotation)); Quaternion horizontal = Quaternion.CreateFromAxisAngle(up, MouseIntensity * mouseX); Quaternion vertical = Quaternion.CreateFromAxisAngle(RIGHT, MouseIntensity * mouseY); Vector3 directionTemp = Vector3.Transform(direction, Matrix.CreateFromQuaternion(Quaternion.Concatenate(horizontal, banking))); if (IsFlightDirectionOK(directionTemp)) { this.Model.LocalRotation = banking; } else { horizontal = Quaternion.CreateFromAxisAngle(up, 0); vertical = Quaternion.CreateFromAxisAngle(RIGHT, 0); } Rotate(Quaternion.Concatenate(vertical, horizontal)); } else { // Banking this.Model.LocalRotation = Quaternion.CreateFromYawPitchRoll((angHorzTemp + angHorz) / 2, (angVertTemp + angVert) / 2, (angRollTemp + angRoll) / 2); firstTime--; LocalRotation = Quaternion.Identity; } #endregion Update model and camera view #region camera fov for boost // interpolate camera fov between 90° and 120° depending on current speed cam.Fov = 90 + 30 * (Math.Max(0, speed - minSpeed) / (maxSpeed - minSpeed)); #endregion // Update others UpdatePosition(); UpdateCameraZoom(); if (!isFinish) { if (hasSpaceMouse) { Weapons.UpdatePlayerWeapons3D(gameTime, device.Keyboard); } else { Weapons.UpdatePlayerWeapons(gameTime); } } UpdateAudio(); AngularVelocity = Vector3.Zero; #region Pre-Frame Buffer angHorzTemp = angHorz; angRollTemp = angRoll; angVertTemp = angVert; #endregion Pre-Frame Buffer }
/// <summary> /// Called when the DrawableGameComponent needs to be drawn. Override this method with component-specific drawing code. /// </summary> /// <param name="gameTime">Time passed since the last call to Microsoft.Xna.Framework.DrawableGameComponent.Draw(Microsoft.Xna.Framework.GameTime).</param> public override void Draw(GameTime gameTime) { if (spriteBatch != null) { spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState, Matrix.CreateScale(game.Graphics.ScreenWidth, game.Graphics.ScreenHeight, 1)); // DRAW HUD2 - BACK LAYER spriteBatch.Draw(hudBack, new Rectangle(0, 0, 1, 1), Color.White); spriteBatch.End(); spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Texture, SaveStateMode.None); // HEALTH, SHIELD DrawVerticalBarAt(hudHealthBar, new Vector2(0.027f, 0.829f), game.World.Players[0].Health, 100); DrawVerticalBarAt(hudShieldBar, new Vector2(0.09f, 0.829f), game.World.Players[0].Shield, 250); // BOOST DrawHorizontalBarAt(hudBoostBar, new Vector2(0.144f, 0.932f), game.World.Players[0].BoosterHeat, 100); // FUEL DrawVerticalBarAt(hudFuelBar, new Vector2(0.007f, 0.128f), (int)((Player2)game.World.Players[0]).Fuel, (int)((Player2)game.World.Players[0]).MaxFuel); #region HUD-Controls // DRAW CONTROLS foreach (HudControl x in controls.Values) { HudTextControl text = x as HudTextControl; HudSpriteControl sprite = x as HudSpriteControl; Hud3DControl model = x as Hud3DControl; HudBarControl bar = x as HudBarControl; if (text != null) { text.Draw(spriteBatch); } if (sprite != null) { sprite.Draw(spriteBatch); } if (model != null) { model.Draw(spriteBatch); } if (bar != null) { bar.Draw(spriteBatch, font); } } foreach (HudTextControl x in this.scrollingText) { if (x != null) { x.Draw(spriteBatch); } } spriteBatch.End(); #endregion spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Texture, SaveStateMode.SaveState, Matrix.CreateScale(game.Graphics.ScreenWidth, game.Graphics.ScreenHeight, 1)); // DRAW HUD2 - FRONT LAYER spriteBatch.Draw(hudFront, new Rectangle(0, 0, 1, 1), Color.White); if (currentCrossHair != null) { float scale = 4f; Vector2 crossHairPosition = new Vector2( 0.5f - ((currentCrossHair.Width) * (0.05f * scale / game.Graphics.ScreenWidth)), 0.55f - ((currentCrossHair.Height) * (0.05f * scale / game.Graphics.ScreenHeight))); spriteBatch.Draw(currentCrossHair, crossHairPosition, new Rectangle(0, 0, currentCrossHair.Width, currentCrossHair.Height), Color.White, 0, new Vector2(0.5f, 0.5f), new Vector2(0.1f * scale / game.Graphics.ScreenWidth, 0.1f * scale / game.Graphics.ScreenHeight), SpriteEffects.None, 0.5f); } if (((Player2)game.World.Players[0]).Weapons.PrimaryWeapon != null) { Texture2D icon = ((Player2)game.World.Players[0]).Weapons.PrimaryWeapon.Icon; spriteBatch.Draw(icon, new Vector2(0.703f, 0.924f), new Rectangle(0, 0, icon.Width, icon.Height), Color.White, 0, new Vector2(0.5f, 0.5f), new Vector2(1f / game.Graphics.ScreenWidth, 1f / game.Graphics.ScreenHeight), SpriteEffects.None, 0.5f); } if (((Player2)game.World.Players[0]).Weapons.SecondaryWeapon != null) { Texture2D icon = ((Player2)game.World.Players[0]).Weapons.SecondaryWeapon.Icon; spriteBatch.Draw(icon, new Vector2(0.818f, 0.924f), new Rectangle(0, 0, icon.Width, icon.Height), Color.White, 0, new Vector2(0.5f, 0.5f), new Vector2(1f / game.Graphics.ScreenWidth, 1f / game.Graphics.ScreenHeight), SpriteEffects.None, 0.5f); } #region BOOSTER-WARNING if (showWarning) { if (!alert.Playing()) { alert.Play(); } warningGlowCount--; if (warningGlowCount <= 0) { warningFpsCount++; } if (warningFpsCount > 8) { warningVisible = !warningVisible; warningFpsCount = 0; warningGlowCount = 3; } if (warningVisible) { if (warningGlowCount > 0) { spriteBatch.Draw(hudBoosterWarning, new Rectangle(0, 0, 1, 1), new Color(255, 255, 255, (byte)(255 / warningGlowCount))); } else { spriteBatch.Draw(hudBoosterWarning, new Rectangle(0, 0, 1, 1), new Color(255, 255, 255, 255)); } } } else { alert.Stop(); } #endregion spriteBatch.End(); } }
private const float MaxHorzAngleDiff = (float)Math.PI / 6; // 30° /// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { base.Update(gameTime); float steuerVert = 0; float steuerHorz = 0; bool booster = false; bool firePrimary = false; bool fireSecondary = false; if (game.GameStates.InputFocus == game.World && health > 0) { if (game.Input.IsKeyDown("Player" + playerID + ".Up")) { steuerVert = -MaxMove; } if (game.Input.IsKeyDown("Player" + playerID + ".Down")) { steuerVert = MaxMove; } if (game.Input.IsKeyDown("Player" + playerID + ".Left")) { steuerHorz = MaxMove; } if (game.Input.IsKeyDown("Player" + playerID + ".Right")) { steuerHorz = -MaxMove; } booster = game.Input.IsKeyDown("Player" + playerID + ".Boost"); if (game.Input.IsKeyDown("Player" + playerID + ".PrimaryFire")) { firePrimary = true; } if (game.Input.IsKeyDown("Player" + playerID + ".SecondaryFire")) { fireSecondary = true; } if (game.Input.HasKeyJustBeenPressed("Player" + playerID + ".PrimarySwitchUp")) { Weapons.SwitchUp(true); } if (game.Input.HasKeyJustBeenPressed("Player" + playerID + ".PrimarySwitchDown")) { Weapons.SwitchDown(true); } if (game.Input.HasKeyJustBeenPressed("Player" + playerID + ".SecondarySwitchUp")) { Weapons.SwitchUp(false); } if (game.Input.HasKeyJustBeenPressed("Player" + playerID + ".SecondarySwitchDown")) { Weapons.SwitchDown(false); } Vector2 mm = game.Input.MouseMovement; WeaponX += mm.X / 500f; WeaponY += mm.Y / 500f; if (WeaponX < 0) { WeaponX = 0; } if (WeaponY < 0) { WeaponY = 0; } if (WeaponX > 1) { WeaponX = 1; } if (WeaponY > 1) { WeaponY = 1; } } if (booster) { speed = speed * 0.95f + BoostSpeed * 0.05f; SpeedF = SpeedF * 0.95f + 1 * 0.05f; } else { speed = speed * 0.95f + NormSpeed * 0.05f; SpeedF = SpeedF * 0.95f + 0 * 0.05f; } angHorz += steuerHorz; angVert += steuerVert; angRoll += steuerHorz; angRoll *= 0.95f; // Amounts der Canyon Teile bestimmen //TODO: Richard - Fix Crash wenn canyonPosition = 99: +1 -> out of range // System.IndexOutOfRangeException wurde nicht behandelt. //Message="Der Index war außerhalb des Arraybereichs." //Source="Canyon Shooter" //StackTrace: // bei CanyonShooter.GameClasses.Player.Update(GameTime gameTime) in C:\DATEN\WORK\CanyonShooter\svn\CS_XNA2.0\CanyonShooter\GameClasses\Player\Player.cs:Zeile 269. // bei Microsoft.Xna.Framework.Game.Update(GameTime gameTime) // bei CanyonShooter.CanyonShooterGame.Update(GameTime gameTime) in C:\DATEN\WORK\CanyonShooter\svn\CS_XNA2.0\CanyonShooter\CanyonShooterGame.cs:Zeile 155. // bei Microsoft.Xna.Framework.Game.Tick() // bei Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e) // bei Microsoft.Xna.Framework.GameHost.OnIdle() // bei Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e) // bei System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef) // bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) // bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) // bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) // bei System.Windows.Forms.Application.Run(Form mainForm) // bei Microsoft.Xna.Framework.WindowsGameHost.Run() // bei Microsoft.Xna.Framework.Game.Run() // bei CanyonShooter.Program.Main(String[] args) in C:\DATEN\WORK\CanyonShooter\svn\CS_XNA2.0\CanyonShooter\Program.cs:Zeile 12. Vector2 tmp2 = new Vector2(game.World.Level.Cache[canyonPosition].ADir.Z, game.World.Level.Cache[canyonPosition].ADir.X); Vector2 tmp3 = new Vector2(game.World.Level.Cache[canyonPosition + 1].ADir.Z, game.World.Level.Cache[canyonPosition + 1].ADir.X); float n1, n2, n3; game.World.Level.GetSegmentAmounts(LocalPosition, canyonPosition, out n1, out n2, out n3); Vector2 tmp = tmp2 * n2 + tmp3 * n3; float angHorzCanyon; float angVertCanyon; if (tmp.X == 0) { angHorzCanyon = 0; } else if (tmp.X > 0) { angHorzCanyon = (float)Math.PI + (float)Math.Atan(tmp.Y / tmp.X); } else { angHorzCanyon = (float)Math.Atan(tmp.Y / tmp.X); } angVertCanyon = 0; // Bewegungsbereich maximal einschränken, jedoch nur wenn er nicht gerade ausgeschöpft wird if (angHorz > angHorzMin) { angHorzMin = angHorz; } if (angHorz < angHorzMax) { angHorzMax = angHorz; } // Bewegungsbereich je nach Canyon Beschaffenheit ausdehnen if (angHorzMin > angHorzCanyon - MaxHorzAngleDiff) { angHorzMin = angHorzCanyon - MaxHorzAngleDiff; } if (angHorzMax < angHorzCanyon + MaxHorzAngleDiff) { angHorzMax = angHorzCanyon + MaxHorzAngleDiff; } // Wenn wir über dem Bewegungsbereich sind, dann korrigieren if (angHorz < angHorzMin) { angHorz = (angHorz - angHorzMin) * 0.90f + angHorzMin; } if (angHorz > angHorzMax) { angHorz = (angHorz - angHorzMax) * 0.90f + angHorzMax; } //angHorz *= 0.95f; angVert *= 0.97f; //if (health > 0) { LocalRotation = Quaternion.CreateFromYawPitchRoll(angHorz, angVert, angRoll); //Move(Vector3.Transform(new Vector3(0, 0, -Speed*2), LocalRotation)); Velocity = Vector3.Transform(new Vector3(0, 0, -speed), LocalRotation); //Velocity = game.World.Level.Cache[canyonPosition].ADir; } /*else * { * Velocity = new Vector3(); * }*/ UpdatePosition(); // Bounding Box Test //Vector2 Pfadabstand = game.World.Level.GetDistanceToSegment(LocalPosition, canyonPosition); //if (Math.Abs(Pfadabstand.X) > Level.CanyonSpanFactor || Math.Abs(Pfadabstand.Y) > Level.CanyonSpanFactor) //{ // health = 0; //} // Kameraeinstellungen angHorzCamera = angHorzCamera * 0.97f + angHorzCanyon * 0.03f; angVertCamera = angVertCamera * 0.97f + angVertCanyon * 0.03f; Quaternion camq = Quaternion.CreateFromYawPitchRoll(angHorzCamera, 0.0f, 0.0f); camera.LocalPosition = LocalPosition + Vector3.Transform( new Vector3(0, 12 * 2 / 1.7f * SpeedF + 12 * 2 * (1 - SpeedF), 30 * 2 / 1.7f * SpeedF + 30 * 2 * (1 - SpeedF)), camq); camera.LocalRotation = camq; camera.Fov = 130 * SpeedF + 90 * (1 - SpeedF); // Lokale Waffenrotation Quaternion WR = Quaternion.CreateFromYawPitchRoll(-(WeaponX - 0.5f), -(WeaponY - 0.5f), 0); Weapons.PrimaryWeapon.Parent.LocalRotation = WR; //Weapons.SecondaryWeapon.Parent.LocalRotation = WR; // Globale Waffenrotation WR = Quaternion.Concatenate(WR, camq); Vector3 WF = Vector3.Transform(new Vector3(0, 0, -speed), WR); // Waffenaiming Weapons.PrimaryWeapon.AimAt(WF); //Weapons.SecondaryWeapon.AimAt(WF); // Waffenfeuer if (firePrimary) { Weapons.PrimaryWeapon.BeginFire(); } else { Weapons.PrimaryWeapon.EndFire(); } if (fireSecondary) { //Weapons.SecondaryWeapon.BeginFire(); } else { //Weapons.SecondaryWeapon.EndFire(); } // For audio and mesh animation by M.R. if (modelAnimationPart != null) { if (!meshSoundEfx.Playing()) { meshSoundEfx.Play(); } } // ------------------------------------- }