Exemple #1
0
 /// <summary>
 /// From absolute position in pixels to side of tile = 1
 /// </summary>
 /// <param name="tmxObject"></param>
 /// <param name="tileWidth"></param>
 /// <param name="tileHeight"></param>
 /// <param name="worldHeight"></param>
 private static void NormalizeObjectPosition(TmxObject tmxObject, int tileWidth, int tileHeight, int worldHeight)
 {
     tmxObject.X /= tileWidth;
     tmxObject.Y /= tileHeight;
     tmxObject.Y = worldHeight - tmxObject.Y;
     tmxObject.Width /= tileWidth;
     tmxObject.Height /= tileHeight;
     tmxObject.Rotation = -MathHelper.ToRadians(tmxObject.Rotation);
 }
Exemple #2
0
 /// <summary>
 /// Transforms from rotation around left lower corner to rotation around center
 /// </summary>
 /// <param name="tmxObject"></param>
 private static void TransformObjectPosition(TmxObject tmxObject)
 {
     Vector2 rotationCenter = new Vector2(tmxObject.X, tmxObject.Y);
     Vector2 size = new Vector2(tmxObject.Width / 2, tmxObject.Height / 2);
     Vector2 newPosition = RotateAroundCenter(rotationCenter + size, rotationCenter, tmxObject.Rotation);
     tmxObject.X = newPosition.X;
     tmxObject.Y = newPosition.Y;
 }
Exemple #3
0
        private static Avatar LoadAgent(TmxObject avatar, List<Tileset> tilesets)
        {
            var initialPosition = new Vector2(avatar.X, avatar.Y);
            var size = new Vector2(avatar.Width, avatar.Height);
            float rotation = avatar.Rotation;

            int originalGid = avatar.Gid;
            Tuple<string, int> nameNewGid = TilesetNameFromGid(tilesets, originalGid);
            string tilesetName = nameNewGid.Item1;
            int newGid = nameNewGid.Item2;

            var gameAvatar = new Avatar(tilesetName, newGid, avatar.Name, avatar.Id, initialPosition, size, rotation);

            // this is magic
            if (avatar.Properties != null)
            {
                SetGameObjectProperties(avatar.Properties.PropertiesList, gameAvatar);
            }

            return gameAvatar;
        }
Exemple #4
0
        private static Character LoadCharacter(TmxObject tmxObject, List<Tileset> tilesets)
        {
            var initialPosition = new Vector2(tmxObject.X, tmxObject.Y);
            var size = new Vector2(tmxObject.Width, tmxObject.Height);
            float rotation = tmxObject.Rotation;

            int originalGid = tmxObject.Gid;
            Tuple<string, int> nameNewGid = TilesetNameFromGid(tilesets, originalGid);
            string tilesetName = nameNewGid.Item1;
            int newGid = nameNewGid.Item2;

            Type objectType = Type.GetType("World.GameActors.GameObjects." + tmxObject.Type);

            if (objectType == null)
            {
                throw new ArgumentException("MapLoader cannot find \"" + tmxObject.Type + "\" class.");
            }

            var gameObject = (Character)Activator.CreateInstance(
                objectType,
                tilesetName,
                newGid,
                tmxObject.Name,
                initialPosition,
                size,
                rotation
                );

            // this is magic
            if (tmxObject.Properties != null)
            {
                SetGameObjectProperties(tmxObject.Properties.PropertiesList, gameObject);
            }

            return gameObject;
        }
Exemple #5
0
 private static IEnumerable<Vector2> PolylineTransform(Map map, TmxObject polyline)
 {
     float tilewidth = map.Tilewidth;
     float tileheight = map.Tileheight;
     float polX = polyline.X;
     float polY = polyline.Y;
     foreach (Vector2 point in polyline.Polyline.GetPoints())
     {
         yield return new Vector2(polX + point.X / tilewidth, polY - point.Y / tileheight);
     }
 }