Exemplo n.º 1
0
        public MapCollider(IsometricMap map)
        {
            var collidersGroup = map.ObjectGroups["Colliders"];

            Colliders = new PolygonCollider[collidersGroup.Count];

            for (var i = 0; i < collidersGroup.Count; i++)
            {
                var obj = collidersGroup[i];

                var points = new Vector2[4];
                points[0] = new Vector2(obj.Position.X, obj.Position.Y);                          //Topleft
                points[1] = new Vector2(obj.Position.X + obj.Width, obj.Position.Y);              //Topright
                points[2] = new Vector2(obj.Position.X + obj.Width, obj.Position.Y + obj.Height); //BotRight
                points[3] = new Vector2(obj.Position.X, obj.Position.Y + obj.Height);             //BotLeft

                for (var o = 0; o < 4; o++)
                {
                    points[o] = Isometric.WorldToIsometricWorld(points[o], map);
                }

                Colliders[i] = new PolygonCollider(points);

                Colliders[i].SetShouldColliderScaleAndRotateWithTransform(true);
                //entity.addComponent<BoxCollider>(colliders[i]);
            }
        }
Exemplo n.º 2
0
        private PolygonColliderTrigger[] LoadColliders(IsometricMap map, string groupName)
        {
            var collidersGroup = map.ObjectGroups[groupName];
            var colliders      = new PolygonColliderTrigger[collidersGroup.Count];

            for (var i = 0; i < collidersGroup.Count; i++)
            {
                var obj = collidersGroup[i];

                var points = new Vector2[4];
                points[0] = new Vector2(obj.Position.X, obj.Position.Y);                          //Topleft
                points[1] = new Vector2(obj.Position.X + obj.Width, obj.Position.Y);              //Topright
                points[2] = new Vector2(obj.Position.X + obj.Width, obj.Position.Y + obj.Height); //BotRight
                points[3] = new Vector2(obj.Position.X, obj.Position.Y + obj.Height);             //BotLeft

                for (var o = 0; o < 4; o++)
                {
                    points[o] = Isometric.WorldToIsometricWorld(points[o], map);
                }

                colliders[i] = new PolygonColliderTrigger(points);
                colliders[i].SetShouldColliderScaleAndRotateWithTransform(false);


                //Finally check to see if it has a depth property before adding
                if (obj.Properties.TryGetValue("depth", out var depth))
                {
                    float.TryParse(depth, out var floatValue);
                    colliders[i].Depth = floatValue;
                }

                colliderEntity.AddComponent(colliders[i]);
            }
            return(colliders);
        }
Exemplo n.º 3
0
 public Vector2 ConvertCoordinatesToIsometricSpace(IsometricMap map)
 {
     WorldPosition = Isometric.WorldToIsometricWorld(Position, map);
     return(WorldPosition);
 }