示例#1
0
        //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);
        }
示例#2
0
        //loop through all rigidbodies and add each one to the graph
        public static void PopulateGraph(Physics.PhysicsEngine physEng, Node topNode)
        {
            foreach (var rb in physEng.staticPhysicsObjects)
            {
                //create the rigibody's node
                topNode.AddNode(GraphBuilder.CreateNodesFromRB(rb, topNode.index, topNode.internalNodes.Count));
                AddInternalConnections(topNode.internalNodes[topNode.internalNodes.Count - 1]);

                //connect the new node to the previous nodes
                for (int i = 0; i < topNode.internalNodes.Count - 1; ++i)
                {
                    GraphBuilder.AddConnections(topNode.internalNodes[topNode.internalNodes.Count - 1], topNode.internalNodes[i]);
                }
            }

            foreach (Physics.MovingPlatform mp in physEng.movingPlatforms)
            {
                //create the rigibody's node
                topNode.AddNode(new NodeOnRails(GraphBuilder.CreateNodesFromRB(mp.platform, topNode.index, topNode.internalNodes.Count), mp.point1, mp.point2));
                AddInternalConnections(topNode.internalNodes[topNode.internalNodes.Count - 1]);

                //connect the new node to the previous nodes
                for (int j = 0; j < topNode.internalNodes.Count - 1; ++j)
                {
                    GraphBuilder.AddConnections(topNode.internalNodes[topNode.internalNodes.Count - 1], topNode.internalNodes[j]);
                }
            }

            //Note: this method does not cull connections that get blocked by new rigidbodies.
            //The naive solution to this would increase an already long graph generation time, and as such has not been implemented.
        }
示例#3
0
        public Scene()
        {
            //initialise the physics engine and the AI graph singletons (this is the first initialisation of both)
            thePhysicsEngine = Physics.PhysicsEngine.GetPhysicsEngine();
            AIGraph          = AI.WorldGraph.GetWorldGraph();

            //create the rigidbodies that make up the game world
            CreateObjects();

            //Create the player
            thePlayer = new Physics.Player(20.0f, 15000);
            thePlayer.playerBody.SetPosition(new Physics.Vector2D(0, 620));
            thePlayer.playerBody.Shape.mColor = System.Drawing.Color.Blue;
            thePhysicsEngine.addRigidBody(thePlayer.playerBody);
            thePhysicsEngine.playerCharacter = thePlayer;

            //create the AI manager
            theAIManager = new AI.AIManager(thePlayer, GlobalConstants.WINDOW_WIDTH, GlobalConstants.WINDOW_HEIGHT);
            //add the hardcoded AI spawn points
            CreateAISpawnLocations();

            //use the current level's rigidbodies to generate the nodes and connections of the AI graph
            AIGraph.PopulateGraph(thePhysicsEngine);

            headsUpDisplay = new UI();

            currentState = GAMESTATE.RUNNING;
        }
示例#4
0
        public AIEngine(Physics.Player thePlayer)
        {
            physEng   = Physics.PhysicsEngine.GetPhysicsEngine();
            mainGraph = WorldGraph.GetWorldGraph();

            AIPlayer = thePlayer;

            actionPlan = new List <act_dur>();

            currentState         = STATES.WAITING;
            currentStateCooldown = 0.0f;
            walkingSpeed         = 500f;
            destinationNode      = null;
            currentlyJumping     = false;
        }
示例#5
0
        public AIManager(Physics.Player aTargetPlayer, float width, float height)
        {
            windowHeight = height;
            windowWidth  = width;

            numberGenerator = new Random();
            aiControllers   = new List <AI.AIEngine>();
            targetPlayer    = aTargetPlayer;

            physEng        = Physics.PhysicsEngine.GetPhysicsEngine();
            aiGraphManager = AI.WorldGraph.GetWorldGraph();

            AISpawnLocations = new List <Physics.Vector2D>();

            timeSinceLastSpawn = 0.0f;
            lastSpawnPoint     = 0;
        }
示例#6
0
        public DebugDisplay(Physics.Player thePlayer, AI.AIManager aManager, SimpleRenderer aRender)
        {
            //get references to the useful game classes
            playerCharacter = thePlayer;
            mAImanager      = aManager;
            physEng         = Physics.PhysicsEngine.GetPhysicsEngine();
            AIgraph         = AI.WorldGraph.GetWorldGraph();

            mRenderer = aRender;

            //initialise the bools
            showCurrentPlayerJump = false;
            showNodes             = false;
            showPath              = false;
            showJumpRange         = false;
            showFallRange         = false;
            showJumpBoxCollisions = false;
            showFallBoxCollisions = false;
            showCollisionNormals  = false;
            showLocalNodes        = -1;

            jumpDestination = null;
        }
示例#7
0
 //create the graph from the rigidbodies in the physics engine
 public void PopulateGraph(Physics.PhysicsEngine physEng)
 {
     topLevelNode = new Node(new Physics.Vector2D(0, 0), new NodeIndex(0), NODE_TYPE.GROUP);
     GraphBuilder.PopulateGraph(physEng, topLevelNode);
 }