/// <summary> /// Generates GameObjects from tourney /// </summary> /// <param name="tournament"></param> /// <returns></returns> public Collection <GameObjectRobot> CreateGameObjects(Tournament tournament) { Collection <GameObjectRobot> objectList = new Collection <GameObjectRobot>(); if (tournament.Rules.Mode == TournamentMode.LastManStanding || tournament.Rules.Mode == TournamentMode.TeamLastTeamStanding) { foreach (Bracket bracket in tournament.Bracket.Root) { foreach (RobotLoader robot in Teams[bracket.Current - 1].Robots) { GameObjectRobot tank = new GameObjectRobot(robot); objectList.Add(tank); } } } else { Bracket b = tournament.Bracket.FirstRoot.NextBattle(); if (b.Left != null) { /*GameObjectRobot robot = new GameObjectRobot(Teams[b.Left.Current - 1].Robots[0]); * objectList.Add(robot);*/ foreach (RobotLoader robot in Teams[b.Left.Current - 1].Robots) { GameObjectRobot tank = new GameObjectRobot(robot); objectList.Add(tank); } } if (b.Right != null) { /*GameObjectRobot robot = new GameObjectRobot(Teams[b.Right.Current - 1].Robots[0]); * objectList.Add(robot);*/ foreach (RobotLoader robot in Teams[b.Right.Current - 1].Robots) { GameObjectRobot tank = new GameObjectRobot(robot); objectList.Add(tank); } } } return(objectList); }
/// <summary> /// Check if target is in scanner range of robot /// </summary> /// <param name="scanner">The scanning robot</param> /// <param name="target">The target object</param> /// <returns>true if in range</returns> public static bool ObjectInScannerRange(GameObjectRobot scanner, GameObject target) { double scanRadius = 0.69813170079773183076947630739545; //40° double scanRadiusHalf = scanRadius / 2.0; double scannerAngleInRad = scanner.RotationRadar - scanRadiusHalf; double scannerAngleInRad2 = scanner.RotationRadar + scanRadiusHalf; double angleBetweenObjects = Math.Atan2(target.PositionY - scanner.PositionY, target.PositionX - scanner.PositionX); if (angleBetweenObjects >= scannerAngleInRad && angleBetweenObjects <= scannerAngleInRad2) { return(true); } if (scannerAngleInRad < -Math.PI && angleBetweenObjects == Math.PI && target.PositionX < scanner.PositionX) { return(true); } return(false); }