private void 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); // top if (IsLineIntersection(topLeft, topRight, isVerticalLine, slope, offset, rfStartPoint, rfEndPoint, new Vector2(0, 1)))//new Vector2(0, -1))) { IsIntersecting = true; } // bottom if (IsLineIntersection(bottomLeft, bottomRight, isVerticalLine, slope, offset, rfStartPoint, rfEndPoint, new Vector2(0, -1)))//new Vector2(0, 1))) { IsIntersecting = true; } // left if (IsLineIntersection(bottomLeft, topLeft, isVerticalLine, slope, offset, rfStartPoint, rfEndPoint, new Vector2(-1, 0)))//new Vector2(1, 0))) { IsIntersecting = true; } // right if (IsLineIntersection(bottomRight, topRight, isVerticalLine, slope, offset, rfStartPoint, rfEndPoint, new Vector2(1, 0)))//new Vector2(-1, 0))) { IsIntersecting = true; } //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); }
private void CheckDrops(Stopwatch stopwatch, int difficulty) { if (AgentList.Where(ga => ga.Type == (int)Enums.AgentType.Enemy).Count() > 0) { GameAgent agent = AgentList.Where(ga => ga.Type == (int)Enums.AgentType.Enemy && ((Enemy)ga).DropType == 0).OrderByDescending(ga => ga.ID).FirstOrDefault(); if (agent == null) { return; } if (nukeDropTime > 0 && stopwatch.ElapsedMilliseconds > nukeDropTime) { ((Enemy)agent).DropType = (int)Enums.ItemType.NukeAttack; nukeDropTime = 0; } else if (teleportDropTime > 0 && stopwatch.ElapsedMilliseconds > teleportDropTime) { ((Enemy)agent).DropType = (int)Enums.ItemType.TeleportSpell; teleportDropTime = 0; } else if ((difficulty != 0) && (stopwatch.ElapsedMilliseconds - lastPowerUp > powerUpInterval / difficulty)) { Player playerObj = PulseGame.Current.player; if (playerObj.Health < playerObj.MaxHealth * 0.25 && GetCurrentHealthPowerUpCount() < 3) { ((Enemy)agent).DropType = (int)Enums.ItemType.HealthPowerUp; lastPowerUp = stopwatch.ElapsedMilliseconds; } else if (playerObj.Power < playerObj.MaxPower * 0.25 && GetCurrentEnergyPowerUpCount() < 3) { ((Enemy)agent).DropType = (int)Enums.ItemType.EnergyPowerUp; lastPowerUp = stopwatch.ElapsedMilliseconds; } } } }