//--------------------------------------------------------------------------------------------------------------------------------------------------- // // 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 System.Collections; 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 Xclna.Xna.Animation; using DarkWynter.Engine.EventControl; using DarkWynter.Engine.Utilities; using DarkWynter.Engine.Init; #endregion /// /// Child class of player which handles human interactions with the game /// public class Human : Player, IHuman { #region init variables //Human specific indexes of text/imageDisplays private int timerIndex; private int positIndex; public int expIndex; private int successIndex; private int thoughtIndex; private int boopIndex; private int realmapIndex; private int posiX; private int posiY; private int newXpos; private int newYpos; private Stopwatch logPositionTimer = new Stopwatch(); private const double MAGIC_HEALTH_NUMBER = 1.475; private int coins = Statics_Engine.PlayerSettings.coinsCollected; private int displayLimit = 1000; public int mapIndex { get { return _mapIndex; } set { _mapIndex = value; } } public int _mapIndex; public Texture2D MapStart { get { return _MapStart; } set { _MapStart = value; } } public Texture2D _MapStart; public Vector2 MAP_IMAGE_LOCATION { get { return _MAP_IMAGE_LOCATION; } set { _MAP_IMAGE_LOCATION = value; } } public Vector2 _MAP_IMAGE_LOCATION = new Vector2(0, 0); public int MapXOffset = 212; public int MapYOffset = 10; public int stackIndex { get { return _stackIndex; } set { _stackIndex = value; } } public int _stackIndex; public Texture2D StackStart { get { return _StackStart; } set { _StackStart = value; } } public Texture2D _StackStart; public Vector2 STACK_IMAGE_LOCATION { get { return _STACK_IMAGE_LOCATION; } set { _STACK_IMAGE_LOCATION = value; } } public Vector2 _STACK_IMAGE_LOCATION = new Vector2(0, 0); public int StackXOffset = 212; public int StackYOffset = 10; #endregion public Human() : base() { } /// /// Constructor /// public Human(Load gameObjectLoader) : base(gameObjectLoader) { mass.gameObjectPointer = this; } /// /// Find the indexes of all text/imageDisplays specific to human /// /// ObjectLibrary /// True if load was successful public override bool Load(ObjectLibrary objectLibrary) { for (int x = 0; x < DarkWynterEngine.HUD.textDisplays.Count; x++) { if (DarkWynterEngine.HUD.textDisplays[x].name == "timerText") { timerIndex = x; } if (DarkWynterEngine.HUD.textDisplays[x].name == "positionText") { positIndex = x; } if (DarkWynterEngine.HUD.textDisplays[x].name == "expPointsNum") { expIndex = x; } } for (int x = 0; x < DarkWynterEngine.HUD.imageDisplays.Count; x++) { if (DarkWynterEngine.HUD.imageDisplays[x].name == "ThoughtE") { thoughtIndex = x; } if (DarkWynterEngine.HUD.imageDisplays[x].name == "success") { successIndex = x; } if (DarkWynterEngine.HUD.imageDisplays[x].name == "boop") { boopIndex = x; } if (DarkWynterEngine.HUD.imageDisplays[x].name == "REALmap") { realmapIndex = x; } } DarkWynterEngine.HUD.imageDisplays[successIndex].stopWatch.Start(); logPositionTimer.Start(); if (!base.Load(objectLibrary)) { return false; } return true; } /// /// Update player behavior /// public override void Update(ref ObjectLibrary objectLibrary) { #region Logging if (logPositionTimer.ElapsedMilliseconds > 6000) { if (mass.currentPosition != Statics_Engine.PlayerSettings.previousPosition) { Logging.G2LPositionalLog.Add(DateTime.Now.ToString() + " " + mass.currentPosition.ToString()); Statics_Engine.PlayerSettings.previousPosition = mass.currentPosition; } logPositionTimer.Reset(); logPositionTimer.Start(); } #endregion #region Human HUD specific updates (GameTime, Health, Position, and Thought Collected) // Update the Game Time int seconds = ((int)Statics_Engine.LevelSettings.gameTimer.Elapsed.TotalSeconds) % 60; int minutes = ((int)Statics_Engine.LevelSettings.gameTimer.Elapsed.TotalSeconds) / 60; string formatedSeconds = seconds.ToString(); if (seconds < 10) { formatedSeconds = "0" + seconds.ToString(); } string timing = minutes.ToString() + ":" + formatedSeconds; //update the boop posiX = (int)Convert.ToDecimal(this.x); posiY = (int)Convert.ToDecimal(this.z); DarkWynterEngine.HUD.textDisplays[timerIndex].text = timing; //this is terrible fix it later //HACK newXpos = (int)(((float)posiX / 8192.0) * DarkWynterEngine.HUD.imageDisplays[realmapIndex].width + DarkWynterEngine.HUD.imageDisplays[realmapIndex].position.X) - DarkWynterEngine.HUD.imageDisplays[boopIndex].width / 2; newYpos = (int)(((float)posiY / 8192.0) * DarkWynterEngine.HUD.imageDisplays[realmapIndex].height + DarkWynterEngine.HUD.imageDisplays[realmapIndex].position.Y) - DarkWynterEngine.HUD.imageDisplays[boopIndex].height / 2; DarkWynterEngine.HUD.imageDisplays[boopIndex].position = new Vector2(newXpos, newYpos); // figure out what angle we are at and display to the screen DarkWynterEngine.HUD.imageDisplays[boopIndex].rotation = (float)Math.Asin((double.Parse(this.mass.currentRotation.W.ToString()))); DarkWynterEngine.HUD.textDisplays[positIndex].text = "W: " + this.mass.currentRotation.W + " X: " + this.mass.currentRotation.X + " Y: " + this.mass.currentRotation.Y + " Z: " + this.mass.currentRotation.Z; // Update the experience points if changed DarkWynterEngine.HUD.textDisplays[expIndex].text = Statics_Engine.GameSettings.experiencePoints.ToString(); // Update the sanity bar DarkWynterEngine.HUD.imageDisplays[thoughtIndex].Source = new Rectangle(0, 0, DarkWynterEngine.HUD.imageDisplays[thoughtIndex].width, (int)(MAGIC_HEALTH_NUMBER * ((80 - (int)((Statics_Engine.PlayerSettings.coinsCollected) * 10)) * ((int) DarkWynterEngine.HUD.imageDisplays[thoughtIndex].height / 80)))); // Update the success image upon collecting a coin if the coin count changes if (Statics_Engine.PlayerSettings.coinsCollected != coins) { //start the timer and post the message to the screen if (! DarkWynterEngine.HUD.imageDisplays[successIndex].stopWatch.IsRunning) { coins = Statics_Engine.PlayerSettings.coinsCollected; DarkWynterEngine.HUD.imageDisplays[successIndex].stopWatch.Reset(); DarkWynterEngine.HUD.imageDisplays[successIndex].stopWatch.Start(); DarkWynterEngine.HUD.imageDisplays[successIndex].visible = true; } if ( DarkWynterEngine.HUD.imageDisplays[successIndex].stopWatch.ElapsedMilliseconds >= displayLimit) { DarkWynterEngine.HUD.imageDisplays[successIndex].visible = false; DarkWynterEngine.HUD.imageDisplays[successIndex].stopWatch.Stop(); DarkWynterEngine.HUD.imageDisplays[successIndex].stopWatch.Reset(); } } #endregion base.Update(ref objectLibrary); } /// /// Toggle First Person View /// public override void FPVToggle() { fpvEnabled = !fpvEnabled; } } }