//draw the current range of the player's jump by drawing a grid of dots to the screen //each dot it white if it cannot be jumped to and black if it can //This method DOES take into account collisions with rigidbodies private void DrawJumpRange(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 jump to calculated position if (physEng.CanPlayerJumpFromTo(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); } } }
//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); }
//jumping is only possible if the player is colliding with something and the jump arc is allowed by the physics engine private bool CanBecomeJumping() { if (currentNode == null) { return(false); } if (destinationNode == null) { return(false); } //can't jump if the player isn't colliding with anything if (AIPlayer.playerBody.collisionNormal == null) { return(false); } //can only jump if the jump path from the start to the end is possible if (physEng.CanPlayerJumpFromTo(AIPlayer, AIPlayer.playerBody.Position, mainGraph.topLevelNode.GetNodePosition(destinationNode))) { return(true); } //if in doubt, no jumping return(false); }