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; }
//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); }
//spawn an AI at a given coordinate public void AddAIAt(Physics.Vector2D spawnLocation) { if (aiControllers.Count < MAX_AI_COUNT) { Physics.Player newAIPlayer = new Physics.Player(); newAIPlayer.playerBody.type = Physics.RBTypes.ENEMY; newAIPlayer.playerBody.SetPosition(spawnLocation); physEng.addRigidBody(newAIPlayer.playerBody); aiControllers.Add(new AI.AIEngine(newAIPlayer)); aiGraphManager.AddAIagent(); } }
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; }
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; }
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; }
//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); } } }