/* * Hackerhavoc.cs * Authors: Brian Chesbrough * * Copyright Matthew Belmonte 2007 */ using System; using System.Collections.Generic; using System.Text; 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 Pina3D; using Pina3D.Particles; using tAC_Engine; namespace Astropolis { class HackerHavocOld : MiniGame { /// /// Hacker Havoc /// //variables private enum GameState { Menu, Tutorial, NavagationMode, HackerMode, Paused } private enum GameTurnold { playerTurn, friendlyTurn, enemyTurn } private GameState mGameState; // The state of the minigame private GameWorld mGameWorld; // Defines a basic 3D coordinate system, game entities private bool mInitialized; // Flag for reinitializing between phases private bool mAllIsLost; // True when the player has lost, signalling that the game can still update logic even though the player is dead. This is mostly aesthetic private Random mRandom = new Random(); // Basic random number generator private PlayerShip mPlayerShip; // The ship that the player controls private Entity mMenuBackground; // The background image for the main menu private Button mStartButton; // For the main menu private Button mTutorialButton; // '' private Button mBackButton; // '' private Button mPassTurnButton; // Button to pass turn in navagation phase //private GameTur mCurrentTurn; // What turn is active private float mPlayerMeterMax; // What the players movement meter is set to when its full private Planet mPlanet1; //temp planet will likely make this a list private Planet mPlanet2; //temp planet will likely make this a list /// /// Constructor /// public HackerHavocOld() { // Basic game initialization HUD.ShowMouseCursor = true; mInitialized = false; mAllIsLost = false; //Logger.LogCode(Logger.ExperimentalCode.HH_GameBegin); LuaHelper.RegisterLuaCallbacks(this); // Get the phase queue from the config file //mPhaseQueue = new MeteorPhaseQueue(GenericBaseApplication.GameManager.GetPhaseQueueForMiniGame("MeteorMadness")); mGameState = GameState.Menu; mCurrentTurn = GameTurn.playerTurn; // Initialize game params mGameWorld = new GameWorld(); //temp MM menu declaration mMenuBackground = new Entity(TextureManager.Load(@"Content\MiniGames\HHSplashLogo")); mStartButton = new Button( TextureManager.Load(@"Content\MiniGames\MMStartButton"), TextureManager.Load(@"Content\MiniGames\MMStartButtonOn")); mTutorialButton = new Button( TextureManager.Load(@"Content\MiniGames\MMTutorialButton"), TextureManager.Load(@"Content\MiniGames\MMTutorialButtonOn")); mBackButton = new Button( TextureManager.Load(@"Content\MiniGames\MMBackButton"), TextureManager.Load(@"Content\MiniGames\MMBackButtonOn")); int screenWidth = GenericBaseApplication.GameManager.ScreenWidth; int screenHeight = GenericBaseApplication.GameManager.ScreenHeight; mMenuBackground.Size = new Vector3(screenWidth, screenHeight, 0); mMenuBackground.Position = new Vector3(screenWidth / 2, screenHeight / 2, 0); mStartButton.Size = new Vector3(screenWidth * .22f, screenHeight * .09f, 0f); mTutorialButton.Size = mStartButton.Size; mBackButton.Size = mStartButton.Size; mStartButton.Position = new Vector3(screenWidth * .12f, screenHeight * .935f, 0f); mTutorialButton.Position = mStartButton.Position + new Vector3(screenWidth * .24f, 0f, 0f); mBackButton.Position = mTutorialButton.Position + new Vector3(screenWidth * .24f, 0f, 0f); mPassTurnButton = new Button(TextureManager.Load(@"Content\MiniGames\HHPassTurnButton")); mPassTurnButton.Position = new Vector3((mPassTurnButton.Position.X + mPassTurnButton.Size.X / 2), (mPassTurnButton.Position.Y + mPassTurnButton.Size.Y / 2), 0f); //create planets, wormholes, merchants and then raiders mPlayerShip = new PlayerShip(TextureManager.Load(@"content\MiniGames\HHPlayerShip"), 0,0); mPlayerMeterMax = 500f; mPlanet1 = new Planet(TextureManager.Load(@"content\MiniGames\HHPlanet"), mGameWorld.GameBoard[2].X, mGameWorld.GameBoard[2].Y); mPlanet2 = new Planet(TextureManager.Load(@"content\MiniGames\HHPlanet2"), mGameWorld.GameBoard[8].X, mGameWorld.GameBoard[8].Y); mGameWorld.AddEntity(mPlayerShip); mGameWorld.AddEntity(mPlanet1); mGameWorld.AddEntity(mPlanet2); mPlayerShip.X = 0; mPlayerShip.Y = 0; mGameWorld.center = mPlayerShip; } float pAccel = 200; float deCellMod = 0.75f; /// /// Perform necessary logic updates /// /// public override void Update() { float dt = AstroBaseApplication.GameManager.ElapsedSeconds; if (mGameState == GameState.Menu) { //SoundManager.SetMusic("Maritime Defender Theme"); HUD.ShowMouseCursor = true; mStartButton.Update(); mTutorialButton.Update(); mBackButton.Update(); if (mStartButton.IsLeftClicked || (InputState.IsKeyDown(Keys.Enter) && !InputState.WasKeyDown(Keys.Enter))) { //Start the game up mGameState = GameState.NavagationMode; } } if (mGameState == GameState.NavagationMode) { if (mCurrentTurn == GameTurn.playerTurn) { bool input = false; if (InputState.IsKeyDown(Keys.Right)) { mPlayerShip.dX += pAccel * dt; if (mPlayerShip.dX > pAccel) { mPlayerShip.dX = pAccel; } input = true; } if (InputState.IsKeyDown(Keys.Left)) { mPlayerShip.dX -= pAccel * dt; if (mPlayerShip.dX < -pAccel) { mPlayerShip.dX = -pAccel; } input = true; } if (InputState.IsKeyDown(Keys.Up)) { mPlayerShip.dY -= pAccel * dt; if (mPlayerShip.dY < -pAccel) { mPlayerShip.dY = -pAccel; } input = true; } if (InputState.IsKeyDown(Keys.Down)) { mPlayerShip.dY += pAccel * dt; if (mPlayerShip.dY > pAccel) { mPlayerShip.dY = pAccel; } input = true; } if (!input) { int mod =1; if (mPlayerShip.dX > 0) { mod = -1; } mPlayerShip.dX += pAccel * deCellMod * mod * dt; mod = 1; if (mPlayerShip.dY > 0) { mod = -1; } mPlayerShip.dY += (pAccel * deCellMod * mod) * dt; if (!(mPlayerShip.dX > pAccel * deCellMod) && !(mPlayerShip.dX < -pAccel * deCellMod)) { mPlayerShip.dX = 0.0f; } if (!(mPlayerShip.dY > pAccel * deCellMod) && !(mPlayerShip.dY < -pAccel * deCellMod)) { mPlayerShip.dY = 0.0f; } // System.Console.WriteLine(mod + " x " + mPlayerShip.X +" Y " + mPlayerShip.Y + " " + dt); } // mPlayerShip.Update(); mGameWorld.Update(); } } } /// /// Draws all objects registered with the gameboard /// public override void Draw() { if (mGameState == GameState.Menu) { SpriteBatch sb = new SpriteBatch(GenericBaseApplication.GameManager.GraphicsDevice); sb.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None); // Render the main menu mMenuBackground.Draw(sb); mStartButton.Draw(sb); mTutorialButton.Draw(sb); mBackButton.Draw(sb); sb.End(); } else if (mGameState == GameState.NavagationMode) { // Render the objects registered in the gameboard mGameWorld.Render(); //temp pass turn button rednering // SpriteBatch sb = new SpriteBatch(GenericBaseApplication.GameManager.GraphicsDevice); // sb.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None); // Render the pass turn button // mPassTurnButton.Draw(sb); // sb.End(); } } } }