protected override void Update(GameTime gameTime) { // Allows the game to exit if ((keyboardStateCurrent.IsKeyUp(Keys.Escape) && keyboardStatePrevious.IsKeyDown(Keys.Escape)) || GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // Update keyboard state keyboardStatePrevious = keyboardStateCurrent; keyboardStateCurrent = Keyboard.GetState(); // Update mouse state mouseStatePrevious = mouseStateCurrent; mouseStateCurrent = Mouse.GetState(); player.Update(gameTime, keyboardStateCurrent, keyboardStatePrevious, mouseStateCurrent, mouseStatePrevious, agentAIList, windowWidth, windowHeight); // Create new agent on mouse click if (mouseStateCurrent.LeftButton == ButtonState.Pressed && mouseStatePrevious.LeftButton != ButtonState.Pressed) { // Create a new agent at mouse location GameAgent agent = new GameAgent(); agent.LoadContent(this.Content, "Images\\agent"); agent.Position = new Vector2(mouseStateCurrent.X, mouseStateCurrent.Y); agent.Rotation = 0.0f; agentAIList.Add(agent); agent.Type = (int)Enums.AgentType.NPC; } base.Update(gameTime); }
private bool IsInAgentSensorRange(GameAgent agent, Vector2 playerPos, Vector2 endPoint1, Vector2 endPoint2) { Rectangle agentBounds = agent.Bounds; // getting the 4 points of the agent Vector2 bottomLeft = new Vector2(agentBounds.Left, agentBounds.Top); Vector2 bottomRight = new Vector2(agentBounds.Left + agentBounds.Width, agentBounds.Top); Vector2 topLeft = new Vector2(agentBounds.Left, agentBounds.Top + agentBounds.Height); Vector2 topRight = new Vector2(bottomRight.X, topLeft.Y); return (IsPointInTriangle(bottomLeft, playerPos, endPoint1, endPoint2) || IsPointInTriangle(bottomRight, playerPos, endPoint1, endPoint2) || IsPointInTriangle(topLeft, playerPos, endPoint1, endPoint2) || IsPointInTriangle(topRight, playerPos, endPoint1, endPoint2)); }
private bool CheckIntersection(GameAgent agent, bool isVerticalLine, float slope, float offset, Vector2 rfStartPoint, Vector2 rfEndPoint) { // NOTE: drawing lines backwards so that higher values are always on the top and right // making it easier for calculation. Rectangle agentBounds = agent.Bounds; Vector2 bottomLeft = new Vector2(agentBounds.Left, agentBounds.Top); Vector2 bottomRight = new Vector2(agentBounds.Left + agentBounds.Width, agentBounds.Top); Vector2 topLeft = new Vector2(agentBounds.Left, agentBounds.Top + agentBounds.Height); Vector2 topRight = new Vector2(bottomRight.X, topLeft.Y); return (IsLineIntersection(topLeft, topRight, isVerticalLine, slope, offset, rfStartPoint, rfEndPoint) || IsLineIntersection(bottomLeft, bottomRight, isVerticalLine, slope, offset, rfStartPoint, rfEndPoint) || IsLineIntersection(bottomLeft, topLeft, isVerticalLine, slope, offset, rfStartPoint, rfEndPoint) || IsLineIntersection(bottomRight, topRight, isVerticalLine, slope, offset, rfStartPoint, rfEndPoint)); }