//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynter.Game.GameObjects { #region Using Statements using System; 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 System.Xml; using System.Diagnostics; using System.Threading; using DarkWynter.Game.Globals; using DarkWynter.Engine; using DarkWynter.Engine.Globals; using DarkWynter.Engine.ObjectLib; using DarkWynter.Engine.GameObjects; using DarkWynter.Engine.Controllers; using DarkWynter.Engine.UserInterface; using DarkWynter.Stream; using DarkWynter.Engine.Init; using Xclna.Xna.Animation; #endregion /// /// Child class of player which handles human interactions with the game /// public class Human : Player { /// /// Heads up display /// public HeadsUpDisplay HUD = new HeadsUpDisplay(); #region init variables public HeadsUpDisplay deadHUD = new HeadsUpDisplay();//HUDs which can be removed private Viewport viewport; private Viewport originalViewport = Statics_Stream.RenderSettings.cameraList[0].viewport; // original viewport for resize private Enums_Game.HUDGPUDebugScreen debugScreen = Enums_Game.HUDGPUDebugScreen.NONE; private Stopwatch ReadTimer = new Stopwatch(); private Stopwatch VisTimer = new Stopwatch(); private Stopwatch ReadCodeTimer = new Stopwatch(); private Stopwatch MoveCodeTimer = new Stopwatch(); bool healthWarningShown = false; bool codeVis1 = false; private string timing; private string formatedSeconds; private string codeToBeDisplayed; private float GameWindowWidth = Statics_Stream.RenderSettings.GAME_WINDOW_WIDTH; private float GameWindowHeight = Statics_Stream.RenderSettings.GAME_WINDOW_HEIGHT; private float sizeRatioH; private float sizeRatioW; private float scaleX, scaleY; private const double MAGIC_HEALTH_NUMBER = 1.475; private const int MARGIN_WIDTH = 15; private const int SCROLL = 20; private int dhudKilledByIndex; private int thoughtIndex; private int thoughtEIndex; private int sanityIndex; private int sanityEIndex; private int timerIndex; private int timerTextIndex; private int sanityTextIndex; private int thoughtTextIndex; private int dialogueBoxIndex; private int speakerTextIndex; private int dialogueTextIndex; private int hudDPadGlyph; private int codeBackgroundIndex; private int codeScrollIndex; private int eleIconIndex; private int eleNameIndex; private int seconds; private int minutes; private int setLag = 10000; // 10 seconds private Vector2 CENTER_LOCATION = new Vector2(Statics_Stream.RenderSettings.GAME_WINDOW_WIDTH / 4, Statics_Stream.RenderSettings.GAME_WINDOW_HEIGHT / 4); private Vector2 CODE_VIS_LOCATION = new Vector2(0, 0); private Vector2 TIMER_TEXT_OFFSET = new Vector2(25, 10); private Vector2 SANITY_TEXT_OFFSET = new Vector2(50, 10); private Vector2 THOUGHT_TEXT_OFFSET = new Vector2(5, 10); private Vector2 DIALOGUE_LOCATION = new Vector2(20, 500); private Vector2 SPEAKER_OFFSET = new Vector2(25, 10); private Vector2 TEXT_OFFSET = new Vector2(20, 50); private Vector2 SANITY_LOCATION = new Vector2(0, 0); private Vector2 THOUGHT_LOCATION = new Vector2(0, 0); private Vector2 TIMER_LOCATION = new Vector2(0, 0); private Vector2 ELE_ICON_LOCATION = new Vector2(0, 0); private Vector2 ELE_NAME_LOCATION = new Vector2(0, 0); private Vector2 SCROLL_BAR_LOCATION = new Vector2(0, 0); private Texture2D sanityBarTexture; private Texture2D sanityBarEmptyTexture; private Texture2D thoughtBarTexture; private Texture2D thoughtBarEmptyTexture; private Texture2D timerTexture; private Texture2D dialogueBoxTexture; private Texture2D codeBackgroundTexture; private Texture2D eleIconTexture; private Texture2D codeScrollTexture; #region old textures //private Texture2D earthHUDTexture; //private Texture2D fireHUDTexture; //private Texture2D airHUDTexture; //private Texture2D waterHUDTexture; //private Texture2D terrainModHUDTexture; //private Texture2D borderTexture_top; //private Texture2D borderTexture_side; //private Texture2D hudMannaGainTexture; //private Texture2D hudDamageTexture; //private Texture2D hudKeyTexture; //private Texture2D hudLeftBackgroundTexture; //private Texture2D hudRightBackgroundTexture; #endregion #endregion /// /// Constructor /// public Human(Load gameObjectLoader) : base(gameObjectLoader) { mass.objectType = Enums_Engine.ObjectType.PLAYER; mass.gameObjectPointer = this; } #region old constructor //public Human(int playerNumber) // : base(playerNumber) //{ // rumbleEventList.Clear(); // mass.objectType = Enums_Engine.ObjectType.PLAYER; // mass.gameObjectPointer = this; //} #endregion /// /// Load Human information from XML /// /// ObjectLibrary /// True if load was successful public override bool Load(ObjectLibrary objectLibrary) { // playerInfo = XML.playerInfo[0]; if (!base.Load(objectLibrary)) { return false; } //StopRumble(); //rumbleEventList.Clear(); CreateHUD(Statics_Stream.RenderSettings.cameraList[0].viewport, objectLibrary); return true; } /// /// Update player behavior /// public override void Update(ref ObjectLibrary objectLibrary) { //if (DarkWynterGame.playerController == null) //{ // return; //} //// Get the controller updates //DarkWynterGame.playerController.Update(lastModeSelected); // Update HUD UpdateHUD(objectLibrary); //UpdateRumble(); base.Update(ref objectLibrary); //UpdateIndicators(); UpdateKillInfo(); //if (stopRumble) //{ // StopRumble(); //} } /// /// Toggle First Person View /// public override void FPVToggle() { fpvEnabled = !fpvEnabled; } /// /// Draw HUD /// /// Sprite Batch public override void DrawHUD(SpriteBatch spriteBatch) { HUD.Draw(spriteBatch); } /// /// Displays how the current player died /// public void UpdateKillInfo() { if (killInfo != "") { deadHUD.UpdateText(this.dhudKilledByIndex, killInfo); } else if (killingParticle != null) { string killerString; if (killedBy == playerIndex) { deadHUD.UpdateText(this.dhudKilledByIndex, "Suicidal tendencies..."); } else { switch (killedBy) { case 0: killerString = "Player 1"; break; case 1: killerString = "Player 2"; break; case 2: killerString = "Player 3"; break; case 3: killerString = "Player 4"; break; default: killerString = "Bot " + (killedBy - 3); break; } switch (killingParticle.particleType) { case Enums_Engine.ParticleType.Air: deadHUD.UpdateText(this.dhudKilledByIndex, "Blown away by " + killerString); break; case Enums_Engine.ParticleType.Earth: if (killingParticle.mass.energy > 0.3f) { deadHUD.UpdateText(this.dhudKilledByIndex, "Molted by " + killerString); } else { deadHUD.UpdateText(this.dhudKilledByIndex, "Buried by " + killerString); } break; case Enums_Engine.ParticleType.Water: if (killingParticle.mass.energy > 0.3f) { deadHUD.UpdateText(this.dhudKilledByIndex, "Boiled by " + killerString); } else if (killingParticle.mass.energy < -0.3f) { deadHUD.UpdateText(this.dhudKilledByIndex, "Frozen by " + killerString); } else { deadHUD.UpdateText(this.dhudKilledByIndex, "Drowned by " + killerString); } break; } } } } /// /// Update the HUD /// /// private void UpdateHUD(ObjectLibrary objectLibrary) { #region timing seconds = ((int)Statics_Engine.LevelSettings.gameTimer.Elapsed.TotalSeconds) % 60; minutes = ((int)Statics_Engine.LevelSettings.gameTimer.Elapsed.TotalSeconds) / 60; formatedSeconds = seconds.ToString(); if (seconds < 10) { formatedSeconds = "0" + seconds.ToString(); } timing = minutes.ToString() + ":" + formatedSeconds; #endregion //Update the time in-game HUD.UpdateTextVis(this.timerTextIndex, timing, true, Color.DarkGreen); HUD.UpdateTextVis(this.sanityTextIndex, health.ToString(), true, Color.ForestGreen); //placeholder for HUD.UpdateTextVis(this.thoughtTextIndex, escapedThoughts.ToString() + "/" + totalThoughts.toString(), true, Color.Violet); HUD.UpdateTextVis(this.thoughtTextIndex, "10/10", true, Color.Violet); //Update the health bar HUD.UpdateImageSource(sanityEIndex, new Rectangle(0, 0, sanityBarEmptyTexture.Width, (int)(MAGIC_HEALTH_NUMBER * ((100 - (int)health) * ((int)sanityBarEmptyTexture.Height / 100))))); //the math should be just (int)((100 - (int)health) * ((int)sanityBarEmpty.Height / 100)); #region Not finished/working Code ////Update the thought bar //HUD.UpdateImageSource(thoughtEIndex, // new Rectangle(0, 0, // thoughtBarEmpty.Width, // (int)(MAGIC_HEALTH_NUMBER * ((totalThoughts - escapedThoughts)/100 * ((int)thoughtBarEmpty.Height / 100))))); //if (hudDPadGlyph == -1 && objectLibrary.gpuObjectLists.Count != 0) //{ // hudDPadGlyph = HUD.AddImageDisplay(objectLibrary.gpuObjectLists[0].variables[0]._read, // new Vector2(0, 0), // objectLibrary.gpuObjectLists[0].variables[0]._read.Width, // objectLibrary.gpuObjectLists[0].variables[0]._read.Height, // Color.White, // false); //} #endregion if (Statics_Game.GameSettings.isProblemFinished && !codeVis1) { // DisplayDialog(Statics_Engine.PlayerSettings.studentName,Statics_Engine.PlayerSettings.studentMessage, Color.Blue, 2000, ReadTimer, ref healthWarningShown); RunCodeVisualization(); } #region debug stuff // Debug walking // DisplayDialog(this.mass.currentPosition.ToString(), Statics_Game.GameSettings.whereAreYou.ToString(), Color.Blue, 20000000, ReadTimer, ref healthWarningShown); //debug health bars //if (health > 10) //{ // healthWarningShown = false; // health -= 6; //} //if (health <= 10) //{ // DisplayDialog("Cera", "You're about to die...", Color.Red, 2000, ReadTimer, ref healthWarningShown); //} if (debugScreen != Statics_Game.HumanSettings.debugScreen && objectLibrary.gpuObjectLists.Count != 0) { debugScreen = Statics_Game.HumanSettings.debugScreen; SetDebugScreen(objectLibrary); } #endregion } /// /// Get the code from the student and run it on the screen so they can follow what it actually does /// Going to be hacky and buggy for the time being /// private void RunCodeVisualization() { // after 5 seconds, move the scroll bar down to the next line of code if (ReadCodeTimer.ElapsedMilliseconds >= 1000) { SCROLL_BAR_LOCATION.Y += codeScrollTexture.Height; HUD.UpdateImageDisplay(codeScrollIndex, codeScrollTexture, SCROLL_BAR_LOCATION, codeScrollTexture.Width, codeScrollTexture.Height, Color.White, true); ReadCodeTimer.Reset(); ReadCodeTimer.Start(); } else if (SCROLL_BAR_LOCATION.Y > CODE_VIS_LOCATION.Y + codeBackgroundTexture.Height) { ReadCodeTimer.Stop(); ReadCodeTimer.Reset(); codeVis1 = true; } else if (!ReadCodeTimer.IsRunning) { codeScrollIndex = HUD.AddImageDisplay(codeScrollTexture, CODE_VIS_LOCATION, codeScrollTexture.Width, codeScrollTexture.Height, Color.White, true); codeToBeDisplayed = Statics_Game.GameSettings.ParsesandCompilesCode; HUD.UpdateImageDisplay(codeBackgroundIndex, codeBackgroundTexture, CODE_VIS_LOCATION, codeBackgroundTexture.Width, codeBackgroundTexture.Height, Color.White, true); VisTimer.Start(); // display the user code HUD.AddTextDisplay(codeToBeDisplayed, CODE_VIS_LOCATION, Color.White); // display the scroll bar over (illusion) the code //HUD.AddImageDisplay(codeScrollTexture, CODE_VIS_LOCATION, codeScrollTexture.Width, codeScrollTexture.Height, Color.White, true); ReadCodeTimer.Reset(); ReadCodeTimer.Start(); } else { // HUD.UpdateImageDisplay(codeScrollIndex, codeScrollTexture, // SCROLL_BAR_LOCATION, codeScrollTexture.Width, codeScrollTexture.Height, Color.White, false); } // // if the readcode timer is less than 10 seconds, remove the image and update to the new position // if (ReadCodeTimer.ElapsedMilliseconds > 1000) // { // HUD.UpdateImageDisplay(codeScrollIndex, codeScrollTexture, SCROLL_BAR_LOCATION, codeScrollTexture.Width, codeScrollTexture.Height, Color.White, false); // MoveCodeTimer.Reset(); // MoveCodeTimer.Start(); // //if (MoveCodeTimer.ElapsedMilliseconds > 10000) // //{ // // MoveCodeTimer.Stop(); // // MoveCodeTimer.Reset(); // //} // ReadCodeTimer.Stop(); // ReadCodeTimer.Reset(); // } //// when the visualization is complete, drop the images and reset back to the player // codeToBeDisplayed = ""; // HUD.UpdateImageVis(codeBackgroundIndex, false, Color.White); // eleNameIndex = HUD.AddTextDisplay(Statics_Engine.PlayerSettings.studentName, ELE_NAME_LOCATION, Color.White); } /// /// Generate the HUD /// /// Viewport to associate with the HUD /// ObjectLibrary public void CreateHUD(Viewport viewport, ObjectLibrary objectLibrary) { viewport = AssignHUDTextures(viewport); HUD = new HeadsUpDisplay(playerIndex, viewport); timerTextIndex = HUD.AddTextDisplay(" ", TIMER_LOCATION + TIMER_TEXT_OFFSET, Color.DarkGreen); sanityTextIndex = HUD.AddTextDisplay(" ", SANITY_LOCATION + SANITY_TEXT_OFFSET, Color.ForestGreen); thoughtTextIndex = HUD.AddTextDisplay(" ", THOUGHT_LOCATION + THOUGHT_TEXT_OFFSET, Color.Violet); dialogueBoxIndex = HUD.AddImageDisplay(dialogueBoxTexture, DIALOGUE_LOCATION, dialogueBoxTexture.Width, dialogueBoxTexture.Height, Color.White, false); speakerTextIndex = HUD.AddTextDisplay("", DIALOGUE_LOCATION + SPEAKER_OFFSET, Color.White); HUD.UpdateTextVisible(speakerTextIndex, false); dialogueTextIndex = HUD.AddTextDisplay("", DIALOGUE_LOCATION + TEXT_OFFSET, Color.White); HUD.UpdateTextVisible(dialogueTextIndex, false); sanityIndex = HUD.AddImageDisplay(sanityBarTexture, SANITY_LOCATION, sanityBarTexture.Width, sanityBarTexture.Height, Color.ForestGreen, true); sanityEIndex = HUD.AddImageDisplay(sanityBarEmptyTexture, SANITY_LOCATION, sanityBarEmptyTexture.Width, sanityBarEmptyTexture.Height, Color.White, true); thoughtIndex = HUD.AddImageDisplay(thoughtBarTexture, THOUGHT_LOCATION, thoughtBarTexture.Width, thoughtBarTexture.Height, Color.Violet, true); thoughtEIndex = HUD.AddImageDisplay(thoughtBarEmptyTexture, THOUGHT_LOCATION, thoughtBarEmptyTexture.Width, thoughtBarEmptyTexture.Height, Color.Violet, true); timerIndex = HUD.AddImageDisplay(timerTexture, TIMER_LOCATION, timerTexture.Width, timerTexture.Height, Color.White, true); // hudDPadGlyph = -1; codeBackgroundIndex = HUD.AddImageDisplay(codeBackgroundTexture, CODE_VIS_LOCATION, codeBackgroundTexture.Width, codeBackgroundTexture.Height, Color.White, false); eleIconIndex = HUD.AddImageDisplay(eleIconTexture, ELE_ICON_LOCATION, eleIconTexture.Width, eleIconTexture.Height, Color.White, true); UpdateHUD(objectLibrary); } /// /// /// /// /// private Viewport AssignHUDTextures(Viewport viewport) { //init our teckschores sanityBarTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/Sanity"); sanityBarEmptyTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/SanityE"); thoughtBarTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/Thought"); thoughtBarEmptyTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/ThoughtE"); timerTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/Timer"); dialogueBoxTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/dialogueBox"); codeBackgroundTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/transBlack"); codeScrollTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/scrollBar"); eleIconTexture = Statics_Engine.SystemSettings.content.Load("Content/_textures/EleIcon"); // init our locations ELE_ICON_LOCATION = new Vector2(0 + MARGIN_WIDTH, 0 + MARGIN_WIDTH * 2); SANITY_LOCATION = new Vector2(0 + MARGIN_WIDTH + eleIconTexture.Width, 0 + MARGIN_WIDTH); ELE_NAME_LOCATION = new Vector2(MARGIN_WIDTH + 0, sanityBarTexture.Height + MARGIN_WIDTH); THOUGHT_LOCATION = new Vector2(viewport.Width - thoughtBarTexture.Width - MARGIN_WIDTH, 0 + MARGIN_WIDTH); TIMER_LOCATION = new Vector2((viewport.Width / 2) - (int)(timerTexture.Width / 2), MARGIN_WIDTH); CODE_VIS_LOCATION = new Vector2(0 + MARGIN_WIDTH, viewport.Height / 4 + MARGIN_WIDTH); SCROLL_BAR_LOCATION = new Vector2(0 + MARGIN_WIDTH, (viewport.Height / 4 + MARGIN_WIDTH)); return viewport; } /// /// helper method for display dialog /// /// Speaker Name /// Message Text /// Color of Box public void ShowDialog(string speaker, string message, Color color) { HUD.UpdateImageVis(dialogueBoxIndex, true, color); HUD.UpdateTextVis(speakerTextIndex, speaker, true, Color.White); HUD.UpdateTextVis(dialogueTextIndex, message, true, Color.White); } /// /// helper method for display dialog /// public void KillDialog() { HUD.UpdateImageVis(dialogueBoxIndex, false, Color.White); HUD.UpdateTextVis(speakerTextIndex, "ERROR", false, Color.White); HUD.UpdateTextVis(dialogueTextIndex, "YOU SHOULDN'T EVER SEE THIS", false, Color.White); } /// /// Displays a Dialog Box in the proper location in the HUD /// /// The Speaker of the Message /// The Message's Text /// The Message Box's Color /// The Time To Display The Image For /// The Stopwatch to use to keep track /// The Boolean Flip representing this box public void DisplayDialog(string speaker, string message, Color color, int limitMilli, Stopwatch timer, ref bool boxShownFlip) { if (!boxShownFlip) { timer.Start(); if (timer.ElapsedMilliseconds < limitMilli) { ShowDialog(speaker, message, color); } else if (timer.ElapsedMilliseconds >= limitMilli) { KillDialog(); timer.Stop(); timer.Reset(); boxShownFlip = true; } } else boxShownFlip = true; } /// /// Debugging stuff /// /// private void SetDebugScreen(ObjectLibrary objectLibrary) { switch (debugScreen) { case Enums_Game.HUDGPUDebugScreen.NONE: { HUD.UpdateImageVis(hudDPadGlyph, false, Color.White); break; } case Enums_Game.HUDGPUDebugScreen.LOCATION_MAP: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].locationMap._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].locationMap._read.Width, objectLibrary.gpuObjectLists[0].locationMap._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.TOTAL_FORCE: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[0]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[0]._read.Width, objectLibrary.gpuObjectLists[0].variables[0]._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.ACCELERATION: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[1]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[1]._read.Width, objectLibrary.gpuObjectLists[0].variables[1]._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.VELOCITY: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[2]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[2]._read.Width, objectLibrary.gpuObjectLists[0].variables[2]._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.ROTATION: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[3]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[3]._read.Width, objectLibrary.gpuObjectLists[0].variables[3]._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.CURRENT_POSITION: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[4]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[4]._read.Width, objectLibrary.gpuObjectLists[0].variables[4]._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.DUMMY: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[5]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[5]._read.Width, objectLibrary.gpuObjectLists[0].variables[5]._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.RADIUS: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[6]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[6]._read.Width, objectLibrary.gpuObjectLists[0].variables[6]._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.SCALE: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[7]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[7]._read.Width, objectLibrary.gpuObjectLists[0].variables[7]._read.Height, Color.White, true); break; } case Enums_Game.HUDGPUDebugScreen.MASS: { HUD.UpdateImageDisplay(hudDPadGlyph, objectLibrary.gpuObjectLists[0].variables[8]._read, new Vector2(0, 0), objectLibrary.gpuObjectLists[0].variables[8]._read.Width, objectLibrary.gpuObjectLists[0].variables[8]._read.Height, Color.White, true); break; } } } } }