//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// 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 DarkWynter.Engine.Globals;
using DarkWynter.Engine.Physics;
using DarkWynter.Engine.ObjectLib;
using DarkWynter.Engine.GameObjects;
using DarkWynter.Engine.Init;
using DarkWynter.Stream;
using DarkWynter.Engine.EventControl;
using System.Diagnostics;
#endregion
///
/// An arrow indicating which node the player is on
///
public class Arrows : GameObject
{
Stopwatch stopWatch = new Stopwatch();
const int TIMER = 1;
public int arrowID;
GameObject firstChild;
GameObject secondChild;
///
/// Arrow constructor
///
public Arrows(Load gameObjectLoader)
: base(gameObjectLoader)
{
mass.objectType = Enums_Engine.ObjectType.PORTAL;
mass.dynamicFrictionCoefficient = 0.0f;
mass.isMoving = true;
typeID = "Arrow";
firstChild = new GameObject();
secondChild = new GameObject();
}
///
/// Override and supplament base loading in GameObject.
///
/// XML node containing load data.
/// ObjectLibrary that arrow belongs to.
/// True if it was able to load, else false
public override bool Load(ObjectLibrary objectLibrary)
{
// Call before user code is executed
if (!base.Load(objectLibrary))
{
return false;
}
arrowID = int.Parse(this.name);
//draw.textureList[0] = Statics_Engine.SystemSettings.content.Load("Content/_textures/arrow");
// Get terrain height at position
//float yPosition = objectLibrary.terrain.GetTerrainHeight(load.startPosition.X / Statics_Engine.TerrainSettings.terrainScaleFactor,
// load.startPosition.Z / Statics_Engine.TerrainSettings.terrainScaleFactor);
float yPosition = float.Parse(load.node.Attributes["y"].Value) * Statics_Engine.TerrainSettings.terrainScaleFactor;
// Set position and reference
Vector3 locpos = new Vector3(load.startPosition.X, yPosition, load.startPosition.Z);
Vector3 refpos = new Vector3(load.startPosition.X, yPosition, load.startPosition.Z - 1);
mass.SetPosition(locpos, refpos);
draw.drawMethod = Enums_Stream.DrawMethod.BasicGameObject_Draw;
draw.technique = "BasicLightingShaderMain";
mass.scale = new Vector3(mass.scale.X, 20, mass.scale.Z);
mass.boundingVolume = new BoundingVolume(new BoundingSphere(mass.currentPosition, 180.0f));
stopWatch.Start();
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);
//mass.Rotate(0.0f, 0.05f);
//mass.boundingVolume.radius = 40.0f;
//mass.boundingVolume.UpdateSphere(mass.currentPosition);
}
public override Draw[] DrawM()
{
return new Draw[] { firstChild.Draw(), secondChild.Draw() };
}
///
/// 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)
{
//HACK This is for the Heap Game - Hardcoded for the moment *****HACK*****
if (collidedObject is Human && Statics_Engine.levelIndex == 0)
{
Human human = collidedObject as Human;
human.currentArrow = this;
}
// DFS Game Code
if (collidedObject is Human && Statics_Engine.levelIndex != 1)
{
Statics_Engine.PlayerSettings.lastSpawnPoint = mass.currentPosition;
if (GameEventHandler.CurrentGameConditions.lastNodeVisited != 0)
{
// Update Current Game Conditions
GameEventHandler.CurrentGameConditions.lastNodeVisited = this.arrowID;
}
}
// DFS Game Code
if (collidedObject is ThoughtsAI && Statics_Engine.levelIndex == 1)
{
if (GameEventHandler.CurrentGameConditions.lastNodeVisited != 0)
{
// Update Current Game Conditions
GameEventHandler.CurrentGameConditions.lastNodeVisited = this.arrowID;
}
}
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_Engine.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_Engine.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_Engine.SystemSettings.dt, 0.0f)));
}
}
}
///
/// Override draw for portal
///
public override Draw Draw()
{
// Calculate ObjectSpace(Rotation) and WorldSpace(Translation) Transformation Matrix
draw.matrix = draw.initialTransform *
Matrix.CreateScale(mass.scale) *
Matrix.CreateRotationY((float)Math.PI) *
Matrix.CreateBillboard(this.mass.currentPosition,
Statics_Stream.RenderSettings.cameraList[0].cameraPosition,
Statics_Stream.RenderSettings.cameraList[0].upVec,
Statics_Stream.RenderSettings.cameraList[0].lookAtPosition);
//Matrix.CreateFromQuaternion(mass.currentRotation) *
// Matrix.CreateTranslation(mass.currentPosition);
return draw;
}
///
/// 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)
{
}
}
}