/* * AstroGameManager.cs * Authors: August Zinsser, Sriharsha Matta * * Copyright Matthew Belmonte 2007 */ #region Using Statements using System; using System.Diagnostics; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using tAC_Engine; using Pina3D.Particles; #endregion namespace Astropolis { /// /// This class is the manager for all specific Colony games. This class's methods are automatically /// called when necessary, but the MainGame delegates those tasks by calling functions from ColonyGame /// or MiniGames. /// public class AstroGameManager : GenericGameManager { // Regular Non-Config Global Variables private bool mOutputPanelKeysAreUp = true; // If all keys necessary to display the parallel port communicator panel are up or down private ScoreSummary mScoreSheet; // The score sheet to display after minigames // Meteor Madness Non-Config Globals private int mNumDots = 0; // Number of dots that are being displayed in the dot phase of meteor madness private float mDotCoherencePercentage = 0F; // Holds the current coherence percentage of dots in the dot phase of meteor madness private float mDotShields = 1F; // Shield percentage of the ship in meteor madness private float mMeteorCameraFocalLength = .2F; // Focal length of the camera in meteor madness private float mDotWeaponCooldown = .25F; // Initial cooldown for the player's lasers in the shooter phase of meteor madness // Meteor Madness Config Globals private float mDotDiameter; // The diameter of the dots in the dot phase (essentially arbitrary units) private float mDotSpeed; // '' speed private float mDotLifeSpan; // '' lifespan private float mDotWaitToReset = 0f; // Time before a dot trial resets coherence after a user response /// /// Number of dots for meteor madness /// public int NumDots { set { mNumDots = value; } get { return mNumDots; } } /// /// Diameter of Meteor Madness dots in screen percentage at mid-depth /// public float DotDiameter { set { mDotDiameter = value; } get { return mDotDiameter; } } /// /// Speed that the dots move in the dot phase of meteor madness (arbitrary units) /// public float DotSpeed { set { mDotSpeed = value; } get { return mDotSpeed; } } /// /// Lifespan (in seconds) of the dots in the dot phase of meteor madness /// public float DotLifeSpan { set { mDotLifeSpan = value; } get { return mDotLifeSpan; } } /// /// Shield percentage of the ship in meteor madness /// public float DotShields { set { mDotShields = value; } get { return mDotShields; } } /// /// Current cooldown for the player's lasers in the shooter phase of meteor madness /// public float DotWeaponCooldown { set { mDotWeaponCooldown = value; } get { return mDotWeaponCooldown; } } /// /// The current coherence percentage of dots in the dot phase of meteor madness /// public float DotCoherencePercentage { set { mDotCoherencePercentage = value; } get { return mDotCoherencePercentage; } } /// /// Time before a dot trial resets coherence after a user response /// public float DotCoherenceRefreshDelay { set { mDotWaitToReset = value; } get { return mDotWaitToReset; } } /// /// Focal length of the camera in meteor madness /// public float MeteorCameraFocalLength { set { mMeteorCameraFocalLength = value; } get { return mMeteorCameraFocalLength; } } // Lua Accessors [LuaCallback("SetDotDiameter")] public void SetDotDiameter(float value) { DotDiameter = value; } [LuaCallback("SetDotSpeed")] public void SetDotSpeed(float value) { DotSpeed = value; } [LuaCallback("SetDotLifeSpan")] public void SetDotLifeSpan(float value) { DotLifeSpan = value; } [LuaCallback("SetDotWaitToReset")] public void SetDotCoherenceRefreshDelay(float value) { DotCoherenceRefreshDelay = value; } /// /// Default constructor /// public AstroGameManager() : base() { } /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() { base.Initialize(); // Initialize the score card mScoreSheet = new ScoreSummary(); // Register Lua Callbacks LuaHelper.RegisterLuaCallbacks(this); mLastGameTimeSnapshot = new GameTime(); Logger.LogCode(Logger.ExperimentalCode.SVN_REVISION, Game.Astropolis.SubVersion.Revision); Logger.FlushLog(); } /// /// Displays the given scorecard /// public void ShowScore(AstroScoreCard score, bool success, string resultsMessage) { mScoreSheet.DisplayScores(score, success, resultsMessage); } /// /// A wrapper for ColonyBaseApplication.SwitchMode(...) to for the Lua VM /// /// [LuaCallback("SwitchMode")] public static void LuaSwitchMode(string mode) { switch (mode.ToLower()) { case "modeselector": AstroBaseApplication.SwitchMode(AstroBaseApplication.Modes.ModeSelector); break; case "colony": AstroBaseApplication.SwitchMode(AstroBaseApplication.Modes.Colony); break; case "meteormadness": AstroBaseApplication.SwitchMode(AstroBaseApplication.Modes.MeteorMadness); break; case "hackerhavok": AstroBaseApplication.SwitchMode(AstroBaseApplication.Modes.HackerHavoc); break; default: throw new Exception("Unrecognized mode passed to SwitchMode(...). This was probably called from a Lua file)"); } } protected override void LoadGraphicsContent(bool loadAllContent) { AstroBaseApplication.MiniGame.LoadGraphicsContent(loadAllContent); base.LoadGraphicsContent(loadAllContent); } /// /// Processes and records input every tick, but only updates game logic /// at the rate of LogicUpdateTargetTime /// /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { base.Update(gameTime); if (AstroBaseApplication.OutputPanel.ParallellPortPresent) { AstroBaseApplication.OutputPanel.Update(gameTime); } // Decide whether this is just an input update or a full-fledged logic update if (mLogicUpdate) { // Bring up the output panel if (InputState.IsKeyDown(Keys.O) && (InputState.IsKeyDown(Keys.LeftAlt) || InputState.IsKeyDown(Keys.RightAlt)) && (InputState.IsKeyDown(Keys.LeftControl) || InputState.IsKeyDown(Keys.RightControl)) && mOutputPanelKeysAreUp) { if (AstroBaseApplication.OutputPanel.Visible == false) AstroBaseApplication.OutputPanel.Show(); else AstroBaseApplication.OutputPanel.Hide(); mOutputPanelKeysAreUp = false; } if (InputState.IsKeyUp(Keys.O)) mOutputPanelKeysAreUp = true; //Pause Game if (!(AstroBaseApplication.GameManager.PauseGames) && InputState.WasKeyUp(Keys.Escape) && InputState.IsKeyDown(Keys.Escape)) { AstroBaseApplication.GameManager.PauseGames = true; Pina3D.Particles.Sparx.Paused = true; HUD.ShowMouseCursor = true; HUD.ShowPauseMenu = true; Logger.LogCode(Logger.ExperimentalCode.APP_Pause); } //Unpause Game else if (InputState.WasKeyUp(Keys.Escape) && InputState.IsKeyDown(Keys.Escape)) { //if (InputState.IsKeyUp(Keys.T)) { AstroBaseApplication.GameManager.PauseGames = false; Pina3D.Particles.Sparx.Paused = false; HUD.ShowMouseCursor = false; HUD.ShowPauseMenu = false; Logger.LogCode(Logger.ExperimentalCode.APP_UnPause); } } // Update the (possibly invisible) scoresheet mScoreSheet.Update(); // Only update minigames if one has been assigned and the game manager hasn't paused them if (!mPauseGames && AstroBaseApplication.MiniGame != null) AstroBaseApplication.MiniGame.Update(); // Update the maingame if (!mPauseGames && AstroBaseApplication.MiniGame == null) { AstroBaseApplication.Game.Update(); } } } /// /// Draw the current game /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { // Clear the buffer mGraphics.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0); // Only draw the minigames if one is selected and the game manager hasn't paused games //if (!mPauseGames && AstroBaseApplication.MiniGame != null) //Draw the minigame even when the game manager has paused games if (AstroBaseApplication.MiniGame != null) { // Open a spritebatch to draw whichever game is currently running //mSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.SaveState); // TODO: Create a sperate non-sorted spritebatch for opaque objects // TOOD: Create an Additive-blended spritebatch // Draw the minigame to that spritebatch AstroBaseApplication.MiniGame.Draw(); // Draw alpha-blended particles //ParticleEngine.DrawAlphaBlend(gameTime, mSpriteBatch); // Close that spritebatch // TODO: Move this close down and close all SB's at the same time //mSpriteBatch.End(); // Draw additive-blended particles. This must be done on a new spritebatch //mSpriteBatch.Begin(SpriteBlendMode.Additive); //ParticleEngine.DrawAdditive(gameTime, mSpriteBatch); //mSpriteBatch.End(); } if (AstroBaseApplication.MiniGame == null) { AstroBaseApplication.Game.Draw(); } // Draw the scoresheet on top of everything so far (if applicable) // TODO: Make the scoresheet as a HUD element, eliminating the need for this call mScoreSheet.Draw(mSpriteBatch); // Draw Generic stuff last so that it ends up on top of game stuff base.Draw(gameTime); } } }