/// <summary> /// Use this for finding the floor while in the air /// </summary> /// <returns></returns> public Vector2 getFloorBelow(float offset = 0.0f) { Vector2 yIntersection = Vector2.Zero; foreach (FloorNode node in CurrentRoom.Floor.Nodes.Items) { if ((Bounds.Bottom <= node.Position.Y) || (Bounds.Bottom <= node.LeftNeighbor.Position.Y) || (Bounds.Bottom <= node.RightNeighbor.Position.Y)) { if (dir < 0) { if ((node.Position.X <= Position.X && node.RightNeighbor.Position.X >= Position.X) || (node.Position.X <= Position.X && node.RightNeighbor.Position == node.Position)) { // Are we on the right edge trying to turn around? currentNode = node; yIntersection = CONSTANTS.Y_INTERSECTION(node.RightNeighbor.Position, node.Position, Position.X); } //Are we on the left edge? else if (node.LeftNeighbor.Position == node.Position && Position.X - offset < node.LeftNeighbor.Position.X && node.Position.X <= Bounds.Right) { currentNode = node; yIntersection = CONSTANTS.Y_INTERSECTION(node.RightNeighbor.Position, node.Position, Position.X); } // Are we on the right edge? if (node.RightNeighbor.Position == node.Position && Position.X - offset > node.RightNeighbor.Position.X && node.Position.X >= Bounds.Left) { currentNode = node; yIntersection = CONSTANTS.Y_INTERSECTION(node.LeftNeighbor.Position, node.Position, Position.X); } } else if (dir > 0) // Are we moving right? { if ((node.Position.X >= Position.X && node.LeftNeighbor.Position.X <= Position.X) || (node.Position.X >= Position.X && node.LeftNeighbor.Position == node.Position)) { // Are we on the left edge and trying to turn around? currentNode = node; yIntersection = CONSTANTS.Y_INTERSECTION(node.LeftNeighbor.Position, node.Position, Position.X); } // Are we on the right edge? else if (node.RightNeighbor.Position == node.Position && Position.X + offset > node.RightNeighbor.Position.X && node.Position.X >= Bounds.Left) { currentNode = node; yIntersection = CONSTANTS.Y_INTERSECTION(node.LeftNeighbor.Position, node.Position, Position.X); } // Are we on the left edge? if (node.LeftNeighbor.Position == node.Position && Position.X + offset < node.LeftNeighbor.Position.X && node.Position.X <= Bounds.Right) { currentNode = node; yIntersection = CONSTANTS.Y_INTERSECTION(node.RightNeighbor.Position, node.Position, Position.X); } } } } return(yIntersection); }
public Vector2 getWalkingDistance(Vector2 offset = new Vector2()) { Vector2 yIntersection; foreach (FloorNode node in CurrentRoom.Floor.Nodes.Items) { if (dir < 0) { if ((node.Position.X <= Position.X && node.RightNeighbor.Position.X >= Position.X) || (node.Position.X <= Position.X && node.RightNeighbor.Position == node.Position)) { // Are we on the right edge trying to turn around? yIntersection = CONSTANTS.Y_INTERSECTION(node.RightNeighbor.Position, node.Position, Position.X); if (!IsGrounded && yIntersection.Y > Bounds.Bottom) { currentNode = node; return(yIntersection); } else if (IsGrounded) { currentNode = node; return(CONSTANTS.VECTOR_DISTANCE(Position, node.Position, offset.X)); } } //Are we on the left edge? else if (node.LeftNeighbor.Position == node.Position && Position.X - offset.X < node.Position.X && node.Position.X <= Bounds.Right) { yIntersection = CONSTANTS.Y_INTERSECTION(node.RightNeighbor.Position, node.Position, Position.X); if (!IsGrounded && yIntersection.Y > Bounds.Bottom) { currentNode = node; return(yIntersection); } else if (IsGrounded) { currentNode = node; if (node.LeftNeighbor.Position == node.Position && Position.X - offset.X < node.LeftNeighbor.Position.X && node.Position.X <= Bounds.Right) { Vector2 newDist = CONSTANTS.Y_INTERSECTION(node.Position, new Vector2( node.Position.X - offset.X + (Position.X - Bounds.Left), node.Position.Y), Position.X - offset.X); return(newDist); } else { //currentNode = node; //return CONSTANTS.VECTOR_DISTANCE(Position, node.Position, offset.X); return(Vector2.Zero); } } } } else if (dir > 0) // Are we moving right? { if ((node.Position.X >= Position.X && node.LeftNeighbor.Position.X <= Position.X) || (node.Position.X >= Position.X && node.LeftNeighbor.Position == node.Position)) { // Are we on the left edge and trying to turn around? yIntersection = CONSTANTS.Y_INTERSECTION(node.LeftNeighbor.Position, node.Position, Position.X); if (!IsGrounded && yIntersection.Y > Bounds.Bottom) { currentNode = node; return(yIntersection); } else if (IsGrounded) { currentNode = node; return(CONSTANTS.VECTOR_DISTANCE(Position, node.Position, offset.X)); } } // Are we on the right edge? else if (node.RightNeighbor.Position == node.Position && Position.X + offset.X > node.RightNeighbor.Position.X && node.Position.X >= Bounds.Left) { yIntersection = CONSTANTS.Y_INTERSECTION(node.LeftNeighbor.Position, node.Position, Position.X); if (!IsGrounded && yIntersection.Y > Bounds.Bottom) { currentNode = node; return(yIntersection); } else if (IsGrounded) { currentNode = node; if (node.RightNeighbor.Position == node.Position && Position.X + offset.X > node.Position.X && node.Position.X >= Bounds.Left) { //if (node.LeftNeighbor.Position == node.Position && Position.X - offset.X < node.LeftNeighbor.Position.X && node.Position.X <= Bounds.Right) Vector2 newDist = CONSTANTS.Y_INTERSECTION(node.Position, new Vector2( node.Position.X + offset.X + (Bounds.Right - Position.X), node.Position.Y), Position.X + offset.X); //Vector2 newDist = CONSTANTS.Y_INTERSECTION(node.Position, new Vector2(node.Position.X - offset.X + (Position.X - Bounds.Left), node.Position.Y), Position.X - offset.X); return(newDist); } else { //currentNode = node; //return CONSTANTS.VECTOR_DISTANCE(Position, node.Position, offset.X); return(Vector2.Zero); } } } } } return(Vector2.Zero); }