//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace ElementalGame.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; #endregion using DarkWynterEngine.Globals; using DarkWynterEngine.Physics; using DarkWynterEngine.ObjectLib; using DarkWynterEngine.GameObjects; /// /// An abstract door with locking mechanics. /// public class Portal : GameObject { private int portalID; private int health; private bool isLocked = true; private int fireIterator = 0; /// /// Portal constructor /// public Portal():base() { mass.objectType = Enums.ObjectType.PORTAL; mass.dynamicFrictionCoefficient = 0.0f; mass.isMoving = true; } /// /// Override and supplament base loading in GameObject. /// /// XML node containing load data. /// ObjectLibrary that portal belongs to. /// True if it was able to load, else false public override bool Load(XmlNode node, ObjectLibrary objectLibrary) { // Call before user code is executed if (!base.Load(node, objectLibrary)) { return false; } //mass.boundingVolume = new BoundingVolume(new BoundingBox(mass.currentPosition - mass.scale, mass.currentPosition + mass.scale)); mass.boundingVolume = new BoundingVolume(new BoundingSphere(mass.currentPosition, 100.0f)); textureList.Add(Statics.SystemSettings.content.Load("Content/_textures/FireRed")); //textureList.Add(Statics.SystemSettings.content.Load("Content/_textures/FireDesert")); textureList.Add(Statics.SystemSettings.content.Load("Content/_textures/FireBlue")); textureList.Add(Statics.SystemSettings.content.Load("Content/_textures/FireAir")); // Xml Parameters specific to object health = int.Parse(node.Attributes["portalHealth"].Value); return true; } /// /// Override and supplement base Update in GameObject. /// /// ObjectLibrary that portal belongs to. public override void Update(ref ObjectLibrary objectLibrary) { // Call before user code is executed base.Update(ref objectLibrary); // Update Collision Box : CLEAN : SCALE SHOULD BE 3 VALUES IN XML //mass.boundingVolume.UpdateBox(mass.currentPosition, mass.currentRotation, mass.scale * new Vector3(20.0f, 1000.0f, 1000.0f)); mass.boundingVolume.UpdateSphere(mass.currentPosition); // Fun with doors... //mass.Rotate(0.0f, 0.01f); //mass.AddForce(new Vector3(-10.0f, 0.0f, 0.0f)); } /// /// Override and supplement response to colliding GameObjects /// /// Object that hit the Portal. /// Force that Portal was hit with. /// ObjectLibrary that portal belongs to. /// True if collidedObject needs to be recycled public override bool ObjectCollisionResponse(GameObject collidedObject, Vector3 resultantForce, ObjectLibrary objectLibrary) { if (collidedObject.mass.objectType != Enums.ObjectType.PLAYER) { // Non-playerObject - Non-playerObject collision response if (health == 0) { mass.AddForce(new Vector3(0.0f, -1000.0f, 0.0f)); } else { health--; } } if (collidedObject.mass.objectType == Enums.ObjectType.PLAYER) { // if human, load next room // if islocked = true, rotate door model open // else, remain shut // HACK: BreakPoint for dev... health--; health++; } switch (portalID) { case 1: // Call the method for the door //if (collidedObject.mass.objectType == Mass.ElementType.EARTH) //Door can take damage //portalHealth = portalHealth - totalDamage(); //} if (health <= 0) { // Call the doop open method //Drop the collision detection mass.boundingVolume.UpdateBox(mass.currentPosition, mass.currentRotation, Vector3.Zero); } break; case 2: // Call the method for the door break; } if (isLocked == false) { //Rotate door model open } return false; } /// /// Overrides and supplements response to this object hitting the ground. /// /// The terrain object which this Portal hit. public override void TerrainCollisionResponse(Terrain terrain) { base.GetObjectHeight(terrain); // Add Gravity if terrain and player are touching if (heightDifference < 0.0f) { mass.AddForce(mass.mass * Statics.GameSettings.accelDueToGravity); } else if (heightDifference > 0.0f) { base.TerrainCollisionResponse(terrain); if (mass.totalForce.Y > 0.0f) { mass.totalForce.Y = 0.0f; } if (mass.velocity.Y > 0.0f) { mass.velocity.Y = 0.0f; } if (heightDifference < 0.0f) { mass.AddForce(mass.mass * Statics.GameSettings.accelDueToGravity); } else if (heightDifference > 0.0f) { if (mass.totalForce.Y > 0.0f) { mass.totalForce.Y = 0.0f; } if (mass.velocity.Y > 0.0f) { mass.velocity.Y = 0.0f; } // Ground pushing up to negate gravity mass.AddForce(new Vector3(0.0f, heightDifference * terrain.propSurfaceTension, 0.0f) - (new Vector3(0.0f, mass.totalForce.Y, 0.0f) + new Vector3(0.0f, mass.velocity.Y * mass.mass / Statics.SystemSettings.dt, 0.0f))); } } } /// /// Override and supplement base Billboard drawing specific to this Portal. /// /// ObjectLibrary that portal belongs to. /// Dynamic list of billboards to be drawn this frame. public override void Draw_Billboards(ObjectLibrary objectLibrary, BillboardList gameObjectBillboards) { fireIterator++; if (fireIterator > 2) fireIterator = 0; Random random = new Random(); // Random number between -0.5 and 0.5 to modulate height float randOffsetY = (float) random.NextDouble(); randOffsetY -= 0.5f; // Random number between 0-3, excluding 4.. int randTexture = (int) (random.NextDouble() * textureList.Count - .01); Vector3 offset = new Vector3(80.0f , 10.0f * randOffsetY + 150.0f , 250.0f * randOffsetY); gameObjectBillboards.Add(new Billboard(mass.currentPosition, offset, 600.0f, 800.0f, textureList[randTexture])); } } }