Exemplo n.º 1
0
 public Cluster(ClusterType type, int x, int y)
 {
     Type = type;
       tiles = new Tile[Constants.ClusterWidth * Constants.ClusterHeight];
       Active = false;
       Coordinates = new Coordinates(x, y);
       HashCode = GetHashCode();
 }
Exemplo n.º 2
0
        public Cluster(ClusterData data)
        {
            Type = data.Type;
              tiles = data.Tiles;
              Coordinates = data.Coordinates;

              SetHashCode();
              Active = false;
        }
        public void LoadCluster(Coordinates coordinates)
        {
            if (loadList.Exists(delegate(Coordinates c)
              {
            return c == coordinates;
              }))
            return;

              Debug.WriteLine(string.Format("Loading ({0}, {1}).", coordinates.X, coordinates.Y));
              loadList.Add(coordinates);
              if (loadThread.IsAlive == false)
              {
            StartLoading();
              }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Insert a cluster at the given coordinates in cluster space.
        /// </summary>
        /// <param name="clusterCoordinates"></param>
        private static void AddCluster(World world, Coordinates clusterCoordinates)
        {
            Cluster cluster = new Cluster(ClusterType.Evergreen, clusterCoordinates);

              Matrix clusterOffset = Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, 0));

              Matrix tileTranslate =
            /*TilePositionTransform **/
            TileClusterTransform *
            clusterOffset *
            ClusterTileTransform
            ;

              for (int y = 0; y < Constants.ClusterHeight; ++y)
              {
            for (int x = 0; x < Constants.ClusterWidth; ++x)
            {
              Vector2 tilePos = Vector2.Transform(new Vector2(x, y), tileTranslate);

              Tile t = cluster.GetTileAt(x, y);
              t.Type = TileType.Grass;
              cluster.SetTileAt(x, y, t);
            }
              }

              world.AddCluster(cluster);
        }
Exemplo n.º 5
0
        //public void InsertCluster(Cluster cluster)
        //{
        //  InsertCluster(cluster);
        //}
        private void GetClusterDataFromRow(DataRow row, out ClusterData data)
        {
            byte[] bytes = (byte[])row["data"];
              //using (MemoryStream memStream = new MemoryStream(bytes))
              //{
              //  memStream.Seek(0, SeekOrigin.Begin);
              //  data = (ClusterData)serializer.Deserialize(memStream);
              //  memStream.Close();
              //}

              const int clusterLength = Constants.ClusterWidth * Constants.ClusterHeight;

              data = new ClusterData();
              data.Tiles = new Tile[clusterLength];

              // Get huffman encoded tile data.
              using (MemoryStream stream = new MemoryStream(bytes))
              {
            data.Type = (ClusterType)stream.ReadByte();
            int tileIndex = 0;
            while (tileIndex < clusterLength)
            {
              //stream.Seek(streamIndex, SeekOrigin.End);
              TileType type = (TileType)stream.ReadByte();

              byte[] intCounter = new byte[4];

              for (int i = 0; i < 4; ++i)
            intCounter[i] = (byte)stream.ReadByte();

              int tileCount = BitConverter.ToInt32(intCounter, 0);

              for (int i = 0; i < tileCount; ++i)
              {
            data.Tiles[tileIndex++] = new Tile(type);
              }
            }
              }

              //for (int i = 1; i < clusterLength + 1; ++i)
              //{
              //  data.Tiles[i - 1] = new Tile((TileType)bytes[i]);
              //}

              Coordinates coords = new Coordinates();
              coords.X = BitConverter.ToInt32(bytes, bytes.Length - 8);
              coords.Y = BitConverter.ToInt32(bytes, bytes.Length - 4);
              data.Coordinates = coords;
        }
Exemplo n.º 6
0
 public Cluster(ClusterType type, Coordinates coordinates)
     : this(type, coordinates.X, coordinates.Y)
 {
 }
Exemplo n.º 7
0
 /// <summary>
 /// Retrieves the tile at the input coordinates relative
 /// to the cluster.
 /// </summary>
 private Tile GetTileAt(Coordinates coord)
 {
     return GetTileAt(coord.X, coord.Y);
 }
Exemplo n.º 8
0
 public void SetTileAt(Coordinates coord, Tile newTile)
 {
     SetTileAt(coord.X, coord.Y, newTile);
 }
Exemplo n.º 9
0
        private bool IsInView(Coordinates clusterCoordinates)
        {
            Vector2 topLeft = new Vector2(Camera2D.Bounds.Left, Camera2D.Bounds.Top);
              Vector2 bottomRight = new Vector2(Camera2D.Bounds.Right, Camera2D.Bounds.Bottom);

              topLeft = WorldManager.TransformScreenToCluster(topLeft);
              bottomRight = WorldManager.TransformScreenToCluster(bottomRight);

              // Offsets are in cluster coordinates.
              if (clusterCoordinates.X + 0.5f >= topLeft.X &&
              clusterCoordinates.X - 0.5f <= bottomRight.X &&
              clusterCoordinates.Y - 0.5f <= bottomRight.Y &&
              clusterCoordinates.Y + 0.5f >= topLeft.Y)
              {
            return true;
              }

              return false;
        }
Exemplo n.º 10
0
 private void ClusterNotLoadedHandler(Coordinates coords)
 {
     loadedClusters.Push(CreateCluster(coords));
 }
Exemplo n.º 11
0
 public Cluster CreateCluster(Coordinates coordinates)
 {
     return CreateCluster(coordinates.X, coordinates.Y);
 }
Exemplo n.º 12
0
        private static bool Equals(Coordinates lhs, Coordinates rhs)
        {
            if (lhs.x == rhs.x && lhs.y == rhs.y)
              {
            return true;
              }

              return false;
        }