//check to see if the player could jump or fall between the provided nodes private static CONNECTION_TYPE GetConnectionBetween(NODE_TYPE sourceNodeType, NODE_TYPE destNodeType, Physics.Vector2D sourceNodePosition, Physics.Vector2D destinationNodePosition) { //a fall node should never be the destination of a jump or a fall, just the sourcepoint for a fall if (destNodeType == NODE_TYPE.FALL) { return(CONNECTION_TYPE.NONE); } Physics.Player examplePlayer = new Physics.Player(); Physics.PhysicsEngine physEng = Physics.PhysicsEngine.GetPhysicsEngine(); //if a fall connection is possible, return it if ((sourceNodeType == NODE_TYPE.FALL || sourceNodeType == NODE_TYPE.WALL) && physEng.CanPlayerFallFromTo(examplePlayer, sourceNodePosition, destinationNodePosition)) { return(CONNECTION_TYPE.FALL); } //if a jump connection is possible, return it if ((sourceNodeType == NODE_TYPE.FLOOR || sourceNodeType == NODE_TYPE.WALL) && physEng.CanPlayerJumpFromTo(examplePlayer, sourceNodePosition, destinationNodePosition)) { return(CONNECTION_TYPE.JUMP); } return(CONNECTION_TYPE.NONE); }
//the same as DrawJumpRange except it shows what areas the player can currently fall to private void DrawFallRange(Graphics displayDevice) { Physics.RigidBody temp = new Physics.RigidBody(); temp.Shape = new Physics.Circle(7); temp.SetPosition(new Physics.Vector2D()); //draw a grid of dots 40 units apart for (int i = -700; i < 700; i += 40) { for (int j = -360; j < 400; j += 40) { //calculate the position of the dot temp.Position.X = playerCharacter.playerBody.Position.X + i; temp.Position.X -= temp.Position.X % 40; temp.Position.Y = playerCharacter.playerBody.Position.Y + j; temp.Position.Y -= temp.Position.Y % 40; //set colour based on ability to fall to calculated position if (physEng.CanPlayerFallFromTo(playerCharacter, playerCharacter.playerBody.Position, temp.Position)) { temp.Shape.mColor = Color.Black; } else { temp.Shape.mColor = Color.White; } //draw a dot at that position mRenderer.Draw(temp, displayDevice); } } }