public IEnumerator OnCannonBulletTouch() { ObstacleMap.RemoveObstacle(this); yield return(null); Destroy(this.gameObject); }
public ObstacleMap BuildMap(ObstacleLayerViewModel[] selectedLayers) { ObstacleMap result = new ObstacleMap(); if (selectedLayers == null) { return(result); } Vector2 margin = new Vector2(50f, 50f); foreach (var layer in selectedLayers) { foreach (var obs in layer.Obstacles) { Vector2 positionOnCanvas = new Vector2((float)obs.X, (float)obs.Y); result.Obstacles.Add( new Obstacle() { Radius = 16f, Position = positionOnCanvas - margin }); } } return(result); }
public void CreateObstacle(GameObject objectPrefab, List <Vector2> positions) { foreach (var pos in positions) { var obstacle = Instantiate(objectPrefab, obstacleRoot).GetComponent <Obstacle>(); obstacle.transform.position = new Vector3(pos.x, pos.y, 0) * Globals.TILE_SIZE + new Vector3(0.5f, 0.5f, 0f); obstacle.GetPosition(); ObstacleMap.AddObstacle(obstacle); } }
public void InsideRangeObstacleTest() { obstacleMap = new ObstacleMap(); Obstacle obstacle = new Obstacle(new Vector(-100, 100), new Vector(100, 100)); obstacleMap.AddObstacle(obstacle); Vector result = obstacleMap.GetRouteSuggestion(new Vector(0, 1)).Item1; Assert.IsTrue(result.X <-0.998f && result.X> -1.005f); }
public void CreateCannon(List <Vector2> positions, CannonType type) { foreach (var pos in positions) { var obstacle = Instantiate(cannon, obstacleRoot).GetComponent <Obstacle>(); obstacle.transform.position = new Vector3(pos.x, pos.y, 0) * Globals.TILE_SIZE + new Vector3(0.5f, 0.5f, 0f); obstacle.GetPosition(); obstacle.gameObject.GetComponent <Cannon>().SetType(type); ObstacleMap.AddObstacle(obstacle); } }
public void BetweenObstaclesTest_NarrowSpace() { obstacleMap = new ObstacleMap(); Obstacle obstacleLeft = new Obstacle(new Vector(-1000, 500), new Vector(-200, 500)); Obstacle obstacleRight = new Obstacle(new Vector(200, 500), new Vector(1000, 500)); obstacleMap.AddObstacle(obstacleLeft); obstacleMap.AddObstacle(obstacleRight); Vector result = obstacleMap.GetRouteSuggestion(new Vector(0, 1)).Item1; Assert.IsTrue(result.X <-0.998f && result.X> -1.005f); }
public void BetweenObstaclesTest_WideSpace() { obstacleMap = new ObstacleMap(); Obstacle obstacleLeft = new Obstacle(new Vector(-800, 500), new Vector(-400, 500)); Obstacle obstacleRight = new Obstacle(new Vector(400, 1000), new Vector(800, 1000)); obstacleMap.AddObstacle(obstacleLeft); obstacleMap.AddObstacle(obstacleRight); Vector result = obstacleMap.GetRouteSuggestion(new Vector(0, 1)).Item1; Assert.IsTrue(result.Y > 0.995f && result.Y < 1.005f); }
public void AvoidDirectObstacleTest() { obstacleMap = new ObstacleMap(); Obstacle obstacle = new Obstacle(new Vector(-500, 1000), new Vector(500, 1000)); obstacleMap.AddObstacle(obstacle); Vector result = obstacleMap.GetRouteSuggestion(new Vector(0, 1)).Item1; Assert.IsTrue(result.Y > 0.79f && result.Y < 0.81f); Assert.IsTrue(result.X > -0.59f && result.X < -0.57f); Assert.IsTrue(result.Length > 0.999 && result.Length < 1.001); }
public bool Move(Vector2Int direction) { var target = position + direction; if (ObstacleMap.ObstacleIn(target) == null) { position = target; transform.DOMove(new Vector3(target.x, target.y, 0) + new Vector3(0.5f, 0.5f, 0) * Globals.TILE_SIZE, Globals.TIME_BETWEEN_TURNS); return(true); } else { return(false); } }
public IEnumerator Shoot(Vector2Int init, Vector2Int target) { Vector3 i = new Vector3(init.x + 0.5f, init.y + 0.5f, 0); Vector3 f = new Vector3(target.x + 0.5f, target.y + 0.5f, 0); transform.DOMove(i, 0); transform.DOMove(f, Globals.TIME_BETWEEN_TURNS).SetEase(Ease.Linear); yield return(new WaitForSeconds(Globals.TIME_BETWEEN_TURNS)); if (ObstacleMap.ObstacleIn(target) != null && ObstacleMap.ObstacleIn(target).GetComponent <IBulletTarget>() != null) { yield return(ObstacleMap.ObstacleIn(target).GetComponent <IBulletTarget>().OnBulletTouch()); } Destroy(this.gameObject); }
private void UpdateRoad() { // place a road roadLooper.Place(RoadPlacerLogic.nextRoad()); position = roadLooper.GetRoadByIndex(1).GetPosition(); // next road; // move trigger to a new position position.z += 2; transform.position = position; // design how obstacles should be ObstacleMap map = obstacleGenretor.Generate(); // place obstacles on the new road GameObject road = roadLooper.GetLastRoad().gameObject; //obstaclePlacer.Place(road, map); }
public void Place(GameObject road, ObstacleMap map) { //Vector3 origin = road.transform.position; //origin -= planeOffset; //Debug.Log("Origin " + origin.ToString()); foreach (ObstacleFigure obs in map) { float z = obs.Row + (obs.Width / 2.0f); float x = obs.Column + (obs.Length / 2.0f); float y = obs.Height / 2.0f; Vector3 pos = planeOrigin + new Vector3(x, y, z); GameObject tmp = ObstacleTemplateFetcher.Fetch(obs.Type); tmp.transform.position = pos; GameObject instance = Instantiate(tmp, road.transform); } }
public IEnumerator ShootBullet() { GetComponent <AudioSource>().Play(); Vector2Int bulletPosition = position; for (int i = 0; i < Globals.BULLET_RANGE; i++) { bulletPosition += direction; var obstacle = ObstacleMap.ObstacleIn(bulletPosition); if (obstacle != null && obstacle.GetComponent <ICannonBulletTarget>() != null) { print("Cannon Bullet Start at <" + position.x + "," + position.y + "> until reaches <" + bulletPosition.x + "," + bulletPosition.y + ">"); break; } } var bullet = Instantiate(cannonBulletPrefab, transform.position, Quaternion.identity); yield return(bullet.GetComponent <CannonBullet>().Shoot(position, bulletPosition)); }
private void SwapBarrelForRaft() { var mapBuilder = FindObjectOfType <MapBuilder>(); foreach (var o in horizontalBarrelsOnWater) { GameObject obj = ObstacleMap.ObstacleIn(new Vector2Int((int)o.x, (int)o.y)).gameObject; ObstacleMap.obstacles.Remove(new Vector2Int((int)o.x, (int)o.y)); Destroy(obj); } foreach (var o in verticalBarrelsOnWater) { GameObject obj = ObstacleMap.ObstacleIn(new Vector2Int((int)o.x, (int)o.y)).gameObject; ObstacleMap.obstacles.Remove(new Vector2Int((int)o.x, (int)o.y)); Destroy(obj); } mapBuilder.CreateObstacle(mapBuilder.horizontalRaft, horizontalBarrelsOnWater); mapBuilder.CreateObstacle(mapBuilder.verticalRaft, verticalBarrelsOnWater); }
public void AddObstacles(ObstacleMap obstacleMap) { if (obstacleMap == null) { throw new ArgumentNullException(); } foreach (var obstacle in obstacleMap.Obstacles) { var shape = new Circular(obstacle.Radius); // Bouncy balls are made from rubber. Body body = m_physicsEngine.AddImmobileBody(shape, obstacle.Position, "BouncyBall"); body.Position = obstacle.Position; TireObstacle tire = new TireObstacle(body); m_obstacles.Add(tire); _collisionEngine.AddImmobileBody(body); } }
public void BuildMap() { Clear(); ObstacleMap.ResetMap(); LevelMap levelMap = LevelManager.GetCurrentLevelData().map; DrawFloor(groundTile, levelMap.ground); DrawFloor(waterTile, levelMap.borders); CreateObstacle(horizontalBarrel, levelMap.horizonalBarrel); CreateObstacle(verticalBarrel, levelMap.verticalBarrel); CreateObstacle(woodenBox, levelMap.woodenBox); CreateObstacle(pointyRocks, levelMap.pointyRocks); CreateObstacle(verticalRaft, levelMap.verticalRaft); CreateObstacle(horizontalRaft, levelMap.horizontalRaft); CreateCannon(levelMap.upCannon, CannonType.UP); CreateCannon(levelMap.downCannon, CannonType.DOWN); CreateCannon(levelMap.leftCannon, CannonType.LEFT); CreateCannon(levelMap.rightCannon, CannonType.RIGHT); CreateTreasures(); }
/// <summary> /// Public constructor /// </summary> /// <param name="cartographer">Instance of the cartographer</param> /// <param name="eyetribeConnected">Whether an EyeTribe is connected</param> /// <param name="controllerConnected">Whether an Xbox 360 controller is connected</param> public MainWindow(Pose pose, ObstacleMap obstacleMap, ICartographer cartographer = null, INavigator nav = null, IDoorDetector doorDetector = null, OverlayRenderer overlayRenderer = null, bool eyetribeConnected = false, bool controllerConnected = false, SensorArray senorArray = null) { //Only done here because it is passed to this function Data.EyeTribeConnected = eyetribeConnected; Data.XboxConnected = controllerConnected; Data.Cartographer = cartographer; Data.Navigator = nav; InitializeComponent(); this.doorsControl.DoorDetector = doorDetector; this.CurrentPose = pose; this.doorsControl.SensorInfo = senorArray; this.overlayRenderer = overlayRenderer; this.NavigationTab.SetPose(this.CurrentPose); ConfigureOverlays(); Input.Input.DeviceChanged += Input_DeviceChanged; }
public IEnumerator Walk() { transform.GetChild(0).GetComponent <PlayerAnimation>().ChangeAnimation(lookDirection); isWaiting = false; if (FindObjectOfType <GroundMap>().IsBorderTile(position + lookDirection)) { yield return(null); } if (ObstacleMap.ObstacleIn(position + lookDirection) == null) { if (FindObjectOfType <GroundMap>().IsSandTile(position + lookDirection)) { position += lookDirection; var targetPosition = new Vector3(position.x, position.y, 0); transform.DOMove(targetPosition + new Vector3(0.5f, 0.5f, 0) * Globals.TILE_SIZE, Globals.TIME_BETWEEN_TURNS); } else { ErrorHandling.AddError(new Error(Compiler.steps, "WALKING ON WATER")); transform.GetChild(2).GetComponent <PlayerErrorMessage>().ShowError(); } } else { if (ObstacleMap.ObstacleIn(position + lookDirection).OnPush(lookDirection)) { position += lookDirection; var targetPosition = new Vector3(position.x, position.y, 0); transform.DOMove(targetPosition + new Vector3(0.5f, 0.5f, 0) * Globals.TILE_SIZE, Globals.TIME_BETWEEN_TURNS); } else { ErrorHandling.AddError(new Error(Compiler.steps, "PUSHING OBSTACLE")); transform.GetChild(2).GetComponent <PlayerErrorMessage>().ShowError(); } } yield return(null); }
static void Main() { //change the test file xml here and make sure it is in bin. string startingXMLFile = "ETRL_03_07.xml"; //string startingXMLFile = "FloorPlanTest.xml"; //string startingOpenFile = "Sloan46_FINAL.xml"; double compassToMapOffset = 72.0; // List of all the objects we'll be initializing. // Default to null, as some of them will only // be initialized conditionally e.g. // vehicle is only initialized if // there is a vehicle connected. SerialPort sp = null; IVehicle vehicle = null; IImageStream depthStream = null; IImageStream videoStream = null; IObstacleDetector obstacleDetector = null; ICartographer cartographer = null; IOdometer odometer = null; IInputDevice input = KeyboardInput.Instance; ObstacleMap obstacleMap = null; INavigator navigator = null; MainWindow mainWindow = null; Driver.Driver driver = null; VisualInputGridPresenter uiInputPresenter = null; ObstacleGridPresenter uiGridPresenter = null; PositioningSystem ips = null; OverlayRenderer overlayRenderer = null; SensorArray sensorArray = null; Pose pose = null; IDoorDetector doorDetector = null; ObstacleLocalizer obstacleLocalizer = null; SonarDetector sonarDetector = null; Config.Initialize(); Devices.Initialize(); //string wheelchair_com_port = Devices.IsWheelchairConnected(); string wheelchair_com_port = "COM3";//Devices.FindComPort("Arduino Uno"); bool WheelChairConnected = false; if (wheelchair_com_port != "") { WheelChairConnected = true; } //bool WheelChairConnected = true; bool EyeTribeConnected = true; // Devices.IsEyeTribeConnected(); bool ControllerConnected = true; //Devices.IsControllerConnected(); bool KinectConnected = true; //Devices.IsKinectConnected(); //Console.WriteLine("Kinect Connected: {0}", KinectConnected.ToString()); //Console.WriteLine("Eyetribe Connected: {0}", EyeTribeConnected.ToString()); //Console.WriteLine("Wheelchair Connected: {0}", WheelChairConnected.ToString()); //Console.WriteLine("Controller Connected: {0}", ControllerConnected.ToString()); // Initialize vehicle and serial connection if // there is a vehicle connected. if (WheelChairConnected) { //sp = new SerialPort(wheelchair_com_port, 9600); vehicle = Wheelchair.Instance(wheelchair_com_port); vehicle.initializeOffset(Properties.Settings.Default.CalibrationOffset); } else { vehicle = new MockVehicle(); MockVehicleWindow mockDisplay = new MockVehicleWindow((MockVehicle)vehicle); mockDisplay.Show(); } //initalize IPS here IByteReader sensorReader = null; try { //sensorReader = new SerialByteReader("Arduino Mega"); sensorReader = new SerialByteReader("COM4"); } catch (Exception e) { MessageBox.Show(e.Message); } if (sensorReader != null) { ILogger logger = new NullLogger(); sensorArray = new SensorArray(sensorReader, logger); sonarDetector = new SonarDetector(); } else { sensorReader = new NullByteReader(); ILogger logger = new NullLogger(); sensorArray = new SensorArray(sensorReader, logger); } IByteReader byteReader = null; try { //byteReader = new SerialByteReader(Devices.FindComPort("STMicroelectronics")); byteReader = new SerialByteReader("COM3"); } catch (Exception e) { MessageBox.Show(e.Message); } if (byteReader != null) { ILogger logger = new NullLogger(); ips = new MarvelMind(byteReader, logger); } else { //Setup Mock IPS //IByteReader mockByteReader = new FileByteReader(@"C:\Users\Dana\Documents\Visual Studio 2013\Projects\UITests\UITests\Mock_IPS_Data.txt"); //IByteReader mockByteReader = new XLineFixedYByteReader(800, 100, 200); IByteReader mockByteReader = new RandomByteReader(300, 299); ILogger mockLogger = new NullLogger(); ips = new MarvelMind(mockByteReader, mockLogger); } //wait for an iteration of the IPS system that way //we can get the starting location while (false == ips.XUpdated && false == ips.YUpdated) { continue; } //Tuple<double, double> t = new Tuple<double, double>((double)ips.X, (double)ips.Y); Tuple <double, double> t = new Tuple <double, double>((double)ips.Y, (double)ips.X); mPoint startingLocationInXY = new mPoint(t); // UI, input, object detection, navigation, and driver are initialized always, // as they are not directly dependent on external hardware. obstacleMap = new ObstacleMap(); //cartographer = new Cartographer(Directory.GetCurrentDirectory() + @"\FloorPlanTest.xml", ips); // might need to be changed later. If the location is not in the starting room. add staring room. //cartographer = new Cartographer(Directory.GetCurrentDirectory() + @"\FloorPlanTest.xml", startingLocationInXY); OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "XML | *.xml"; ofd.Title = "Open Map"; if (ofd.ShowDialog() == true) { startingXMLFile = ofd.FileName; Console.WriteLine(startingXMLFile); } cartographer = new Cartographer(startingXMLFile, startingLocationInXY); pose = new Pose(ips, cartographer.GetStartingRoom(), sensorArray.CompassDevice, compassToMapOffset); overlayRenderer = new OverlayRenderer(); if (KinectConnected) { depthStream = DepthStream.Instance; videoStream = VideoStream.Instance; // Initialize depthstream if kinect is connected. obstacleDetector = new ObstacleDetector(depthStream, false); obstacleDetector.Start(); obstacleLocalizer = new ObstacleLocalizer(pose); ObstaclesOverlay obstaclesOverlay = new ObstaclesOverlay(obstacleDetector); overlayRenderer.Overlays.Add(obstaclesOverlay); doorDetector = new DepthBasedDoorDetector(); doorDetector.RunAsync(depthStream); try { sonarDetector.RunAsync(sensorArray); } catch (Exception e) { } } // Obstacle detector and driver are only run // if both the vehicle and kinect are connected. if (vehicle != null && KinectConnected) { Vector startPoint = new Vector(7 / 0.75f, 43 / 0.75f); Vector startRotation = new Vector(-7, -43); startRotation.Normalize(); odometer = new Odometer(); navigator = new Navigator(obstacleMap, obstacleDetector, obstacleLocalizer, cartographer, doorDetector, pose, sonarDetector, sensorArray); driver = new Driver.Driver(input, vehicle, navigator); driver.Start(); } mainWindow = new MainWindow(pose, obstacleMap, cartographer, navigator, doorDetector, overlayRenderer, EyeTribeConnected, ControllerConnected, sensorArray); uiInputPresenter = new VisualInputGridPresenter(mainWindow.visualInputGrid); //This starts the program. Application app = new Application(); app.ShutdownMode = ShutdownMode.OnMainWindowClose; app.MainWindow = mainWindow; app.MainWindow.Show(); app.Run(); }
/// <summary> /// Aktualisiert die View, d.h. es wird in ein Bitmap gezeichnet und /// anschliessend das Bitmap in der PictureBox dargestellt. /// Folgende Objekte werden gezeichnet: /// - Hindernis /// - Koordinaten-Netz /// - Roboter /// - Radar /// </summary> private void UpdateView() { lock (lockObj) { // Verhindert Exception falls Fenster auf 0 verkleinert wird. if (pictureBox.Width == 0 || pictureBox.Height == 0) { return; } // Verhindert Designer-Absturz falls ViewPort auf 0 gesetzt wird. if (_viewPort.Width == 0 || _viewPort.Height == 0) { return; } // Bitmap erstellen auf das die WorldView gezeichnet werden kann if ((_plot == null) || (_plot.Size != pictureBox.Size)) { _plot = new Bitmap(pictureBox.Width, pictureBox.Height); } using (Graphics g = Graphics.FromImage(_plot)) { // Hintergrund löschen g.Clear(Color.White); ObstacleMap obstMap = World.ObstacleMap; if (World.ObstacleMap != null) { Bitmap bmp = obstMap.Image; RectangleF area = obstMap.Area; int rx1 = XtoScreen(area.Left); int ry1 = YtoScreen(area.Bottom); int rx2 = XtoScreen(area.Right); int ry2 = YtoScreen(area.Top); g.DrawImage( World.ObstacleMap.Image, new Rectangle(rx1, ry1, rx2 - rx1, ry2 - ry1), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel); } #region Koordinaten-Netz zeichnen // Vertikale Linien die >viewPort.xMin bzw. <viewPort.xMax sind zeichnen... double y = _viewPort.yMin - (_viewPort.yMin % 0.5); for (; y < _viewPort.yMax; y += .5d) { int yScreen = YtoScreen(y); g.DrawLine((y == 0d ? _penGrid1 : _penGrid2), 0, yScreen, Width, yScreen); g.DrawString(y.ToString(CultureInfo.InvariantCulture), _font, _fontBrush, 5, yScreen + 3); } // Horizontale Linien >viewPort.yMin bzw. <viewPort.yMax sind zeichnen... double x = _viewPort.xMax - (_viewPort.xMax % 0.5); for (; x > _viewPort.xMin; x -= .5d) { int xScreen = XtoScreen(x); g.DrawLine((x == 0d ? _penGrid1 : _penGrid2), xScreen, 0, xScreen, Height); g.DrawString(x.ToString(CultureInfo.InvariantCulture), _font, _fontBrush, xScreen + 3, 5); } #endregion Robot robot = World.Robot; if (robot != null) { #region Roboter zeichnen var pos = robot.Drive.Position; if (_drivedPoints.Last == null || _drivedPoints.Last.Value != pos) { _drivedPoints.AddLast(pos); } double phi = pos.Angle / 180 * Math.PI; foreach (var positionInfo in _parkedSpot) { int width = WidthToScreen(.14f * 1.25f); int height = HeightToScreen(.14f * 1.25f); g.FillEllipse(_brushPark, XtoScreen(positionInfo.X) - width / 2, YtoScreen(positionInfo.Y) - height / 2, width, height); } // Draw Points foreach (var drivedPoint in _drivedPoints) { g.FillEllipse(_brushRun, XtoScreen(drivedPoint.X), YtoScreen(drivedPoint.Y), 5, 5); } // Roboter.Radar PositionInfo radarOffset = robot.Radar.AntennaPosition; PositionInfo radarPos = new PositionInfo( pos.X + radarOffset.X * (float)Math.Cos(phi) - radarOffset.Y * (float)Math.Sin(phi), pos.Y + radarOffset.X * (float)Math.Sin(phi) + radarOffset.Y * (float)Math.Cos(phi), (pos.Angle + radarOffset.Angle) % 360); double radarPhi = radarPos.Angle / 180.0 * Math.PI; double distance = robot.Radar.Distance; // Radarstrahl zeichnen... g.DrawLine(_penRadar, XtoScreen(radarPos.X), YtoScreen(radarPos.Y), XtoScreen(radarPos.X + distance * Math.Cos(radarPhi)), YtoScreen(radarPos.Y + distance * Math.Sin(radarPhi))); g.FillEllipse(BrushRobot, XtoScreen(pos.X - .07f), YtoScreen(pos.Y + .07f), WidthToScreen(.14f), HeightToScreen(.14f)); int xScreen = XtoScreen(pos.X); int yScreen = YtoScreen(pos.Y); g.DrawLine(_penAngle, xScreen, yScreen, xScreen + WidthToScreen((float)(.07f * Math.Cos(phi))), yScreen + HeightToScreen((float)(-.07f * Math.Sin(phi)))); #endregion } } pictureBox.Image = _plot; } }
public void ReplaceObstacles(ObstacleMap obstacleMap) { ClearObstacles(); AddObstacles(obstacleMap); }
private IEnumerator Execution(List <Program> programs) { HideOnExecution(true); steps = 0; yield return(null); TreasureMap.LoadMap(); ResetPlayer(); while (programs.Count > 0) { ErrorHandling.ResetError(); steps++; horizontalBarrelsOnWater = new List <Vector2>(); verticalBarrelsOnWater = new List <Vector2>(); if (AllFlagsRised()) { foreach (var p in FindObjectsOfType <Player>()) { yield return(p.DropFlag()); } } foreach (var e in ObstacleMap.obstacles) { yield return(e.Value.TurnStart()); } int playerIndex = GetRandomPlayerWithFlagNotRised(programs); FindObjectOfType <BlockFitter>().ShowBlock(programs[playerIndex].length - steps); CameraMovement.MoveTo(programs[playerIndex].player.position); yield return(programs[playerIndex].blocks[0].Execute(programs[playerIndex].player)); programs[playerIndex].blocks.Remove(programs[playerIndex].blocks[0]); if (programs[playerIndex].blocks.Count == 0) { programs.Remove(programs[playerIndex]); } foreach (var e in ObstacleMap.obstacles) { yield return(e.Value.TurnUpdate()); } yield return(new WaitForSeconds(Globals.TIME_BETWEEN_TURNS)); ObstacleMap.FixDictionary(); SwapBarrelForRaft(); if (ErrorHandling.errors.Count > 0) { break; } } HideOnExecution(false); yield return(new WaitForSeconds(1f)); if (TreasureMap.FinishLevel()) { yield return(endLevelPanel.OpenPanel(TreasureMap.GetTreasureInfo(), steps)); } else { FindObjectOfType <MapBuilder>().BuildMap(); ResetPlayer(); } }