Esempio n. 1
0
        public void Initialize(Map.Map map)
        {
            var collision = new CollisionMap(map);

            if (_world == null)
            {
                _world = new World(new Vector2(0, 0));
            }
            else
            {
                _world.Clear();
            }

            var obstacles       = collision.GetObstacles();
            var layer2Obstacles = obstacles.GetObstacles(2);

            foreach (var obstacle in layer2Obstacles)
            {
                var body = new Body(_world)
                {
                    BodyType = BodyType.Static
                };
                _json.SetName(body, "Building" + obstacle.Z);
                Shape   shape;
                Fixture fixture;
                switch (obstacle.Type)
                {
                case ObstacleType.Line:
                    var lineObstacle = (LineObstacle)obstacle;
                    shape   = new EdgeShape(lineObstacle.Start.ToMeters(), lineObstacle.End.ToMeters());
                    fixture = body.CreateFixture(shape);
                    _json.SetName(fixture, "Building" + obstacle.Z);
                    break;

                case ObstacleType.Polygon:
                    var polygonObstacle = (PolygonObstacle)obstacle;
                    var convexPolygons  = BayazitDecomposer.ConvexPartition(polygonObstacle.Vertices);
                    foreach (var convexPolygon in convexPolygons)
                    {
                        shape   = new PolygonShape(convexPolygon.ToMeters(), 1);
                        fixture = body.CreateFixture(shape);
                        _json.SetName(fixture, "Building" + obstacle.Z);
                    }
                    break;

                case ObstacleType.Rectangle:
                    var rectangleObstacle = (RectangleObstacle)obstacle;
                    shape   = new PolygonShape(rectangleObstacle.Vertices.ToMeters(), 1);
                    fixture = body.CreateFixture(shape);
                    _json.SetName(fixture, "Building" + obstacle.Z);
                    break;
                }
            }
        }
Esempio n. 2
0
        private static void DebugObstacles()
        {
            try
            {
                var map = new Map.Map(Globals.MapsSubDir + "\\MP1-comp.gmp", "bil");
                //var map = new Map.Map(Globals.MapsSubDir + "\\bil.gmp");
                var collision = new CollisionMap(map);
                var obstacles = collision.GetObstacles();
                //obstacles.Save(map);
                //var newObstacles = ObstacleCollection.Load(map);

                DisplayCollision(obstacles);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.StackTrace);
            }
        }