Exemple #1
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x,y,z);

        GameObject newChunkObject = Instantiate(
            chunkPrefab, new Vector3(worldPos.x,worldPos.y,worldPos.z),
            Quaternion.Euler(Vector3.zero)
            ) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        newChunk.pos = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

        //bool loaded = Serialization.Load(newChunk);
        //if(loaded)
            //return;
        var terrainGen = new TerrainGen();
        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();
        bool loaded = Serialization.Load(newChunk);
    }
Exemple #2
0
    public void CreateChunk(int x, int y, int z) {
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(
                        chunkPrefab, new Vector3(x, y, z),
                        Quaternion.Euler(Vector3.zero)
                    ) as GameObject;
        Chunk newChunk = newChunkObject.GetComponent<Chunk>();
		newChunkObject.name = "Chunk: " + x/16f + ":" + y/16f + ":" + z/16f;
        newChunk.pos = worldPos;
        newChunk.world = this;

        //Add it to the chunks dictionary with the position as the key
        chunks.Add(worldPos, newChunk);

		bool HasLoadedChunk = false;


		if ((Network.isServer || (!Network.isServer && !Network.isClient)) && IsLoadChunks) 
			HasLoadedChunk = Serialization.Load(newChunk);
		if (!HasLoadedChunk) {
			newChunk = MyTerrainGen.ChunkGen(newChunk);
		}
		newChunk.transform.parent = gameObject.transform;
		newChunk.SetBlocksUnmodified();
		GetManager.GetZoneManager ().LoadZones (new Vector3 (x, y, z));
		DebugChunksLoadedCount++;
    }
    public void CreateChunk(int x, int y, int z)
    {
        //the coordinates of this chunk in the world
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(
                        chunkPrefab, new Vector3(worldPos.x, worldPos.y, worldPos.z),
                        Quaternion.Euler(Vector3.zero)
                    ) as GameObject;

        //Get the object's chunk component
        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        //Assign its values
        newChunk.pos = worldPos;
        newChunk.world = this;

        //Add it to the chunks dictionary with the position as the key
        chunks.Add(worldPos, newChunk);

        //now spawn me some test chunks!
        var terrainGen = new TerrainGen();
        newChunk = terrainGen.ChunkGen(newChunk);

           // newChunk.SetBlocksUnmodified();

        //bool loaded = Serialization.Load(newChunk);
    }
    public Chunk GetChunk(int x, int y, int z)
    {
        WorldPos pos = new WorldPos();
        float multiple = Chunk.chunkSize;
        pos.x = Mathf.FloorToInt(x / multiple ) * Chunk.chunkSize;
        pos.y = Mathf.FloorToInt(y / multiple ) * Chunk.chunkSize;
        pos.z = Mathf.FloorToInt(z / multiple ) * Chunk.chunkSize;

        Chunk containerChunk = null;

        chunks.TryGetValue(pos, out containerChunk);
        for (int xi = 0; xi < 16; xi++)
        {
            for (int yi = 0; yi < 16; yi++)
            {
                for (int zi = 0; zi < 16; zi++)
                {
                    if (yi <= 7)
                    {
                        SetBlock(x+xi, y+yi, z+zi, new BlockGrass());
                    }
                    else
                    {
                        SetBlock(x + xi, y + yi, z + zi, new BlockAir());
                    }
                }
            }
        }
        return containerChunk;
    }
Exemple #5
0
	// Update is called once per frame
	void Update() {	
		if (world != null) {
			world.ChunkLoader = this;
			TimeExisted += Time.deltaTime;
			if (TimeExisted - LastDeletedChunks > TimeCoolDown) {
				LastDeletedChunks = TimeExisted;
				// removes all excess chunks outside render range
				playerPos = new WorldPos(
					Mathf.FloorToInt(transform.position.x / Chunk.chunkSize) * Chunk.chunkSize,
					Mathf.FloorToInt(transform.position.y / Chunk.chunkSize) * Chunk.chunkSize,
					Mathf.FloorToInt(transform.position.z / Chunk.chunkSize) * Chunk.chunkSize
					);
				if (IsLoadOnce) {
					playerPos = new WorldPos(0,0,0);
				}
				//if (!IsLoadOnce)
				DeleteChunks ();
				// finds new chunks to load within the list
				//if (!IsLoadOnce)
				FindChunksToLoad ();
				// Loads new chunks and renders them
				LoadAndRenderChunks ();
			}
		
			DebugUpdateListSize = updateList.Count;
			DebugBuildListSize = buildList.Count;
		}
	}
Exemple #6
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(
                        chunkPrefab, new Vector3(x, y, z),
                        Quaternion.Euler(Vector3.zero)
                    ) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent<Chunk>(); //gets the script component

        newChunk.pos = worldPos; //rounds position to an int
        newChunk.world = this; //tells the chunk how to get back to mommy
        newChunk.tag = "breakable";

        //Add it to the chunks dictionary with the position as the key
        chunks.Add(worldPos, newChunk);

        TerrainGen terrainGen = new TerrainGen(); //this has some preset values for generating
        newChunk = terrainGen.ChunkGen(newChunk); //this runs the generation code

        newChunk.SetBlocksUnmodified(); //this tells Serialization not to save as there was no changes

        Serialization.Load(newChunk);
    }
Exemple #7
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(
                        chunkPrefab, new Vector3(x, y, z),
                        Quaternion.Euler(Vector3.zero)
                    ) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        newChunk.pos = worldPos;
        newChunk.world = this;

        //Add it to the chunks dictionary with the position as the key
        chunks.Add(worldPos, newChunk);

        var terrainGen = new TerrainGen();
        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlocksUnmodified();

        Serialization.Load(newChunk);
    }
Exemple #8
0
 void BuildChunk(WorldPos pos)
 {
     if (world.GetChunk(pos.x,pos.y,pos.z) == null)
     {
     world.CreateChunk(pos.x,pos.y,pos.z);
     }
 }
Exemple #9
0
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(
                        chunkPrefab, new Vector3(x, y, z),
                        Quaternion.Euler(Vector3.zero)
                    ) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        newChunk.pos = worldPos;
        newChunk.world = this;

        //Add it to the chunks dictionary with the position as the key
        chunks.Add(worldPos, newChunk);

        // Initializes Chunk with top block layer only - creates ground

        for (int xi = 0; xi < 16; xi++)
        {
            for (int yi = 0; yi < 16; yi++)
            {
                for (int zi = 0; zi < 16; zi++)
                {
                    SetBlock(x + xi, y + yi, z + zi, new BlockAir());
                }
            }
        }

        newChunk.SetBlocksUnmodified();

        Serialization.Load(newChunk);
    }
Exemple #10
0
 // Takes a WorldPos and answers with list of shapes at that position
 public List<Shape> shapesAtPos(WorldPos pos)
 {
     if (posDictionary.ContainsKey(pos))
     {
         return posDictionary[pos];
     }
     return new List<Shape>();
 }
Exemple #11
0
    public static WorldPos GetBlockPos(Vector3 pos)
    {
        WorldPos blockPos = new WorldPos(Mathf.RoundToInt(pos.x),
                                         Mathf.RoundToInt(pos.y),
                                         Mathf.RoundToInt(pos.z));

        return blockPos;
    }
Exemple #12
0
	public void AddChunkPositions(int Max) {
		for (int i = -Max; i <= Max; i++)
			for (int k = -Max; k <= Max; k++)
		{
			WorldPos NewPos = new WorldPos(i,0,k);
			if (!IsInChunkList(NewPos))
				ChunkPositions.Add (NewPos);
		}
	}
Exemple #13
0
	public bool IsInChunkList(WorldPos NewChunkPos) {
		for (int i = 0; i < ChunkPositions.Count; i++) {
			if (NewChunkPos.x == ChunkPositions[i].x && 
			    NewChunkPos.y == ChunkPositions[i].y && 
			    NewChunkPos.z == ChunkPositions[i].z)
				return true;
		}
		return false;
	}
Exemple #14
0
 public void CreateChunk(int x, int y, int z)
 {
     WorldPos worldPos = new WorldPos(x, y, z);
     //if(pending.Count > 0)
     //{
         Chunk c = Instantiate(chunk, worldPos.ToVector() - new Vector3(chunkSize / 2f, chunkSize / 2f, chunkSize / 2f), new Quaternion()) as Chunk;
         c.transform.parent = transform;
         chunks.Add(worldPos, c);
     //}
 }
    public Chunk ChunkColumnGen(Chunk chunk, int x, int z)
    {
        /*int stoneHeight = Mathf.FloorToInt (stoneBaseHeight);
        stoneHeight += GetNoise (x, 0, z, stoneMountainFrequency, Mathf.FloorToInt (stoneMountainHeight));

        if (stoneHeight < stoneMinHeight)
            stoneHeight = Mathf.FloorToInt (stoneMinHeight);

        stoneHeight += GetNoise (x, 0, z, stoneBaseNoise, Mathf.FloorToInt (stoneBaseNoiseHeight));

        int dirtHeight = stoneHeight + Mathf.FloorToInt (dirtBaseHeight);
        dirtHeight += GetNoise (x, 100, z, dirtNoise, Mathf.FloorToInt (dirtNoiseHeight));

        for (int y = 0; y < Chunk.chunkHeight; y++)
        {
            if (y <= stoneHeight)
            {
                chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new Block ());
            } else if (y <= dirtHeight)
            {
                chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockGrass ());
            } else
            {
                chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockAir ());
            }
        }*/

        //*********************
        Random.seed = chunk.world.seed;
        Vector3 offSet0 = new Vector3 (Random.value * 10000, Random.value * 10000, Random.value * 10000);
        Vector3 offSet1 = new Vector3 (Random.value * 10000, Random.value * 10000, Random.value * 10000);
        Vector3 offSet2 = new Vector3 (Random.value * 10000, Random.value * 10000, Random.value * 10000);

        for (int y = 0; y < Chunk.chunkHeight; y++)
        {
            WorldPos pos = new WorldPos (x, y, z);

            float noiseValue = CalculateNoiseValue (pos, offSet0, 0.03f);
            noiseValue += CalculateNoiseValue (pos, offSet1, 0.02f);
            noiseValue += CalculateNoiseValue (pos, offSet2, 0.005f);
            noiseValue += (20 - y) / 10f;
            if (noiseValue < 0.08f)
            {
                chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockAir ());
            } else if (noiseValue < 0.3f)
            {
                chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockGrass ());
            } else
            {
                chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockStone ());
            }
        }

        return chunk;
    }
Exemple #16
0
    public Chunk GetChunk(int x, int y, int z)
    {
        WorldPos pos = new WorldPos();
        float multiple = Chunk.chunkSize;
        pos.x = Mathf.FloorToInt(x / multiple) * Chunk.chunkSize;
        pos.y = Mathf.FloorToInt(y / multiple) * Chunk.chunkSize;
        pos.z = Mathf.FloorToInt(z / multiple) * Chunk.chunkSize;

        Chunk containerChunk = null;
        chunks.TryGetValue(pos, out containerChunk);

        return containerChunk;
    }
	void FindChunksToLoad()
	{
		//Get the position of this gameobject to generate around
		WorldPos playerPos = new WorldPos(
			Mathf.FloorToInt(transform.position.x / Chunk.chunkSize) * Chunk.chunkSize,
			Mathf.FloorToInt(transform.position.y / Chunk.chunkSize) * Chunk.chunkSize,
			Mathf.FloorToInt(transform.position.z / Chunk.chunkSize) * Chunk.chunkSize
			);
		
		//If there aren't already chunks to generate
		if (updateList.Count == 0)
		{
			//Cycle through the array of positions
			for (int i = 0; i < chunkPositions.Length; i++)
			{
				//translate the player position and array position into chunk position
				WorldPos newChunkPos = new WorldPos(
					chunkPositions[i].x * Chunk.chunkSize + playerPos.x,
					0, 
					chunkPositions[i].z * Chunk.chunkSize + playerPos.z
					);
				
				//Get the chunk in the defined position
				Chunk newChunk = world.GetChunk(newChunkPos.x, newChunkPos.y, newChunkPos.z);
				
				//If the chunk already exists and it's already
				//rendered or in queue to be rendered continue
				if (newChunk != null
				    && (newChunk.rendered || updateList.Contains(newChunkPos)))
					continue;
				
				//load a column of chunks in this position
				//load a column of chunks in this position
				for (int y = -4; y < 4; y++)
				{
					
					for (int x = newChunkPos.x - Chunk.chunkSize; x <= newChunkPos.x + Chunk.chunkSize; x += Chunk.chunkSize)
					{
						for (int z = newChunkPos.z - Chunk.chunkSize; z <= newChunkPos.z + Chunk.chunkSize; z += Chunk.chunkSize)
						{
							buildList.Add(new WorldPos(x, y * Chunk.chunkSize, z));
						}
					}
					updateList.Add(new WorldPos(newChunkPos.x, y * Chunk.chunkSize, newChunkPos.z));
				}

				return;
			}
		}
	}
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y , z);

        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z),Quaternion.Euler(Vector3.zero)) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        newChunk.pos = worldPos;
        newChunk.world = this;

        //Adds to dictionary
        chunks.Add(worldPos, newChunk);
    }
    public static void SetBlock(int x, int y, int z, Block block, Chunk chunk, bool replaceBlocks = false)
    {
        x -= chunk.pos.x;
        y -= chunk.pos.y;
        z -= chunk.pos.z;

        if (Chunk.InRange(x) && Chunk.InRange(y) && Chunk.InRange(z))
        {
            if (replaceBlocks || chunk.blocks[x, y, z] == null)
            {
                WorldPos pos = new WorldPos();
                pos.x = x; pos.y = y; pos.z =z;
                chunk.SetBlock(x, y, z, block);
            }
        }
    }
        public void assignVoxel(World thisworld, WorldPos position, int number)
        {
            prime = thisworld.GetBlock(position.x,position.y,position.z);

            corner = (handledirection) number;

            pos.x = position.x;
            pos.y = position.y;
            pos.z = position.z;
            offx = prime.offx;
            offy = prime.offy;
            offz = prime.offz;
            transform.position = Camera.main.WorldToScreenPoint(new Vector3 (pos.x+offx, pos.y+offy, pos.z+offz));

            setupHandle (number);
        }
    void BuildChunk(WorldPos pos)
    {
        for (int y = pos.y - Chunk.chunkSize; y <= pos.y + Chunk.chunkSize; y += Chunk.chunkSize)
        {
            for (int x = pos.x - Chunk.chunkSize; x <= pos.x + Chunk.chunkSize; x += Chunk.chunkSize)
            {
                for (int z = pos.z - Chunk.chunkSize; z <= pos.z + Chunk.chunkSize; z += Chunk.chunkSize)
                {
                    if (world.GetChunk(x, y, z) == null)
                        world.CreateChunk(x, y, z);
                }
            }
        }

        updateList.Add(pos);
    }
Exemple #22
0
    public Save(Chunk chunk)
    {
        for (int x = 0; x < Chunk.chunkWidth; x++)
        {
            for (int y = 0; y < Chunk.chunkHeight; y++)
            {
                for (int z = 0; z < Chunk.chunkWidth; z++)
                {
                    if (!chunk.blocks [x, y, z].changed)
                        continue;

                    WorldPos pos = new WorldPos (x, y, z);
                    blocks.Add (pos, chunk.blocks [x, y, z]);
                }
            }
        }
    }
Exemple #23
0
	public SaveChunk(Chunk chunk)
	{
		for (int x = 0; x < Chunk.chunkSize; x++)
		{
			for (int y = 0; y < Chunk.chunkSize; y++)
			{
				for (int z = 0; z < Chunk.chunkSize; z++)
				{
					if (!chunk.blocks[x, y, z].changed)
						continue;
					
					WorldPos pos = new WorldPos(x, y, z);
					BlocksDictionary.Add(pos, chunk.blocks[x, y, z]);
				}
			}
		}
	}
Exemple #24
0
    public Chunk GetChunk(int x, int y, int z)
    {
        WorldPos pos = new WorldPos ();

        // Variable to operate division as float
        float multiple = Chunk.chunkSize;

        // We divide to get the coord as ints then multiply to get a clean x,y,z of the chunk we are in.
        pos.x = Mathf.FloorToInt (x / multiple) * Chunk.chunkSize;
        pos.y = Mathf.FloorToInt (y / multiple) * Chunk.chunkSize;
        pos.z = Mathf.FloorToInt (z / multiple) * Chunk.chunkSize;

        Chunk containerChunk = null;

        chunks.TryGetValue (pos, out containerChunk);

        return containerChunk;
    }
Exemple #25
0
    //Gets chunk at specified world position
    public Chunk getChunk(int x, int y, int z)
    {
        WorldPos pos = new WorldPos ();
        float multiple = Chunk.chunkSize;

        //Find the start of the nearest chunk - each Chunk is a multiple of 16 so first starts at 0 then 16 then 32 etc
        //ie. a world position of x = 45 -- 45 / 16 = 2.8 -- floor(2.8) = 2 -- 2 * 16 = 32;
        pos.x = Mathf.FloorToInt (x / multiple) * Chunk.chunkSize;
        pos.y = Mathf.FloorToInt	 (y / multiple) * Chunk.chunkSize;
        pos.z = Mathf.FloorToInt (z / multiple) * Chunk.chunkSize;

        Chunk containerChunk = null;

        //Tries to retrieve the chunk from the chunk dictionary
        chunks.TryGetValue (pos, out containerChunk);

        return containerChunk;
    }
Exemple #26
0
    void Update()
    {
        if (genChunk)
        {
            genChunk = false;
            WorldPos chunkPos = new WorldPos(newChunkX, newChunkY);
            Chunk    chunk    = null;

            if (chunks.TryGetValue(chunkPos, out chunk))
            {
                DestroyChunk(chunkPos.x, chunkPos.y);
            }
            else
            {
                CreateChunk(chunkPos.x, chunkPos.y);
            }
        }
    }
        public virtual void setPosition(Vector3 position, Quaternion rotation)
        {
            thisPos = new WorldPos (
                Mathf.RoundToInt (position.x),
                Mathf.RoundToInt (position.y),
                Mathf.RoundToInt (position.z)
            );
            localx = position.x - thisPos.x;
            localy = position.y - thisPos.y;
            localz = position.z - thisPos.z;

            thisRotation = rotation;

            Vector3 rot3 = thisRotation.eulerAngles;
            rotatex = rot3.x;
            rotatey = rot3.y;
            rotatez = rot3.z;
        }
Exemple #28
0
        public Unit(Unit unitToCopy, Map targetMap)
        {
            MapLink             = new ConnectedListLink <Unit, Map>(this);
            MapSelectedUnitLink = new ConnectedListLink <Unit, Map>(this);
            Sectors             = new ConnectedList <clsUnitSectorConnection, Unit>(this);

            var IsDesign = default(bool);

            if (unitToCopy.TypeBase.Type == UnitType.PlayerDroid)
            {
                IsDesign = !((DroidDesign)unitToCopy.TypeBase).IsTemplate;
            }
            else
            {
                IsDesign = false;
            }
            if (IsDesign)
            {
                var DroidDesign = new DroidDesign();
                TypeBase = DroidDesign;
                DroidDesign.CopyDesign((DroidDesign)unitToCopy.TypeBase);
                DroidDesign.UpdateAttachments();
            }
            else
            {
                TypeBase = unitToCopy.TypeBase;
            }
            Pos      = unitToCopy.Pos;
            Rotation = unitToCopy.Rotation;
            var otherUnitGroup = default(clsUnitGroup);

            otherUnitGroup = unitToCopy.UnitGroup;
            if (otherUnitGroup.WZ_StartPos < 0)
            {
                UnitGroup = targetMap.ScavengerUnitGroup;
            }
            else
            {
                UnitGroup = targetMap.UnitGroups[otherUnitGroup.WZ_StartPos];
            }
            SavePriority      = unitToCopy.SavePriority;
            Health            = unitToCopy.Health;
            PreferPartsOutput = unitToCopy.PreferPartsOutput;
        }
//    public int newChunkX;
//    public int newChunkY;
//    public int newChunkZ;
//
//    public bool genChunk;

//    void Start()
//    {
//        for (int x = -4; x < 4; x++)
//        {
//            for (int y = -1; y < 3; y++)
//            {
//                for (int z = -4; z < 4; z++)
//                {
//                    CreateChunk(x * 16, y * 16, z * 16);
//                }
//            }
//        }
//    }
//
//    void Update()
//    {
//        if (genChunk)
//        {
//            genChunk = false;
//            WorldPos chunkPos = new WorldPos(newChunkX, newChunkY, newChunkZ);
//            Chunk chunk = null;
//
//            if (chunks.TryGetValue(chunkPos, out chunk))
//            {
//                DestroyChunk(chunkPos.x, chunkPos.y, chunkPos.z);
//            }
//            else
//            {
//                CreateChunk(chunkPos.x, chunkPos.y, chunkPos.z);
//            }
//        }
//    }

    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject;
        Chunk      newChunk       = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

//        bool loaded = Serialization.Load(newChunk);
//        if (loaded)
//        {
//            return;
//        }

//        for (int xi = 0; xi < 16; xi++)
//        {
//            for (int yi = 0; yi < 16; yi++)
//            {
//                for (int zi = 0; zi < 16; zi++)
//                {
//                    if (yi <= 7)
//                    {
//                        SetBlock(x + xi, y + yi, z + zi, new BlockGrass());
//                    }
//                    else
//                    {
//                        SetBlock(x + xi, y + yi, z + zi, new BlockAir());
//                    }
//                }
//            }
//        }

        var terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlockUnmodified();

        Serialization.Load(newChunk);
    }
    void FindChunksToLoad()
    {
        //Get the position of this gameobject to generate around
        WorldPos playerPos = new WorldPos(
            Mathf.FloorToInt(transform.position.x / Chunk.chunkSize) * Chunk.chunkSize,
            Mathf.FloorToInt(transform.position.y / Chunk.chunkSize) * Chunk.chunkSize,
            Mathf.FloorToInt(transform.position.z / Chunk.chunkSize) * Chunk.chunkSize
            );

        //If there aren't already chunks to generate
        if (buildList.Count == 0)
        {
            //Cycle through the array of positions
            for (int i = 0; i < chunkPositions.Length; i++)
            {
                //translate the player position and array position into chunk position
                WorldPos newChunkPos = new WorldPos(
                    chunkPositions[i].x * Chunk.chunkSize + playerPos.x,
                    0,
                    chunkPositions[i].z * Chunk.chunkSize + playerPos.z
                    );

                //Get the chunk in the defined position
                Chunk newChunk = world.GetChunk(
                    newChunkPos.x, newChunkPos.y, newChunkPos.z);

                //If the chunk already exists and it's already
                //rendered or in queue to be rendered continue
                if (newChunk != null &&
                    (newChunk.rendered || updateList.Contains(newChunkPos)))
                {
                    continue;
                }

                //load a column of chunks in this position
                for (int y = -4; y < 4; y++)
                {
                    buildList.Add(new WorldPos(
                                      newChunkPos.x, y * Chunk.chunkSize, newChunkPos.z));
                }
                return;
            }
        }
    }
	// Update is called once per frame
	void Update () {
		CheckOutOfBound();
		CheckAlive();

		if(Suck_item>0){
			if(!SuckIMG.enabled){
				SuckIMG.enabled = true;
			}
			if(CrossPlatformInputManager.GetButton("ItemSuck")){
				WorldPos WS = new WorldPos((int)transform.position.x, (int)transform.position.y, (int)transform.position.z);
				
				world.SpecialBlockEff(WS, BlockSpecial.Specal_type.Suck, BlockSpecial.Owner.me);
				socket.SendSetSpecBlock(WS, BlockSpecial.Specal_type.Suck);
				Suck_item--;
			}
		}else if(SuckIMG.enabled && Suck_item<=0){SuckIMG.enabled = false;}


		if(Bump_item>0){
			if(!BumpIMG.enabled){
				BumpIMG.enabled = true;
			}
			if(CrossPlatformInputManager.GetButton("ItemBump")){
				WorldPos WS = new WorldPos((int)transform.position.x, (int)transform.position.y, (int)transform.position.z);
				
				world.SpecialBlockEff(WS, BlockSpecial.Specal_type.Bound, BlockSpecial.Owner.me);
				socket.SendSetSpecBlock(WS, BlockSpecial.Specal_type.Bound);
				Bump_item--;
			}
		}else if(BumpIMG.enabled && Bump_item<=0){BumpIMG.enabled = false;}

		if(Teleport_item>0){
			if(!TeleportIMG.enabled){
				TeleportIMG.enabled = true;
			}
			if(CrossPlatformInputManager.GetButton("ItemMine")){
				WorldPos WS = new WorldPos((int)transform.position.x, (int)transform.position.y, (int)transform.position.z);
				
				world.SpecialBlockEff_mod(WS, BlockSpecial.Specal_type.Teleport, BlockSpecial.Owner.me);
				socket.SendSetSpecBlock(WS, BlockSpecial.Specal_type.Teleport);
				Teleport_item--;
			}
		}else if(TeleportIMG.enabled && Teleport_item<=0){TeleportIMG.enabled = false;}
	}
    public override bool Equals(object obj)
    {
        // If the objec is not a world pos (cannot be cast to one), then its not equal
        if ((obj is WorldPos) == false)
        {
            return(false);
        }
        // Actually cast obj to a world pos
        WorldPos pos = (WorldPos)obj;

        if (pos.X != X || pos.Y != Y || pos.Z != Z)
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
    public Save(Chunk chunk)
    {
        for (int x = 0; x < Chunk.chunkWidth; x++)
        {
            for (int y = 0; y < Chunk.chunkHeight; y++)
            {
                for (int z = 0; z < Chunk.chunkWidth; z++)
                {
                    if (!chunk.blocks [x, y, z].changed)
                    {
                        continue;
                    }

                    WorldPos pos = new WorldPos(x, y, z);
                    blocks.Add(pos, chunk.blocks [x, y, z]);
                }
            }
        }
    }
Exemple #34
0
    //    public int newChunkX;
    //    public int newChunkY;
    //    public int newChunkZ;
    //
    //    public bool genChunk;
    //    void Start()
    //    {
    //        for (int x = -4; x < 4; x++)
    //        {
    //            for (int y = -1; y < 3; y++)
    //            {
    //                for (int z = -4; z < 4; z++)
    //                {
    //                    CreateChunk(x * 16, y * 16, z * 16);
    //                }
    //            }
    //        }
    //    }
    //
    //    void Update()
    //    {
    //        if (genChunk)
    //        {
    //            genChunk = false;
    //            WorldPos chunkPos = new WorldPos(newChunkX, newChunkY, newChunkZ);
    //            Chunk chunk = null;
    //
    //            if (chunks.TryGetValue(chunkPos, out chunk))
    //            {
    //                DestroyChunk(chunkPos.x, chunkPos.y, chunkPos.z);
    //            }
    //            else
    //            {
    //                CreateChunk(chunkPos.x, chunkPos.y, chunkPos.z);
    //            }
    //        }
    //    }
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject;
        Chunk newChunk = newChunkObject.GetComponent<Chunk>();

        newChunk.pos = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

        //        bool loaded = Serialization.Load(newChunk);
        //        if (loaded)
        //        {
        //            return;
        //        }

        //        for (int xi = 0; xi < 16; xi++)
        //        {
        //            for (int yi = 0; yi < 16; yi++)
        //            {
        //                for (int zi = 0; zi < 16; zi++)
        //                {
        //                    if (yi <= 7)
        //                    {
        //                        SetBlock(x + xi, y + yi, z + zi, new BlockGrass());
        //                    }
        //                    else
        //                    {
        //                        SetBlock(x + xi, y + yi, z + zi, new BlockAir());
        //                    }
        //                }
        //            }
        //        }

        var terrainGen = new TerrainGen();
        newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlockUnmodified();

        Serialization.Load(newChunk);
    }
    public static Save LoadChunkData(WorldPos pos)
    {
        string saveFile = SaveLocation(World.singleton.worldName);

        saveFile += FileName(pos);

        if (!File.Exists(saveFile))
        {
            return(null);
        }

        IFormatter formatter = new BinaryFormatter();
        FileStream stream    = new FileStream(saveFile, FileMode.Open);

        Save save = (Save)formatter.Deserialize(stream);

        stream.Close();
        return(save);
    }
Exemple #36
0
    //Instantiate Prefab, set chunks pos and add it to dictionary
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldpos = new WorldPos(x, y, z);

        // Instantiate the chunk at coordinates using chunk prefab
        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldpos;
        newChunk.world = this;

        // Add it to the chunks dictionary. Position = key
        chunks.Add(worldpos, newChunk);

        newChunk = terrainGen.ChunkGen(newChunk);
        newChunk.SetBlocksUnmodified();
        bool loaded = Serialization.Load(newChunk);
    }
Exemple #37
0
    public Save(Chunk chunk)
    {
        for (int x = 0; x < Chunk.chunkSize; x++)
        {
            for (int y = 0; y < Chunk.chunkSize; y++)
            {
                for (int z = 0; z < Chunk.chunkSize; z++)
                {
                    if (!chunk.blocks[x, y, z].changed)
                    {
                        continue;
                    }

                    WorldPos pos = new WorldPos(x,y,z);
                    blocks.Add(pos, chunk.blocks[x, y, z]);
                }
            }
        }
    }
Exemple #38
0
    public Save(Chunk chunk)
    {
        for (int x = 0; x < Chunk.chunkSize; x++)
        {
            for (int y = 0; y < Chunk.chunkSize; y++)
            {
                for (int z = 0; z < Chunk.chunkSize; z++)
                {
                    if (!chunk.GetBlock(x, y, z).changed)
                    {
                        continue;
                    }

                    WorldPos pos = new WorldPos(x, y, z);
                    blocks.Add(pos, chunk.GetBlock(x, y, z));
                }
            }
        }
    }
        /**
         * Creates a new chunk at the given world position.
         */
        public void CreateChunk(WorldPos pos)
        {
            Chunk chunk = new Chunk();

            chunk.pos   = pos;
            chunk.world = this;

            chunks.Add(pos, chunk);

            if (!FileManager.LoadChunk(chunk))
            {
                chunk = terrainGen.ChunkGen(chunk);
                MakePhysical(chunk);
                return;
            }

            chunk.empty = IsChunkEmpty(chunk);
            MakePhysical(chunk);
        }
Exemple #40
0
    public static bool SetBlock(RaycastHit2D hit, Block block, bool adjacent = false)
    {
        Chunk chunk = hit.collider.GetComponent <Chunk>();

        if (chunk == null)
        {
            return(false);
        }

        WorldPos pos = GetBlockPos(hit, adjacent);

        if (PlayerController.Instance.OccupiedBlocks().Contains(pos))
        {
            return(false);
        }

        chunk.world.SetBlock(pos.x, pos.y, 0, block);
        return(true);
    }
Exemple #41
0
    public ChunkSaveData(Chunk chunk)
    {
        for (int x = 0; x < Chunk.CHUNK_SIZE; x++)
        {
            for (int y = 0; y < Chunk.CHUNK_SIZE; y++)
            {
                for (int z = 0; z < Chunk.CHUNK_SIZE; z++)
                {
                    if (!chunk.blocks[x, y, z].changed)
                    {
                        continue;
                    }

                    WorldPos pos = new WorldPos(x, y, z);
                    blocks.Add(pos, chunk.blocks[x, y, z]);
                }
            }
        }
    }
    public void CreateChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject;
        Chunk      newChunk       = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;

        chunks.Add(worldPos, newChunk);

//		var terrainGen = new TerrainGen();
//		newChunk = terrainGen.ChunkGen(newChunk);

        newChunk.SetBlockUnmodified();

        Serialization.Load(newChunk);
    }
Exemple #43
0
    public Save(Chunk chunk)
    {
        Debug.Log ("saveattempt blocks");
        //pull our block data from chunk and store it in dictionary only if changed
        for (int x = 0; x < Chunk.chunkSize; x++)
        {
            for (int y = 0; y < Chunk.chunkSize; y++)
            {
                for (int z = 0; z < Chunk.chunkSize; z++)
                {
                    if (chunk.blocks[x, y, z].changed) //if this block was changed, lets save the block and related articles
                    {
                        WorldPos pos = new WorldPos(x, y, z);
                        blocks.Add(pos, chunk.blocks[x, y, z]);
                    }
                }
            }
        }
        //pickup blocks should always be saved
        GameObject[] drops;
        drops = GameObject.FindGameObjectsWithTag("pickup");
        if(drops.Length > 0) {
            Debug.Log ("saveattempt pickups");
            Rect rbounds = new Rect(chunk.pos.x, chunk.pos.y, Chunk.chunkSize, Chunk.chunkSize);
            foreach (GameObject pickupObj in drops)
            {

                if(rbounds.Contains(pickupObj.transform.position, true) )
                {

                        //Debug.Log ("saveattempt single pickup");

                    //set position within the data structure before saving
                    Pickup thisPickup = new Pickup();
                    thisPickup.copyPickup(pickupObj.GetComponent<pickUpScript>().pickup);

                    thisPickup.setPosition(pickupObj.transform.position, pickupObj.transform.rotation);

                    articles.Add(thisPickup.getWorldPos(), thisPickup);
                }
            }
        }
    }
Exemple #44
0
 public Save(Chunk chunk)
 {
     for (int x = 0; x < Chunk.chunkSize; x++)
     {
         for (int y = 0; y < Chunk.chunkSize; y++)
         {
             for (int z = 0; z < Chunk.chunkSize; z++)
             {
                 // Remove comments and changed blocks won't be loaded in, they will be re-generated.
                 if (!chunk.blocks[x, y, z].changed)
                 {
                     continue;
                 }
                 //Debug.Log("saved block");
                 WorldPos pos = new WorldPos(x, y, z);
                 blocks.Add(pos, chunk.blocks[x, y, z]);
             }
         }
     }
 }
Exemple #45
0
    public static bool SetBlock(RaycastHit hit, Block block, bool adjacent = false, bool changed = false)
    {
        Chunk chunk = hit.collider.GetComponent <Chunk>();

        if (chunk == null)
        {
            return(false);
        }

        WorldPos pos = GetBlockPos(hit, adjacent);

        chunk.world.SetBlock(pos.x, pos.y, pos.z, block, changed);

        if (changed)
        {
            chunk.SaveChunk();
        }

        return(true);
    }
    public Save(Chunk chunk)
    {
        for (int x = 0; x < Chunk.chunkSize; x++)
        {
            for (int y = 0; y < Chunk.chunkSize; y++)
            {
                for (int z = 0; z < Chunk.chunkSize; z++)
                {
                    //don't save unchanged blocks
                    if (!chunk.blocks[x, y, z].changed)
                    {
                        continue;
                    }

                    WorldPos pos = new WorldPos(x, y, z);
                    blocks.Add(pos, chunk.blocks[x, y, z]);
                }
            }
        }
    }
    public static Chunk LoadChunk(WorldPos pos)
    {
        Chunk chunk;
        float multiple = Chunk.chunkSize;

        pos.x = Mathf.FloorToInt(pos.x / multiple) * Chunk.chunkSize;
        pos.y = Mathf.FloorToInt(pos.y / multiple) * Chunk.chunkSize;
        pos.z = Mathf.FloorToInt(pos.z / multiple) * Chunk.chunkSize;

        if (!World.singleton.chunks.ContainsKey(pos))
        {
            chunk = World.singleton.CreateChunk(pos.x, pos.y, pos.z);
        }
        else
        {
            chunk = World.singleton.GetChunk(pos.x, pos.y, pos.z);
        }

        return(chunk);
    }
    public void CreateChunk(int x, int y, int z)
    {
        //the coordinates of this chunk in the world
        WorldPos worldPos = new WorldPos(x, y, z);
        //Instantiate the chunk at the coordinates using the chunk prefab
        GameObject newChunkObject = Instantiate(
            chunkPrefab, new Vector3(worldPos.x, worldPos.y, worldPos.z),
            Quaternion.Euler(Vector3.zero)
            ) as GameObject;

        //Get the object's chunk component
        Chunk newChunk = newChunkObject.GetComponent <Chunk>();

        //Assign its values
        newChunk.pos   = worldPos;
        newChunk.world = this;
        //Add it to the chunks dictionary with the position as the key
        chunks.Add(worldPos, newChunk);


        //Add the following:
        for (int xi = 0; xi < 16; xi++)
        {
            for (int yi = 0; yi < 16; yi++)
            {
                for (int zi = 0; zi < 16; zi++)
                {
                    if (yi <= 7)
                    {
                        SetBlock(x + xi, y + yi, z + zi, new BlockGrass());
                    }
                    else
                    {
                        SetBlock(x + xi, y + yi, z + zi, new BlockAir());
                    }
                }
            }
        }
        newChunk.SetBlocksUnmodified();
        Serialization.Load(newChunk);
    }
Exemple #49
0
 //Builds chunk and fills update list
 void BuildChunk(WorldPos pos)
 {
     for (int y = pos.y - Chunk.chunkSize; y <= pos.y + Chunk.chunkSize; y += Chunk.chunkSize)
     {
         if (y > 64 || y < -64)
         {
             continue;
         }
         for (int x = pos.x - Chunk.chunkSize; x <= pos.x + Chunk.chunkSize; x += Chunk.chunkSize)
         {
             for (int z = pos.z - Chunk.chunkSize; z <= pos.z + Chunk.chunkSize; z += Chunk.chunkSize)
             {
                 if (world.GetChunk(x, y, z) == null)
                 {
                     world.CreateChunk(x, y, z);
                 }
             }
         }
     }
     updateList.Add(pos);
 }
    void Update()
    {
        WorldPos CurrPos = GetPlayerPos();

        if (CurrPos.z >= PlayerPos.z + (Chunk.chunkSize))
        {
            MoveZPlus();
        }
        //if (CurrPos.z < PlayerPos.z - (Chunk.chunkSize))
        //    MoveZMinus();
        if (CurrPos.x >= PlayerPos.x + (Chunk.chunkSize))
        {
            MoveXPlus();
        }
        if (CurrPos.x < PlayerPos.x - (Chunk.chunkSize))
        {
            MoveXMinus();
        }

        //Debug.Log(PlayerPos.x + ", " + PlayerPos.y + ", " + PlayerPos.z);
    }
Exemple #51
0
    public Save(Chunk chunk)
    {
        for (int x = 0; x < Chunk.chunkSize; x++)
        {
            for (int y = 0; y < Chunk.chunkSize; y++)
            {
                if (!chunk.blocks[x, y, 0].changed && !chunk.blocks[x, y, 1].changed)
                {
                    continue;
                }

                WorldPos pos = new WorldPos(x, y);
                blocks.Add(pos,
                           new Blocks
                {
                    Foreground = chunk.blocks[x, y, 0],
                    Background = chunk.blocks[x, y, 1]
                });
            }
        }
    }
Exemple #52
0
    public void CreateGrid(int x, int y)
    {
        WorldPos worldPos = new WorldPos(x, y);

        GameObject newGridObject = Instantiate(gridPrefab, new Vector3(x, y), Quaternion.Euler(Vector3.zero)) as GameObject;

        Grid newGrid = newGridObject.GetComponent <Grid>();

        GridGenerator gen = new GridGenerator();

        newGrid.pos   = worldPos;
        newGrid.world = this;
        if (isFogGenerator || !SaveAndLoadManager.LoadGrid(newGrid))
        {
            newGrid = gen.GridGen(newGrid, isFogGenerator);
        }

        grids.Add(worldPos, newGrid);

        newGridObject.layer = 9;
    }
Exemple #53
0
        void FindChunksToLoad()
        {
            WorldPos playerPos = new WorldPos();

            playerPos.x = Mathf.FloorToInt(transform.position.x / Chunk.chunkSize) * Chunk.chunkSize;
            playerPos.y = Mathf.FloorToInt(transform.position.y / Chunk.chunkSize) * Chunk.chunkSize;
            playerPos.z = Mathf.FloorToInt(transform.position.z / Chunk.chunkSize) * Chunk.chunkSize;

            if (updateList.Count == 0)
            {
                for (int i = 0; i < chunkPositions.Length; i++)
                {
                    WorldPos newChunkPos = new WorldPos();
                    newChunkPos.x = chunkPositions[i].x * Chunk.chunkSize + playerPos.x;
                    newChunkPos.y = 0;
                    newChunkPos.z = chunkPositions[i].z * Chunk.chunkSize + playerPos.z;

                    Chunk chunk = world.GetChunk(newChunkPos.x, newChunkPos.y, newChunkPos.z);

                    if (chunk != null && (chunk.wasRendered || updateList.Contains(newChunkPos)))
                    {
                        continue;
                    }

                    for (int y = -4; y < 4; y++)
                    {
                        for (int x = newChunkPos.x - Chunk.chunkSize; x <= newChunkPos.x + Chunk.chunkSize; x += Chunk.chunkSize)
                        {
                            for (int z = newChunkPos.z - Chunk.chunkSize; z <= newChunkPos.z + Chunk.chunkSize; z += Chunk.chunkSize)
                            {
                                buildList.Add(new WorldPos(x, y * Chunk.chunkSize, z));
                            }
                        }
                        updateList.Add(new WorldPos(newChunkPos.x, y * Chunk.chunkSize, newChunkPos.z));
                    }

                    return;
                }
            }
        }
Exemple #54
0
    //immediately calculates all terrain chunks in range of the player
    //very slow, only used at startup
    public void updateAll(WorldPos pos)
    {
        List <LODPos> chunksToSplit = new List <LODPos>();


        //for every chunk that is not split, check if it is close enough to be split
        foreach (LODPos lpos in visChunks)
        {
            //if the distance from the player's position to the lpos is close enough and its not a level 0 pos, add it to the split list
            if (lodposInRange(pos, lpos) && lpos.level > 0)
            {
                chunksToSplit.Add(lpos);
            }
        }

        Debug.Log("terrain chunks " + chunksToSplit.Count);
        if (chunksToSplit.Count == 0)
        {
            return;
        }

        foreach (LODPos chunk in chunksToSplit)
        {
            splitChunk(chunk);
        }

        foreach (LODPos lpos in chunksToSplitRender)
        {
            splitCalc(lpos);
            splitRender(lpos);
        }

        /*foreach(LODPos lpos in chunksToSplitRender)
         * {
         *      splitRender(lpos);
         * }*/
        chunksToSplitRender.Clear();

        updateAll(pos);
    }
    void MoveXPlus()
    {
        PlayerPos = GetPlayerPos();

        for (int z = -(Chunk.chunkSize / 2); z < Chunk.chunkSize / 2; z++)
        {
            for (int y = YSTART; y < YEND; y++)
            {
                newX = PlayerPos.x + Chunk.chunkSize * (Chunk.chunkSize / 2) - Chunk.chunkSize;
                newY = y * Chunk.chunkSize;
                newZ = PlayerPos.z + (z * Chunk.chunkSize);

                CreateChunk(newX, newY, newZ);

                if (z == -(Chunk.chunkSize / 2))
                {
                    while (PlayerPos.z % Chunk.chunkSize != 0)
                    {
                        PlayerPos.z--;
                    }
                    while (PlayerPos.x % Chunk.chunkSize != 0)
                    {
                        PlayerPos.x++;
                    }

                    Debug.Log("PlayerPos: " + PlayerPos.x + " " + PlayerPos.z);

                    for (int d = z; d < Chunk.chunkSize / 2; d++)
                    {
                        DestroyChunk(
                            PlayerPos.x - Chunk.chunkSize * (Chunk.chunkSize / 2) - Chunk.chunkSize,
                            newY,
                            PlayerPos.z + (d * Chunk.chunkSize)
                            );
                    }
                }
            }
        }
    }
    public void createChunk(int x, int y, int z)
    {
        WorldPos worldPos = new WorldPos(x, y, z);

        //Instantiate a new Chunk at the coordinates
        GameObject newChunkObject = Instantiate(chunkPrefab, new Vector3(x, y, z),
                                                Quaternion.Euler(Vector3.zero)) as GameObject;

        Chunk newChunk = newChunkObject.GetComponent <Chunk> ();

        newChunk.pos   = worldPos;
        newChunk.world = this;

        //Add the new Chunk to the dictionary at this world position
        chunks.Add(worldPos, newChunk);

        TerrainGen terrainGen = new TerrainGen();

        newChunk = terrainGen.ChunkGen(newChunk);
        newChunk.setBlocksUnmodified();
        Serialization.loadChunk(newChunk);
    }
    void MoveZPlus()
    {
        PlayerPos = GetPlayerPos();

        for (int x = -(Chunk.chunkSize / 2); x < Chunk.chunkSize / 2; x++)
        {
            for (int y = YSTART; y < YEND; y++)
            {
                newX = PlayerPos.x + (x * Chunk.chunkSize);
                newY = y * Chunk.chunkSize;
                newZ = PlayerPos.z + Chunk.chunkSize * (Chunk.chunkSize / 2) - Chunk.chunkSize;

                CreateChunk(newX, newY, newZ);

                if (x == -(Chunk.chunkSize / 2))
                {
                    while (PlayerPos.x % Chunk.chunkSize != 0)
                    {
                        PlayerPos.x--;
                    }
                    while (PlayerPos.z % Chunk.chunkSize != 0)
                    {
                        PlayerPos.z++;
                    }

                    Debug.Log("PlayerPos: " + PlayerPos.x + " " + PlayerPos.z);

                    for (int d = x; d < Chunk.chunkSize / 2; d++)
                    {
                        DestroyChunk(
                            PlayerPos.x + (d * Chunk.chunkSize),
                            newY,
                            PlayerPos.z - Chunk.chunkSize * (Chunk.chunkSize / 2) - Chunk.chunkSize
                            );
                    }
                }
            }
        }
    }
Exemple #58
0
    private void setUpAndDown(LivingPart part, int i, int size, Block block, WorldPos pos)
    {
        LivingPart lpS    = part;
        LivingPart lpN    = part;
        LivingPart lpUp   = part;
        LivingPart lpDown = part;

        for (int j = 1; j < size - i; j++)
        {
            lpS = lpS.SetChildPart(Block.Direction.south, block);
            base.SetBlock(pos.x + lpS.pos.x, pos.y + lpS.pos.y, pos.z + lpS.pos.z, block);

            lpN = lpN.SetChildPart(Block.Direction.north, block);
            base.SetBlock(pos.x + lpN.pos.x, pos.y + lpN.pos.y, pos.z + lpN.pos.z, block);

            lpUp = lpUp.SetChildPart(Block.Direction.up, block);
            base.SetBlock(pos.x + lpUp.pos.x, pos.y + lpUp.pos.y, pos.z + lpUp.pos.z, block);

            lpDown = lpDown.SetChildPart(Block.Direction.down, block);
            base.SetBlock(pos.x + lpDown.pos.x, pos.y + lpDown.pos.y, pos.z + lpDown.pos.z, block);
        }
    }
Exemple #59
0
    //renders the pieces of a chunk that has already been split
    public void splitRender(LODPos pos)
    {
        //if(!chunks.ContainsKey(pos))
        //	return;


        //Debug.Log("Chunks contains key :" + pos.ToString() + " " + chunks.ContainsKey(pos));
        //hide this terrain object but don't delete it
        //chunks[pos].gameObject.SetActive(false);

        //now find all of its pieces and render them

        //1 level lower
        int newLev = pos.level - 1;
        //the position of the first subchunk in this chunk
        WorldPos newStart = new WorldPos(pos.x * 2, pos.y * 2, pos.z * 2);

        //render all 8 chunks (that exist)
        for (int x = 0; x <= 1; x++)
        {
            for (int y = 0; y <= 1; y++)
            {
                for (int z = 0; z <= 1; z++)
                {
                    LODPos        newChunk = new LODPos(newLev, newStart.x + x, newStart.y + y, newStart.z + z);
                    TerrainObject tobj     = null;
                    if (chunks.TryGetValue(newChunk, out tobj))
                    {
                        tobj.Render();
                    }
                }
            }
        }

        //splitChunks.
        //Debug.Log(pos.ToString() + " is being splitrendered " + chunksToSplitRender.IndexOf(pos) + " " + chunksToSplitRender.LastIndexOf(pos));
        chunks[pos].gameObject.SetActive(false);
        //Debug.Log(pos.ToString() + " was deactivated");
    }
Exemple #60
0
    private void CreateChunk(int x, int y, int z)
    {
        WorldPos   worldPos       = new WorldPos(x, y, z);
        GameObject newChunkObject = Instantiate(chunkPerfab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero)) as GameObject;
        Chunk      newChunk       = newChunkObject.GetComponent <Chunk>();

        newChunk.pos   = worldPos;
        newChunk.world = this;
        chunks.Add(worldPos, newChunk);
        //初始化Chunk
        for (int xi = 0; xi < Chunk.chunkSize; xi++)
        {
            for (int yi = 0; yi < Chunk.chunkSize; yi++)
            {
                for (int zi = 0; zi < Chunk.chunkSize; zi++)
                {
                    SetBlock(x + xi, y + yi, z + zi, new BlockGrass());
                }
            }
        }
        newChunk.UpdateChunk();
    }