private void SetHighPrecisionPosition(GameObject.GameObject obj) { var highPrecision = new HighPrecisionPosition(); highPrecision.Position = Planet.GetComponent <HighPrecisionPosition>().Position; obj.AddComponent(highPrecision); }
internal void RemoveFromInfluence(GameObject.GameObject gameObject) { if (Children.Contains(gameObject)) { Children.Remove(gameObject); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is SetTargetObjectMessage) { SetTargetObjectMessage temp = (SetTargetObjectMessage)msg; mTarget = temp.mTarget_In; if (null != mTarget) { mSetDestinationMsg.mDestination_In = mTarget.pPosition + mParentGOH.pCollisionRoot; mParentGOH.OnMessage(mSetDestinationMsg); } } else if (msg is PathFind.OnPathFindFailedMessage) { PathFind.OnPathFindFailedMessage temp = (PathFind.OnPathFindFailedMessage)msg; // Handle the case were the user places a tile right on top of the destination. if (null != mTarget && temp.mReason == PathFind.OnPathFindFailedMessage.Reason.InvalidLocation) { mSetDestinationMsg.mDestination_In = mTarget.pPosition + mParentGOH.pCollisionRoot; mParentGOH.OnMessage(mSetDestinationMsg); } } }
public void Initalise() { currentVertices = new List <Vector3>(); SystemCore.ActiveScene.SetUpAmbientAndFullLightingRig(); SystemCore.ActiveScene.AddPointLight(new Vector3(0, 15, 0), Color.White, 20, 20, 1, PointLightNumber.One); SystemCore.ActiveScene.AddPointLight(new Vector3(0, -15, 0), Color.White, 20, 20, 1, PointLightNumber.Two); SystemCore.ActiveScene.AddPointLight(new Vector3(0, 0, 15), Color.White, 20, 20, 1, PointLightNumber.Three); SystemCore.ActiveScene.AddPointLight(new Vector3(0, 0, -15), Color.White, 20, 20, 1, PointLightNumber.Four); SystemCore.AddNewUpdateRenderSubsystem(new SkyDome(Color.LightGray, Color.Gray, Color.DarkBlue)); shapeBuilder = new ProceduralShapeBuilder(); CurrentMode = EditMode.Voxel; shapesToBake = new Dictionary <GameObject.GameObject, ProceduralShape>(); cameraGameObject = new GameObject.GameObject("camera"); cameraGameObject.AddComponent(new ComponentCamera()); cameraGameObject.Transform.SetPosition(new Vector3(0, 0, 20)); cameraGameObject.Transform.SetLookAndUp(new Vector3(0, 0, -1), new Vector3(0, 1, 0)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(cameraGameObject); SystemCore.SetActiveCamera(cameraGameObject.GetComponent <ComponentCamera>()); mouseCursor = GameObjectFactory.CreateRenderableGameObjectFromShape(new ProceduralCube(), EffectLoader.LoadSM5Effect("flatshaded")); SystemCore.GameObjectManager.AddAndInitialiseGameObject(mouseCursor); AddGUI(); }
/// <summary> /// Called once per frame by the game object. /// </summary> /// <param name="gameTime">The amount of time that has passed this frame.</param> public override void Update(GameTime gameTime) { // For now we assume the target is always the player, but we could update this to be based on // Classification, or set by a BehaviourMessage. GameObject.GameObject player = GameObjectManager.pInstance.pPlayer; if (null != player) { // Get the vector from our current position to the player. Vector2 delta = player.pPosition - mParentGOH.pPosition; // Calculate how far it is from our current position to the target. Single distanceSq = delta.LengthSquared(); // It must be within a minimum distance before we start to travel towards the target. if (distanceSq < mMaxDistSq) { // Normalize the vector so that it can be scaled by a speed factor. delta.Normalize(); // Speed up as the target gets closer. Single speed = (MathHelper.Lerp(mMaxSpeed, mMinSpeed, (distanceSq / mMaxDistSq))); // Move! mParentGOH.pPosition += delta * speed; } } }
internal void AddToInfluence(GameObject.GameObject gameObject) { if (!Children.Contains(gameObject)) { Children.Add(gameObject); } }
private void CalculateChildMovement(GameTime gameTime, GameObject.GameObject child, Vector3d planetCenter) { //this covers planetary movement through space during orbit. var highPrecisionComponent = child.GetComponent <HighPrecisionPosition>(); Vector3d movementLastFrame = planetCenter - positionLastFrame; highPrecisionComponent.Position += movementLastFrame; //we want to rotate the high precision component around the up vector, around the planet center. if (GetComponent <RotatorComponent>() != null) { double angleRotatedLastFrame = GetComponent <RotatorComponent>().RotationSpeed * gameTime.ElapsedGameTime.TotalMilliseconds; double s = System.Math.Sin(angleRotatedLastFrame); double c = System.Math.Cos(angleRotatedLastFrame); Vector3d shipPos = highPrecisionComponent.Position; shipPos.X -= planetCenter.X; shipPos.Z -= planetCenter.Z; double xNew = shipPos.X * c + shipPos.Z * s; double zNew = -shipPos.X * s + shipPos.Z * c; shipPos.X = xNew + planetCenter.X; shipPos.Z = zNew + planetCenter.Z; highPrecisionComponent.Position = shipPos; child.Transform.Rotate(Vector3.Up, (float)angleRotatedLastFrame); } }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public Behaviour(GameObject.GameObject parentGOH, String fileName) { mParentGOH = parentGOH; // This will call to the derived class's version of LoadContent which should trickle // down through each level. LoadContent(fileName); }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public Behaviour(GameObject.GameObject parentGOH, String fileName) { mParentGOH = parentGOH; // This will call to the derived class's version of LoadContent which should trickle // down through each level. LoadContent(fileName); }
public void GenerateGeometry(Effect testEffect, IModule module) { this.effect = testEffect; this.module = module; vertices = new VertexPositionColorTextureNormal[heightMapSize * heightMapSize]; int vertIndex = 0; for (float i = 0; i < heightMapSize; i++) { for (float j = 0; j < heightMapSize; j++) { var vert = new VertexPositionColorTextureNormal(); vert.Position = CalculateVertexPosition(i, j); vert.Texture = new Vector2(i * 2f / heightMapSize, j * 2f / heightMapSize); vert.Normal = normal; vert.Color = NodeColor; vertices[vertIndex] = vert; vertIndex++; } } GenerateIndices(); if (normal == Vector3.Down || normal == Vector3.Backward || normal == Vector3.Right) { indices = indices.Reverse().ToArray(); } indices = indices.Reverse().ToArray(); Sphereify(sphereSize); GenerateNormals(ref vertices); short[] ind = indices; var p = vertices.Select(x => x.Position).ToList(); var s = BoundingSphere.CreateFromPoints(p); ProceduralShape spherePatch = new ProceduralShape(vertices, indices); spherePatch.Translate(positionOffset); gameObject = GameObjectFactory.CreateRenderableGameObjectFromShape(spherePatch, effect); SystemCore.GameObjectManager.AddAndInitialiseGameObject(gameObject); isLeaf = true; }
internal void AddToInfluence(GameObject.GameObject gameObject) { if (!Children.Contains(gameObject)) { Children.Add(gameObject); if (gameObject is Ship) { ((Ship)gameObject).SetInOrbit(this); } } }
internal void RemoveFromInfluence(GameObject.GameObject gameObject) { if (Children.Contains(gameObject)) { Children.Remove(gameObject); if (gameObject is Ship) { ((Ship)gameObject).ExitedOrbit(); } } }
/// <summary> /// Call this to initialize a Behaviour with data supplied in a file. /// </summary> /// <param name="fileName">The file to load from.</param> public override void LoadContent(String fileName) { base.LoadContent(fileName); //ExampleDefinition def = GameObjectManager.pInstance.pContentManager.Load<ExampleDefinition>(fileName); // By default we have no target. mTarget = null; mSetActiveAnimationMsg = new SpriteRender.SetActiveAnimationMessage();; mSetDestinationMsg = new PathFind.SetDestinationMessage(); mSetSourceMsg = new PathFind.SetSourceMessage(); mGetCurrentBestNodeMsg = new PathFind.GetCurrentBestNodeMessage(); mClearDestinationMsg = new PathFind.ClearDestinationMessage(); mOnReachedPathEndMsg = new OnReachedPathEndMessage(); }
public GameObject.GameObject CreateTranslatedRenderableHeightMap(Color color, Effect effect, Vector3 translation) { var vertexArray = GenerateVertexArray(translation.X, translation.Y, translation.Z); var indexArray = GenerateIndices(); GameObject.GameObject heightMapObject = new GameObject.GameObject(); ProceduralShape shape = new ProceduralShape(vertexArray, indexArray); shape.SetColor(color); RenderGeometryComponent renderGeom = new RenderGeometryComponent(shape); EffectRenderComponent renderComponent = new EffectRenderComponent(effect); heightMapObject.AddComponent(renderGeom); heightMapObject.AddComponent(renderComponent); heightMapObject.AddComponent(new StaticMeshColliderComponent(heightMapObject, GetVertices(), GetIndices().ToArray(), Vector3.Zero)); return(heightMapObject); }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is Health.OnZeroHealthMessage) { // By default just spawn the object where this object is. GameObject.GameObject go = GameObjectFactory.pInstance.GetTemplate(mTemplateFileName); Vector2 spawnPos = mParentGOH.pPosition; // Optionally, there could be an attachment point specified. if (null != mAttachmentPoint) { // Grab that attachment point and position the new object there. mGetAttachmentPointMsg.mName_In = mAttachmentPoint; mParentGOH.OnMessage(mGetAttachmentPointMsg); spawnPos = mGetAttachmentPointMsg.mPoisitionInWorld_Out; } go.pPosition = spawnPos; GameObjectManager.pInstance.Add(go); } }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public FrameRateDisplay(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is SetTargetObjectMessage) { SetTargetObjectMessage temp = (SetTargetObjectMessage)msg; mTarget = temp.mTarget_In; if (null != mTarget) { mSetDestinationMsg.mDestination_In = mTarget.pPosition + mParentGOH.pCollisionRoot; mParentGOH.OnMessage(mSetDestinationMsg); } } else if (msg is PathFind.OnPathFindFailedMessage) { PathFind.OnPathFindFailedMessage temp = (PathFind.OnPathFindFailedMessage)msg; // Handle the case were the user places a tile right on top of the destination. if (null != mTarget && temp.mReason == PathFind.OnPathFindFailedMessage.Reason.InvalidLocation) { mSetDestinationMsg.mDestination_In = mTarget.pPosition + mParentGOH.pCollisionRoot; mParentGOH.OnMessage(mSetDestinationMsg); } } }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public SpawnOnDeath(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public Magnetic(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Call this to put a message back to its default state. /// </summary> public override void Reset() { mTarget_In = null; }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public Health(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Call this to initialize a Behaviour with data supplied in a file. /// </summary> /// <param name="fileName">The file to load from.</param> public override void LoadContent(String fileName) { base.LoadContent(fileName); //ExampleDefinition def = GameObjectManager.pInstance.pContentManager.Load<ExampleDefinition>(fileName); // By default we have no target. mTarget = null; mSetActiveAnimationMsg = new SpriteRender.SetActiveAnimationMessage(); mSetDestinationMsg = new PathFind.SetDestinationMessage(); mSetSourceMsg = new PathFind.SetSourceMessage(); mGetCurrentBestNodeMsg = new PathFind.GetCurrentBestNodeMessage(); mClearDestinationMsg = new PathFind.ClearDestinationMessage(); mOnReachedPathEndMsg = new OnReachedPathEndMessage(); }
/// <summary> /// Call this to put a message back to its default state. /// </summary> public override void Reset() { mTarget_In = null; }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public PathFollow(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public FiniteStateMachine(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public RemoveTileOnDeath(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public FaceForward(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Call this to put a message back to its default state. /// </summary> public override void Reset() { mObject_In = null; mTile_Out = null; }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public Example(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public TileCollision(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Must be called before the singleton is used. /// </summary> public void Initialize() { mCurrentLevel = new GameObject.GameObject("GameObjects\\Levels\\EnvironmentTest\\EnvironmentTest"); GameObjectManager.pInstance.Add(mCurrentLevel); }
/// <summary> /// Called once per frame by the game object. /// </summary> /// <param name="gameTime">The amount of time that has passed this frame.</param> public Result Update(GameTime gameTime) { //DebugMessageDisplay.pInstance.AddDynamicMessage("Path Find - Open: " + mOpenNodes.Count); //DebugMessageDisplay.pInstance.AddDynamicMessage("Path Find - Closed: " + mClosedNodes.Count); //DebugMessageDisplay.pInstance.AddDynamicMessage("Path Find - Unused: " + mUnusedNodes.Count); // Store the current level for easy access throughout algorithm. GameObject.GameObject curLvl = World.WorldManager.pInstance.pCurrentLevel; // If there is no tile at the destination then there is no path finding to do. if (mDestinationTile == null) { return(Result.NotStarted); } // If we have a destination draw it. Even if there isn't a source yet. DebugShapeDisplay.pInstance.AddPoint(mDestination, 2.0f, Color.Yellow); // If the destination is a solid tile then we will never be able to solve the path. if (mDestinationTile != null && mDestinationTile.mType != Level.Tile.TileTypes.Empty) { // We consider this a failure, similar to if a destination was surrounded by solid. return(Result.Failed); } // If our source position is not on a tile then there is no path finding to do. if (mSourceTile == null) { return(Result.NotStarted); } // If our source position is not on a tile, or that tile is solid we cannot ever solve // this path, so abort right away. if (mSourceTile != null && mSourceTile.mType != Level.Tile.TileTypes.Empty) { // Trying to path find to a solid tile is considered a failure. return(Result.Failed); } // If there is a source, draw it. DebugShapeDisplay.pInstance.AddPoint(mSource, 2.0f, Color.Orange); // If the path hasn't already been invalidated this frame, we need to check that // the path didn't get blocked from something like the Player placing blocks. // TODO: This could be changed to only do this check when receiving specific events, // such as the ObjectPlacement Behaviour telling it that a new block has been // placed. if (!mPathInvalidated) { // Loop through the current path and check for any tiles that are not // empty. If they aren't empty this path is no longer valid as there is // something now blocking it. // PathNode node = mCurBest; while (null != node) { if (node.mTile.mType != Level.Tile.TileTypes.Empty) { // Setting this flag will force the path finder to start from // the begining. mPathInvalidated = true; // No need to loop any further. One blockade is enough. break; } node = node.mPrev; } } // If the path has become invalid, we need to restart the pathing algorithm. if (mPathInvalidated) { ClearNodeLists(); // First thing we need to do is add the first node to the open list. PathNode p = mUnusedNodes.Pop(); // There is no cost because it is the starting node. p.mCostFromStart = 0; // For H we use the actual distance to the destination. The Manhattan Heuristic method. p.mCostToEnd = Vector2.Distance(mSource, mDestination); // Store the tile itself. No need to store the previous tile, as there is none in this case. p.mTile = mSourceTile; // Add it to the list, and start the search! mOpenNodes.Add(p); // If the path was invalidated that assume that it is not longer solved. mSolved = false; // The path is no longer invalid. It has begun. mPathInvalidated = false; } // This path finding is very expensive over long distances. To avoid slowing down the game, // the solver is time sliced; it will only execute a small chunk of the algorithm per frame. Int32 timeSliceCount = 0; // TODO: Configure this from XML script. Int32 timeSliceCap = 30; // Continue searching until we hit the destination or run out of open nodes to check against. while (!mSolved && mOpenNodes.Count > 0 && timeSliceCount < timeSliceCap)// && InputManager.pInstance.CheckAction(InputManager.InputActions.B, true)) { timeSliceCount++; // 1. Look for the lowest F cost square on the open list. We refer to this as the current square. mCurBest = mOpenNodes[0]; for (Int32 i = 1; i < mOpenNodes.Count; i++) { if (mOpenNodes[i].pFinalCost <= mCurBest.pFinalCost) { mCurBest = mOpenNodes[i]; } } // 2. Switch it to the closed list. mOpenNodes.Remove(mCurBest); mClosedNodes.Add(mCurBest); // End the search once the destination node is added to the closed list. // if (mCurBest.mTile == mDestinationTile) { OnPathSolved(mCurBest); break; } // 3. For each of the 8 squares adjacent to this current square... for (Int32 i = 0; i < mCurBest.mTile.mAdjecentTiles.Length; i++) { // 3-a. If it is not walkable or if it is on the closed list, ignore it. Otherwise... if (mCurBest.mTile.mAdjecentTiles[i] != null && mCurBest.mTile.mAdjecentTiles[i].mType == Level.Tile.TileTypes.Empty) { // Avoid pathing that cut diagonally across solid tiles. This is ok for the line of // 0 width, but for actual GO, they should not be able to fit through that tight // spot. // / // [+]/ // /[+] // / if (Level.IsAttemptingInvalidDiagonalMove((Level.Tile.AdjacentTileDir)i, mCurBest.mTile)) { continue; } // TODO: Get a better way to know if something is in the closed list already. // Boolean found = false; for (Int32 j = 0; j < mClosedNodes.Count; j++) { if (mClosedNodes[j].mTile == mCurBest.mTile.mAdjecentTiles[i]) { found = true; break; } } // This node is already in the closed list, so move on to the next node. if (found) { continue; } // 3-b. If it isn’t on the open list, add it to the open list. // Make the current square the parent of this square. Record the F, G, and H costs of the square. // TODO: Get a better way to know if something is in the opened list already. // PathNode foundNode = null; for (Int32 j = 0; j < mOpenNodes.Count; j++) { if (mOpenNodes[j].mTile == mCurBest.mTile.mAdjecentTiles[i]) { foundNode = mOpenNodes[j]; break; } } // Diagonal movement cost more than lateral movement, so figure out where this node is // in relation to the current node. Boolean isDiag = (i == (Int32)Level.Tile.AdjacentTileDir.LEFT_DOWN) || (i == (Int32)Level.Tile.AdjacentTileDir.LEFT_UP) || (i == (Int32)Level.Tile.AdjacentTileDir.RIGHT_DOWN) || (i == (Int32)Level.Tile.AdjacentTileDir.RIGHT_UP); // Calculate the cost of moving to this node. This is the distance between the two nodes. // This will be needed in both the case where the node is in the open list already, // and the case where it is not. // The cost is the cost of the previous node plus the distance cost to this node. Single costFromCurrentBest = mCurBest.mCostFromStart + (isDiag ? 11.314f : 8); // If the node was not found it needs to be added to the open list. if (foundNode == null) { // Create a new node and add it to the open list so it can been considered for pathing // in the updates to follow. PathNode p = mUnusedNodes.Pop(); // For now it points back to the current node. This can be overwritten if another node // leads here with a lower cost (see else statement below). p.mPrev = mCurBest; // Store the actual tile. p.mTile = mCurBest.mTile.mAdjecentTiles[i]; // The cost to get to this node (G) is calculated above. p.mCostFromStart = costFromCurrentBest; // The cost to end (H) is just a straight distance calculation. // Manhattan. /* * p.mCostToEnd = Vector2.Distance( * p.mTile.mCollisionRect.pCenterPoint, * mDestination); */ // Diagonal. /* * p.mCostToEnd = 8.0f * System.Math.Max( * System.Math.Abs( * p.mTile.mCollisionRect.pCenterPoint.X - mDestination.X), * System.Math.Abs(p.mTile.mCollisionRect.pCenterPoint.Y - mDestination.Y)); */ // Combo Vector2 source = p.mTile.mCollisionRect.pCenterPoint; Single h_diagonal = System.Math.Min(System.Math.Abs(source.X - mDestination.X), System.Math.Abs(source.Y - mDestination.Y)); Single h_straight = System.Math.Abs(source.X - mDestination.X) + System.Math.Abs(source.Y - mDestination.Y); p.mCostToEnd = (11.314f) * h_diagonal + 8.0f * (h_straight - 2 * h_diagonal); //p.mCostToEnd *= (10.0f + (1.0f/1000.0f)); mOpenNodes.Add(p); /* * Boolean inserted = false; * * for (Int32 k = 0; k < mOpenNodes.Count; k++) * { * if (mOpenNodes[k].mCostToEnd > p.mCostToEnd) * { * mOpenNodes.Insert(k, p); * * inserted = true; * * break; * } * } * * if (!inserted) * { * mOpenNodes.Add(p); * } */ // Ending the search now will alomost always result in the best path // but it is possible for it to fail. if (p.mTile == mDestinationTile) { // Since the path is now solved, update mCurBest so that it is used for // tracing back through the path from now on. mCurBest = p; OnPathSolved(mCurBest); break; } } else { // If it is on the open list already, check to see if this path to that square is better, // using G cost as the measure. A lower G cost means that this is a better path. If so, // change the parent of the square to the current square, and recalculate the G and F // scores of the square. If you are keeping your open list sorted by F score, you may need // to resort the list to account for the change. if (foundNode.mCostFromStart > costFromCurrentBest) { foundNode.mPrev = mCurBest; foundNode.mCostFromStart = costFromCurrentBest; } } } } } // Draw the path. if (mCurBest != null) { DrawPath(mCurBest); } return(mSolved ? Result.Solved : Result.Failed); }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public OgmoRender(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public SimulatedPhysics(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }
/// <summary> /// Constructor which also handles the process of loading in the Behaviour /// Definition information. /// </summary> /// <param name="parentGOH">The game object that this behaviour is attached to.</param> /// <param name="fileName">The file defining this behaviour.</param> public InfiniteBG(GameObject.GameObject parentGOH, String fileName) : base(parentGOH, fileName) { }