Exemple #1
0
        //Draw the nodes and connections associated with all the rigidbodies, and any current AI paths through the rigidbody graph
        private void DrawRigidbodyGraph(Graphics displayDevice)
        {
            Physics.RigidBody temp = new Physics.RigidBody();
            temp.Shape = new Physics.Circle(5);

            AI.NodeIndex previousNode;

            //for each rigidbody, draw it's core node, all its child nodes, and all its connections
            foreach (AI.Node rb in AIgraph.topLevelNode.internalNodes)
            {
                //draw the node
                temp.SetPosition(AIgraph.topLevelNode.GetNodePosition(rb.index));
                temp.Shape.mColor = Color.DarkOrange;
                mRenderer.Draw(temp, displayDevice);

                //draw its children
                foreach (AI.Node nd in rb.internalNodes)
                {
                    temp.SetPosition(AIgraph.topLevelNode.GetNodePosition(nd.index));
                    temp.Shape.mColor = Color.Chocolate;
                    mRenderer.Draw(temp, displayDevice);
                }

                //draw its connections
                foreach (AI.Connection rbconn in rb.connections)
                {
                    mRenderer.DrawLine(rb.position, AIgraph.topLevelNode.GetNodePosition(rbconn.destination), displayDevice, Color.FromArgb(9, Color.Black));
                }

                //draw each Ai's current high level path
                if (AIgraph.topLevelNode.lastPaths != null)
                {
                    foreach (List <AI.NodeIndex> lastPath in AIgraph.topLevelNode.lastPaths)
                    {
                        previousNode = null;
                        if (lastPath != null)
                        {
                            foreach (AI.NodeIndex node in lastPath)
                            {
                                previousNode = AIgraph.topLevelNode.GetNode(node).previousNode;

                                if (previousNode != null)
                                {
                                    mRenderer.DrawLine(AIgraph.topLevelNode.GetNodePosition(previousNode), AIgraph.topLevelNode.GetNodePosition(node), displayDevice, Color.FromArgb(129, Color.Black));
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        //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);
                }
            }
        }
Exemple #3
0
        //Draw the local nodes and their connections of the rigidbody with index stored in "showLocalNodes"
        private void DrawLocalNodes(Graphics displayDevice)
        {
            Physics.RigidBody temp = new Physics.RigidBody();
            temp.Shape = new Physics.Circle(5);

            //reset showLocalNodes to it's null value if it has been incremented above the number of rigidbodies
            if (showLocalNodes >= AIgraph.topLevelNode.internalNodes.Count)
            {
                showLocalNodes = -1;
            }
            else
            {
                foreach (AI.Node nd in AIgraph.topLevelNode.internalNodes[showLocalNodes].internalNodes)
                {
                    //draw the node
                    temp.SetPosition(AIgraph.topLevelNode.GetNodePosition(nd.index));
                    temp.Shape.mColor = Color.Chocolate;
                    mRenderer.Draw(temp, displayDevice);

                    //draw its connections
                    foreach (AI.Connection ndconn in nd.connections)
                    {
                        if (ndconn.connType == AI.CONNECTION_TYPE.JUMP)
                        {
                            mRenderer.DrawLine(temp.Position, AIgraph.topLevelNode.GetNodePosition(ndconn.destination), displayDevice, Color.DarkOrange);
                        }
                        else if (ndconn.connType == AI.CONNECTION_TYPE.FALL)
                        {
                            mRenderer.DrawLine(temp.Position, AIgraph.topLevelNode.GetNodePosition(ndconn.destination), displayDevice, Color.DarkMagenta);
                        }
                        else
                        {
                            mRenderer.DrawLine(temp.Position, AIgraph.topLevelNode.GetNodePosition(ndconn.destination), displayDevice, Color.Black);
                        }
                    }
                }
            }

            //also draw the player's current node, if the player has one
            AI.Node nearestNode = AIgraph.GetNodeAtPoint(playerCharacter.playerBody.Position);
            if (nearestNode != null)
            {
                temp.SetPosition(AIgraph.topLevelNode.GetNodePosition(nearestNode.index));
                temp.Shape.mColor = Color.Black;
                mRenderer.Draw(temp, displayDevice);
            }
        }
 //Draw a given point as a circle with radius 3, with colour Azure
 public void Draw(Physics.Vector2D point, Graphics g)
 {
     Physics.RigidBody temp = new Physics.RigidBody();
     temp.SetPosition(point);
     temp.Shape        = new Physics.Circle(3);
     temp.Shape.mColor = Color.Azure;
     Draw(temp, g);
 }
Exemple #5
0
        //Draw the short term paths of all AI and display the current number of active AI
        private void DrawAIPath(Graphics displayDevice)
        {
            //write the number of AI currently active in the top right of the screen
            mRenderer.Draw(AIgraph.paths.Count().ToString(), new Physics.Vector2D(1200, 10), displayDevice);

            //draw all short term paths
            Physics.RigidBody temp = new Physics.RigidBody();
            AI.NodeIndex      previousNode;
            for (int i = 0; i < AIgraph.paths.Count(); ++i)
            {
                //Draw the AI's current destination node
                temp.Shape        = new Physics.Circle(8);
                temp.Shape.mColor = Color.BlueViolet;
                temp.SetPosition(AIgraph.topLevelNode.GetNodePosition(AIgraph.GetNextDestination(i, AIgraph.GetNodeAtPoint(mAImanager.aiControllers[i].AIPlayer.playerBody.Position))));
                if (temp.Position != null)
                {
                    mRenderer.Draw(temp, displayDevice);
                }

                //draw all nodes in the short term path
                temp.Shape.mColor = Color.Green;
                temp.Shape        = new Physics.Circle(5);
                foreach (AI.NodeIndex node in AIgraph.paths[i])
                {
                    //draw the node
                    temp.SetPosition(AIgraph.topLevelNode.GetNodePosition(node));
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }

                    //draw the connection between that node and the previous node
                    previousNode = AIgraph.topLevelNode.GetNode(node).previousNode;
                    if (previousNode != null)
                    {
                        mRenderer.DrawArrow(AIgraph.topLevelNode.GetNodePosition(previousNode), temp.Position, displayDevice);
                    }
                }
            }
        }
Exemple #6
0
        private void CreateObjects()
        {
            Physics.RigidBody newBody = new Physics.RigidBody();

            //declare the colours used
            System.Drawing.Color wallColour         = System.Drawing.Color.DarkSlateGray;
            System.Drawing.Color furnitureColour    = System.Drawing.Color.Brown;
            System.Drawing.Color cloudColour        = System.Drawing.Color.LightGray;
            System.Drawing.Color liftColour         = System.Drawing.Color.BlueViolet;
            System.Drawing.Color goalColour         = System.Drawing.Color.Gold;
            System.Drawing.Color wreckingBallColour = System.Drawing.Color.Black;


            //create the ground floor
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(1700, 80);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(400, 700));
            thePhysicsEngine.addRigidBody(newBody);
            //front desk
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(200, 40);
            newBody.Shape.mColor = furnitureColour;
            newBody.SetPosition(new Physics.Vector2D(1100, 640));
            thePhysicsEngine.addRigidBody(newBody);

            //Create the left wall
            //bottom bit
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(40, 650);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(0, 275));
            thePhysicsEngine.addRigidBody(newBody);

            //top bit
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(40, 300);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(0, -300));
            thePhysicsEngine.addRigidBody(newBody);

            //create the right wall
            //Top bit
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(40, 850);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(1200, -25));
            thePhysicsEngine.addRigidBody(newBody);

            //bottom bit
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(40, 200);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(1200, 650));
            thePhysicsEngine.addRigidBody(newBody);

            //breakaway bit
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(40, 149);
            newBody.Shape.mColor = wallColour;
            newBody.Mass         = 4000.0f;
            newBody.SetPosition(new Physics.Vector2D(1200, 475));
            newBody.SetDynamic();
            thePhysicsEngine.addRigidBody(newBody);


            //create the first floor
            //floor
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(1000, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(500, 550));
            thePhysicsEngine.addRigidBody(newBody);

            //stairs
            float width = 400, height = 20;
            float Xpos = 200, Ypos = 530;

            for (int i = 0; i < 9; ++i)
            {
                newBody              = new Physics.RigidBody();
                newBody.Shape        = new Physics.Box(width, height);
                newBody.Shape.mColor = wallColour;
                newBody.SetPosition(new Physics.Vector2D(Xpos, Ypos));
                thePhysicsEngine.addRigidBody(newBody);

                width -= 40;
                Ypos  -= 20;
                Xpos  -= 20;
            }

            //create the second floor
            //left bit
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(250, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(425, 300));
            thePhysicsEngine.addRigidBody(newBody);
            //right bit
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(500, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(950, 300));
            thePhysicsEngine.addRigidBody(newBody);
            //fallen bit
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(145, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(620, 302));
            newBody.SetDynamic();
            thePhysicsEngine.addRigidBody(newBody);
            //girdir to hold the fallen piece up
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(10, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(550, 313));
            thePhysicsEngine.addRigidBody(newBody);

            //create the fragmented floor
            //piece 1
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(130, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(940, 220));
            thePhysicsEngine.addRigidBody(newBody);
            //piece 2
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(190, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(650, 130));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 3
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(100, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(400, 90));
            thePhysicsEngine.addRigidBody(newBody);

            //extra step for balcony
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(50, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(250, 20));
            thePhysicsEngine.addRigidBody(newBody);

            //create jumping "puzzle"
            //piece 4
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(80, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(730, 50));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 5
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(70, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(850, -20));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 6
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(30, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(900, -80));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 7
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(80, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(1000, -50));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 8
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(80, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(1100, -170));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 9
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(70, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(800, -150));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 9
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(30, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(700, -30));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 10
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(60, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(600, -80));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 11
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(40, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(670, -160));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 12
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(70, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(950, -230));
            thePhysicsEngine.addRigidBody(newBody);

            //piece 13
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(130, 10);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(1120, -310));
            thePhysicsEngine.addRigidBody(newBody);


            //create balcony
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(400, 20);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(-50, -50));
            thePhysicsEngine.addRigidBody(newBody);
            //lip
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(10, 40);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(-245, -70));
            thePhysicsEngine.addRigidBody(newBody);

            //create clouds outside balcony
            //cloud 1
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(40, 40);
            newBody.Shape.mColor = cloudColour;
            newBody.SetPosition(new Physics.Vector2D(-350, -100));
            thePhysicsEngine.addRigidBody(newBody);


            //cloud 2
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(50, 50);
            newBody.Shape.mColor = cloudColour;
            newBody.SetPosition(new Physics.Vector2D(-490, -130));
            thePhysicsEngine.addRigidBody(newBody);

            //cloud 3
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(90, 70);
            newBody.Shape.mColor = cloudColour;
            newBody.SetPosition(new Physics.Vector2D(-600, -170));
            thePhysicsEngine.addRigidBody(newBody);

            //cloud 4
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(150, 100);
            newBody.Shape.mColor = cloudColour;
            newBody.SetPosition(new Physics.Vector2D(-800, -230));
            thePhysicsEngine.addRigidBody(newBody);

            //cloud 5
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(350, 160);
            newBody.Shape.mColor = cloudColour;
            newBody.SetPosition(new Physics.Vector2D(-300, -370));
            thePhysicsEngine.addRigidBody(newBody);

            //cloud 6
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(50, 30);
            newBody.Shape.mColor = cloudColour;
            newBody.SetPosition(new Physics.Vector2D(-600, -350));
            thePhysicsEngine.addRigidBody(newBody);

            //cloud 7
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(700, 500);
            newBody.Shape.mColor = cloudColour;
            newBody.SetPosition(new Physics.Vector2D(-1100, -700));
            thePhysicsEngine.addRigidBody(newBody);


            //create the roof
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(900, 40);
            newBody.Shape.mColor = wallColour;
            newBody.SetPosition(new Physics.Vector2D(450, -450));
            thePhysicsEngine.addRigidBody(newBody);


            //create the lifts
            Physics.MovingPlatform newPlatform;
            Physics.Shape          platShape;

            platShape        = new Physics.Box(60, 10);
            platShape.mColor = liftColour;
            newPlatform      = new Physics.MovingPlatform(platShape, new Physics.Vector2D(180, -60), new Physics.Vector2D(180, -300), 30f, 1.0f);
            newPlatform.platform.staticFriction  = 0.7f;
            newPlatform.platform.dynamicFriction = 0.6f;
            thePhysicsEngine.addMovingPlatform(newPlatform);


            platShape        = new Physics.Box(60, 10);
            platShape.mColor = liftColour;
            newPlatform      = new Physics.MovingPlatform(platShape, new Physics.Vector2D(700, -280), new Physics.Vector2D(240, -280), 50f, 1.0f);
            newPlatform.platform.staticFriction  = 0.7f;
            newPlatform.platform.dynamicFriction = 0.6f;
            thePhysicsEngine.addMovingPlatform(newPlatform);

            //the final lift to the goal
            platShape        = new Physics.Box(80, 20);
            platShape.mColor = liftColour;
            newPlatform      = new Physics.MovingPlatform(platShape, new Physics.Vector2D(960, -800), new Physics.Vector2D(960, -400), 10f, 1.0f);
            newPlatform.platform.staticFriction  = 0.7f;
            newPlatform.platform.dynamicFriction = 0.6f;
            thePhysicsEngine.addMovingPlatform(newPlatform);

            //The goal platform
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Box(200, 20);
            newBody.Shape.mColor = goalColour;
            newBody.type         = Physics.RBTypes.GOAL;
            newBody.SetPosition(new Physics.Vector2D(800, -800));
            thePhysicsEngine.addRigidBody(newBody);


            //add the wrecking ball
            //the moving arm
            platShape        = new Physics.Box(10, 10);
            platShape.mColor = liftColour;
            newPlatform      = new Physics.MovingPlatform(platShape, new Physics.Vector2D(1300, 330), new Physics.Vector2D(1550, 330), 50f, 1.0f);
            newPlatform.platform.staticFriction  = 1.0f;
            newPlatform.platform.dynamicFriction = 0.9f;
            thePhysicsEngine.addMovingPlatform(newPlatform);

            //the ball
            newBody              = new Physics.RigidBody();
            newBody.Shape        = new Physics.Circle(40);
            newBody.Shape.mColor = wreckingBallColour;
            newBody.SetPosition(new Physics.Vector2D(1300, 510));
            newBody.Mass = 2000;
            newBody.SetDynamic();
            thePhysicsEngine.addRigidBody(newBody);

            //the chain
            Physics.SpringJoint wreckingBallChain = new Physics.SpringJoint(newPlatform.platform, newBody);
            wreckingBallChain.RestLength = 180;
            wreckingBallChain.Stiffness  = 1000000;
            wreckingBallChain.Dampen     = 1;
            thePhysicsEngine.springs.Add(wreckingBallChain);
        }
Exemple #7
0
        //the same as the above method but for falling
        //this method is effectively just copy/pasted from Player.FallCollidesWithRB() with modifications to display the results
        private void DrawFallCullingPoints(Graphics displayDevice)
        {
            Physics.RigidBody temp = new Physics.RigidBody();
            temp.Shape        = new Physics.Circle(3);
            temp.Shape.mColor = Color.OrangeRed;

            //store the start and endpoints of the fall
            Physics.Vector2D source      = playerCharacter.playerBody.Position;
            Physics.Vector2D destination = jumpDestination;
            if (destination == null)
            {
                destination = new Physics.Vector2D(0, 0);
            }
            Physics.Vector2D displacement = destination - source;

            Tuple <float, float> timeToFall = Physics.SuvatEquations.TfromSUA(displacement.Y, 0.0f, 98);

            if (timeToFall == null)
            {
                return;
            }
            if (float.IsNaN(timeToFall.Item1) && float.IsNaN(timeToFall.Item2))
            {
                return;
            }

            //calculate the acceleration needed to fall to the destination
            float acceleration = Physics.SuvatEquations.AfromSUT(displacement.X, 0.0f, Math.Max(timeToFall.Item1, timeToFall.Item2));

            //calculate the four points where the path defined by acceleration could potentially collide with the rigidbody
            Tuple <float, float> timeToReach;

            float leftmostX;
            float leftmostY;

            float righttmostX;
            float righttmostY;

            float topY;
            float topX;

            float bottomY;
            float bottomX;

            //draw the points where the fall arc could collide with each rigidbody
            foreach (Physics.RigidBody RB in physEng.staticPhysicsObjects)
            {
                //obtain the X positions of the sides of the rigidbody
                leftmostX   = (RB.Position.X + RB.Shape.ComputeAABB().MIN.X) - source.X;
                righttmostX = (RB.Position.X + RB.Shape.ComputeAABB().MAX.X) - source.X;
                //obtain the Y positions of the top and bottom of the rigidbody
                topY    = (RB.Position.Y + RB.Shape.ComputeAABB().MIN.Y) - source.Y;
                bottomY = (RB.Position.Y + RB.Shape.ComputeAABB().MAX.Y) - source.Y;



                //calculate the time to reach the left side of the rigidbody
                timeToReach = Physics.SuvatEquations.TfromSUA(leftmostX, 0.0f, acceleration);

                //calculate the first Y position, draw the first point, calculate the second, draw the second point
                leftmostY = Physics.SuvatEquations.SfromUAT(0.0f, 98, timeToReach.Item1);
                if (!float.IsNaN(leftmostY))
                {
                    mRenderer.Draw(temp, displayDevice);
                    temp.SetPosition(new Physics.Vector2D(leftmostX, leftmostY) + source);
                }
                leftmostY = Physics.SuvatEquations.SfromUAT(0.0f, 98, timeToReach.Item2);
                if (!float.IsNaN(leftmostY))
                {
                    mRenderer.Draw(temp, displayDevice);
                    temp.SetPosition(new Physics.Vector2D(leftmostX, leftmostY) + source);
                }



                //calculate the time to reach the right side of the rigidbody
                timeToReach = Physics.SuvatEquations.TfromSUA(righttmostX, 0.0f, acceleration);

                //calculate the first Y position, draw the first point, calculate the second, draw the second point
                righttmostY = Physics.SuvatEquations.SfromUAT(0.0f, 98, timeToReach.Item1);
                if (!float.IsNaN(righttmostY))
                {
                    mRenderer.Draw(temp, displayDevice);
                    temp.SetPosition(new Physics.Vector2D(righttmostX, righttmostY) + source);
                }
                righttmostY = Physics.SuvatEquations.SfromUAT(0.0f, 98, timeToReach.Item2);
                if (!float.IsNaN(righttmostY))
                {
                    mRenderer.Draw(temp, displayDevice);
                    temp.SetPosition(new Physics.Vector2D(righttmostX, righttmostY) + source);
                }



                //calculate the time to reach the top of the rigidbody
                timeToReach = Physics.SuvatEquations.TfromSUA(topY, 0.0f, 98);

                //calculate the first X position, draw the first point, calculate the second, draw the second point
                topX = Physics.SuvatEquations.SfromUAT(0.0f, acceleration, timeToReach.Item1);
                if (!float.IsNaN(topX))
                {
                    mRenderer.Draw(temp, displayDevice);
                    temp.SetPosition(new Physics.Vector2D(topX, topY) + source);
                }
                topX = Physics.SuvatEquations.SfromUAT(0.0f, acceleration, timeToReach.Item2);
                if (!float.IsNaN(topX))
                {
                    mRenderer.Draw(temp, displayDevice);
                    temp.SetPosition(new Physics.Vector2D(topX, topY) + source);
                }



                //calculate the time to reach the bottom of the rigidbody
                timeToReach = Physics.SuvatEquations.TfromSUA(bottomY, 0.0f, 98);

                //calculate the first X position, draw the first point, calculate the second, draw the second point
                bottomX = Physics.SuvatEquations.SfromUAT(0.0f, acceleration, timeToReach.Item1);
                if (!float.IsNaN(bottomX))
                {
                    mRenderer.Draw(temp, displayDevice);
                    temp.SetPosition(new Physics.Vector2D(bottomX, bottomY) + source);
                }
                bottomX = Physics.SuvatEquations.SfromUAT(0.0f, acceleration, timeToReach.Item2);
                if (!float.IsNaN(bottomX))
                {
                    mRenderer.Draw(temp, displayDevice);
                    temp.SetPosition(new Physics.Vector2D(bottomX, bottomY) + source);
                }
            }
        }
Exemple #8
0
        //draw the points of the player's jump arc at each edge of every rigidbody
        //Used to debug the method that determines if a jump collides with a rigidbody
        //this method is effectively just copy/pasted from Player.JumpCollidesWithRB() with modifications to display the results
        private void DrawJumpCullingPoints(Graphics displayDevice)
        {
            Physics.RigidBody temp = new Physics.RigidBody();
            temp.Shape        = new Physics.Circle(3);
            temp.Shape.mColor = Color.OrangeRed;

            //store the list of positions at each edge of a box rigidbody
            Tuple <Tuple <Physics.Vector2D, Physics.Vector2D, Physics.Vector2D, Physics.Vector2D>, Tuple <Physics.Vector2D, Physics.Vector2D, Physics.Vector2D, Physics.Vector2D> > possibleCollisionPoints;

            //for every static rigidbody
            foreach (Physics.RigidBody RB in physEng.staticPhysicsObjects)
            {
                //obtain the list of coordinates
                possibleCollisionPoints = playerCharacter.GetBoxCollisionPoints(RB, playerCharacter.playerBody.Position, 0.0f, 15.0f, physEng.gravity);

                //draw each valid coordinate as a small red circle
                if (possibleCollisionPoints != null)
                {
                    temp.SetPosition(possibleCollisionPoints.Item1.Item1);
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }
                    temp.SetPosition(possibleCollisionPoints.Item1.Item2);
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }
                    temp.SetPosition(possibleCollisionPoints.Item1.Item3);
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }
                    temp.SetPosition(possibleCollisionPoints.Item1.Item4);
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }

                    temp.SetPosition(possibleCollisionPoints.Item2.Item1);
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }
                    temp.SetPosition(possibleCollisionPoints.Item2.Item2);
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }
                    temp.SetPosition(possibleCollisionPoints.Item2.Item3);
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }
                    temp.SetPosition(possibleCollisionPoints.Item2.Item4);
                    if (temp.Position != null)
                    {
                        mRenderer.Draw(temp, displayDevice);
                    }
                }
            }
        }
Exemple #9
0
        //draw the jump arc of a specified player to a specified destination
        //if specified destination is null then draw the jump assuming the player jumped with no acceleration or deceleration

        //This function is useful for debugging the "Player.GetJumpFromSourceToDest()", "Player.GetJumpYFromX()", and "Player.GetJumpXFromY()" methods
        private void DrawJumpArc(Graphics displayDevice, Physics.Player thePlayer, Physics.Vector2D goal)
        {
            //a temporary variable used in draw calls
            Physics.RigidBody temp = new Physics.RigidBody();

            //stores how long the player accelerates after hitting jump
            float accelerationTime = 0.0f;

            //if a goal was specified
            //	calculate the amount of time the player would need to accelerate after jumping in order to reach the goal
            //	draw the goal point
            if (goal != null)
            {
                accelerationTime = thePlayer.GetJumpFromSourceToDest(thePlayer.playerBody.Position, goal, physEng.gravity);

                //draw the goal
                temp.Shape        = new Physics.Circle(6);
                temp.Shape.mColor = Color.Purple;
                temp.SetPosition(goal);
                mRenderer.Draw(temp, displayDevice);
            }

            //set the object to be drawn to a circle of radius 3
            temp.Shape = new Physics.Circle(3);


            //Temporary variable used to store the coordinates returned from the GetJumpYFromX() and GetJumpXFromY() methods
            Tuple <Physics.Vector2D, Physics.Vector2D> resultingPoints;

            //loop through the 1200 X coordinates around the player, calculating the Y position of the jump at that point
            //Draw a circle at each combined X,Y coordinate in Green
            temp.Shape.mColor = Color.Green;
            for (int i = -600; i < 600; i += 1)
            {
                //Get the two possible X,Y coords of the jump given a specific X coord
                resultingPoints = thePlayer.GetJumpYFromX(thePlayer.playerBody.Position, accelerationTime, 15.0f, physEng.gravity, thePlayer.playerBody.Position.X - i);

                //draw any valid returned coordinates
                if (resultingPoints.Item1 != null)
                {
                    temp.SetPosition(resultingPoints.Item1);
                    mRenderer.Draw(temp, displayDevice);
                }
                if (resultingPoints.Item2 != null)
                {
                    temp.SetPosition(resultingPoints.Item2);
                    mRenderer.Draw(temp, displayDevice);
                }
            }

            //loop through the 1200 Y coordinates around the player, calculating the X position of the jump at that point
            //Draw a circle at each combined X,Y coordinate in red
            temp.Shape.mColor = Color.OrangeRed;
            for (int i = -600; i < 600; i += 10)
            {
                //Get the two possible X,Y coords of the jump given a specific Y coord
                resultingPoints = thePlayer.GetJumpXFromY(thePlayer.playerBody.Position, accelerationTime, 15.0f, physEng.gravity, thePlayer.playerBody.Position.Y - i);

                //draw any valid returned coordinates
                if (resultingPoints.Item1 != null)
                {
                    temp.SetPosition(resultingPoints.Item1);
                    mRenderer.Draw(temp, displayDevice);
                }
                if (resultingPoints.Item2 != null)
                {
                    temp.SetPosition(resultingPoints.Item2);
                    mRenderer.Draw(temp, displayDevice);
                }
            }
        }