//--------------------------------------------------------------------------------------------------------------------------------------------------- // // 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; #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 successIndex; private int thoughtIndex; 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(XmlNode objectNode, Vector3 startingLocation) : base(objectNode, startingLocation) { 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.engine.HUD.textDisplays.Count; x++) { if (DarkWynterEngine.engine.HUD.textDisplays[x].name == "timerText") { timerIndex = x; } } for (int x = 0; x < DarkWynterEngine.engine.HUD.imageDisplays.Count; x++) { if (DarkWynterEngine.engine.HUD.imageDisplays[x].name == "ThoughtE") { thoughtIndex = x; } if (DarkWynterEngine.engine.HUD.imageDisplays[x].name == "success") { successIndex = x; } } DarkWynterEngine.engine.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, 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; DarkWynterEngine.engine.HUD.textDisplays[timerIndex].text = timing; // Update the sanity bar DarkWynterEngine.engine.HUD.imageDisplays[thoughtIndex].Source = new Rectangle(0, 0, DarkWynterEngine.engine.HUD.imageDisplays[thoughtIndex].width, (int)(MAGIC_HEALTH_NUMBER * ((80 - (int)((Statics_Engine.PlayerSettings.coinsCollected) * 10)) * ((int)DarkWynterEngine.engine.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.engine.HUD.imageDisplays[successIndex].stopWatch.IsRunning) { coins = Statics_Engine.PlayerSettings.coinsCollected; DarkWynterEngine.engine.HUD.imageDisplays[successIndex].stopWatch.Reset(); DarkWynterEngine.engine.HUD.imageDisplays[successIndex].stopWatch.Start(); DarkWynterEngine.engine.HUD.imageDisplays[successIndex].visible = true; } if (DarkWynterEngine.engine.HUD.imageDisplays[successIndex].stopWatch.ElapsedMilliseconds >= displayLimit) { DarkWynterEngine.engine.HUD.imageDisplays[successIndex].visible = false; DarkWynterEngine.engine.HUD.imageDisplays[successIndex].stopWatch.Stop(); DarkWynterEngine.engine.HUD.imageDisplays[successIndex].stopWatch.Reset(); } } #endregion base.Update(ref objectLibrary); } /// /// Toggle First Person View /// public override void FPVToggle() { fpvEnabled = !fpvEnabled; } } }