public override void Update(BiomeController biome) { if (biome.GetBlockCount() == 0) { biome.SetBlock(new Vector3Int(0, 0, 0), BlockType.Dirt); } }
/** <summary> * Creates a new biome at the specified biome-space coordinates with the specified type * <para /> * If biome is set to null then it picks a random biome except Premade */ public BiomeController CreateBiome(Vector3Int pos, BiomeType?type = null, bool generate = true) { BiomeController b = Instantiate <BiomeController>(BiomePrefab, transform); b.name = String.Format("{0}-{1}-{2}", pos.x, pos.y, pos.z); b.Manager = this; Vector3 worldPos = Biome.BlockSize * (new Vector3(Biome.XSize, Biome.YSize, Biome.ZSize) + Biome.BiomeSpacing * Vector3.one); worldPos.Scale(pos); b.transform.localPosition = worldPos; Biome instance = null; if (type != null) { Biomes.TryGetValue(type.Value, out instance); } else { List <BiomeType> biomes = new List <BiomeType>(Biomes.Keys); type = biomes[UnityEngine.Random.Range(2, biomes.Count - 1)]; Biomes.TryGetValue(type.Value, out instance); } b.Type = type.Value; b.BiomeInstance = instance; if (generate) { instance.Generate(b); } return(b); }
public override void Generate(BiomeController biome) { for (int x = 0; x < Biome.XSize; x++) { for (int y = 0; y < Biome.YSize - 2; y++) { for (int z = 0; z < Biome.ZSize; z++) { if (y == 0 && Random.value > 0.3f) { continue; } if (y == 1 && Random.value > 0.6f) { continue; } biome.SetBlock(new Vector3Int(x, y, z), BlockType.Grass); } } } biome.SetBlock(new Vector3Int(1, 3, 1), BlockShape.Tree); biome.SetBlock(new Vector3Int(1, 3, 3), BlockShape.Tree); biome.SetBlock(new Vector3Int(2, 3, 4), BlockShape.Tree); biome.SetBlock(new Vector3Int(5, 3, 5), BlockShape.Tree); biome.SetBlock(new Vector3Int(2, 3, 5), BlockShape.Tree); biome.SetBlock(new Vector3Int(1, 3, 0), BlockShape.Tree); biome.SetBlock(new Vector3Int(2, 3, 0), BlockShape.Tree); }
void Start() { biomeController = transform.parent.GetComponent <BiomeController>(); if (biomeController == null) { return; } myCordinates = GetComponent <BlockController>().biomeCoords; }
// Regenerate public void Regenerate(string _name = "") { if (_name.Equals("") || _name.Equals(speciesName)) { species[0].GetComponent <CreaturesBase>().InitializeSpecies("", "", true, true); species[1].GetComponent <CreaturesBase>().InitializeSpecies("", "", true, false); BiomeController.HealthUpdate(true); BiomeController.HealthUpdate(true); } }
// Die public void Die() { isAlive = false; // Spawn skeleton SkeletonMeshUpdate(); BiomeController.HealthUpdate(false); BiomeController.DeathRate(speciesName, isPregnent); if (isPregnent) { isPregnent = false; } }
public override void Generate(BiomeController biome) { for (int x = 0; x < Biome.XSize; x++) { for (int y = 0; y < Biome.YSize; y++) { for (int z = 0; z < Biome.ZSize; z++) { biome.SetBlock(new Vector3Int(x, y, z), BlockType.Water); } } } }
public BiomeController CreatePremadeBiomeByName(string name) { GameObject biome = new GameObject("0-0-0"); biome.transform.parent = biomeManager.transform; BiomeController b = biome.AddComponent <BiomeController>(); b.Manager = biomeManager; b.transform.localPosition = Vector3Int.zero; b.BiomeInstance = new BiomePremade(name); b.BiomeInstance.Generate(b); return(b); }
public BiomeController CreatePremadeBiome(Vector3Int pos, string prefabName) { BiomeController b = Instantiate <BiomeController>(BiomePrefab, transform); b.name = String.Format("{0}-{1}-{2}", pos.x, pos.y, pos.z); b.Manager = this; Vector3 worldPos = Biome.BlockSize * (new Vector3(Biome.XSize, Biome.YSize, Biome.ZSize) + Biome.BiomeSpacing * Vector3.one); worldPos.Scale(pos); b.transform.localPosition = worldPos; b.Type = BiomeType.QuickPremade; b.BiomeInstance = new BiomePremade(prefabName); b.BiomeInstance.Generate(b); return(b); }
public void SaveBiome() { BiomeController bc = biomeManager.GetBiome(Vector3Int.zero); if (bc == null) { return; } string path = Path.Combine(Application.dataPath, "Resources/Biomes/" + inputField.text + ".bytes"); using ( BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create)) ) { bc.Save(writer, true); } }
// Pregnant public void Pregnant(bool _make = false) { if (_make) { isPregnent = true; currentGestationDays = gestationDays; } // Time pass by else if (isPregnent) { currentGestationDays--; if (currentGestationDays <= 0) { isPregnent = false; // Birth BiomeController.Birth(speciesName); } } }
public void LoadBiomes(string worldName) { string path = Path.Combine(Application.persistentDataPath, worldName + ".map"); using ( BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)) ) { while (reader.BaseStream.Position != reader.BaseStream.Length) { BiomeController b = Instantiate <BiomeController>(BiomePrefab, transform); b.Manager = this; b.name = reader.ReadString(); b.Type = (BiomeType)reader.ReadByte(); Biomes.TryGetValue(b.Type, out b.BiomeInstance); b.transform.localPosition = reader.ReadVector3(); b.Read(reader); } } }
Vector3Int GetNewBlockPos(RaycastHit hit) { BlockController block = hit.transform.GetComponent <BlockController>(); BiomeController biome = hit.transform.parent.GetComponent <BiomeController>(); Vector3 dist = hit.point - block.transform.position; Vector3Int dir = Vector3Int.zero; if (Mathf.Abs(dist.x) == 1f) { dir = new Vector3Int((int)dist.x, 0, 0); } if (Mathf.Abs(dist.y) == 1f) { dir = new Vector3Int(0, (int)dist.y, 0); } if (Mathf.Abs(dist.z) == 1f) { dir = new Vector3Int(0, 0, (int)dist.z); } return(block.biomeCoords + dir); }
// Health Update - by hunger or attacks static void HealthUpdate(float _dmg = 0, float _foodIntake = 0) { // Check if player is dead if (health <= 0) { if (!PlayerControlls.controlLock) { Debug.Log("Dead - Game Over"); PlayerControlls.controlLock = true; BiomeController.StartRegrowt(); } } // Hunger if (hunger == 0) { health -= STARVATION_DMG; } // Attack Dmg if (_dmg > 0) { health -= _dmg; } // health Replanish if (_foodIntake > 0) { health += _foodIntake; if (health > 100f) { health = 100f; } } // Limit Health if (health < 0) { health = 0; } }
public override void Generate(BiomeController biome) { TextAsset binFile = Resources.Load <TextAsset>("Biomes/" + filename); if (binFile == null) { Debug.LogError("Unable to load premade biome <" + filename + ">"); return; } using ( BinaryReader reader = new BinaryReader(new MemoryStream(binFile.bytes)) ) { try { biome.Read(reader); } catch (Exception e) { Debug.LogError("Error loading biome " + filename); } } }
// Update is called once per frame void Update() { if (!inputField.isFocused) { Camera.main.transform.localPosition += Camera.main.transform.right * Input.GetAxis("Horizontal") + Vector3.up * Input.GetAxis("Vertical"); if (!Input.GetKey(KeyCode.LeftControl)) { Camera.main.transform.localPosition += Camera.main.transform.forward * Input.mouseScrollDelta.y; } Camera.main.transform.LookAt(new Vector3(Biome.XSize, Biome.YSize, Biome.ZSize) * Biome.BlockSize * 0.5f); if (Input.GetKeyUp(KeyCode.F)) { if (editBlocks) { editBlocks = false; currentType = 0; } else { editBlocks = true; currentType = -1; currentShape = 0; } RefreshPreview(); } if (Input.GetKeyUp(KeyCode.R)) { currentRotation = editBlocks ? (currentRotation - currentRotation % 90 + 90) : (currentRotation - currentRotation % 45 + 45); if (currentRotation == 360) { currentRotation = 0; } } if (Input.GetKey(KeyCode.LeftControl)) { currentRotation += (int)Input.mouseScrollDelta.y * 2; if (currentRotation < 0) { currentRotation = 359; } if (currentRotation >= 360) { currentRotation = 0; } } if (editBlocks) { if (Input.GetKeyUp(KeyCode.T)) { currentType--; if (currentType == -2) { currentType = types.Count - 1; } RefreshPreview(); } if (Input.GetKeyUp(KeyCode.Y)) { currentType++; if (currentType == types.Count) { currentType = -1; } RefreshPreview(); } if (Input.GetKeyUp(KeyCode.G)) { currentShape--; if (currentShape == -1) { currentShape = shapes.Count - 1; } if (currentShape != 0) { currentType = -1; } RefreshPreview(); } if (Input.GetKeyUp(KeyCode.H)) { currentShape++; if (currentShape == shapes.Count) { currentShape = 0; } if (currentShape != 0) { currentType = -1; } RefreshPreview(); } } else { if (Input.GetKeyUp(KeyCode.T)) { currentType--; if (currentType == -1) { currentType = items.Count - 1; } RefreshPreview(); } if (Input.GetKeyUp(KeyCode.Y)) { currentType++; if (currentType == items.Count) { currentType = 0; } RefreshPreview(); } } MovePreview(); UpdateCurrentText(); } if (Input.GetMouseButtonUp(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { BlockController block = hit.transform.GetComponent <BlockController>(); if (block != null) { BiomeController biome = hit.transform.parent.GetComponent <BiomeController>(); if (editBlocks) { Vector3Int newPos = GetNewBlockPos(hit); BlockController newBlock; if (currentType == -1) { newBlock = biome.SetBlock(newPos, shapes[currentShape]); } else { newBlock = biome.SetBlock(newPos, shapes[currentShape], types[currentType]); } if (newBlock != null) { newBlock.SetRotation(Vector3.up * currentRotation); } } else { ItemController newItem = Instantiate(itemManager.Items[items[currentType]], biome.transform); newItem.transform.position = preview.position; newItem.transform.localRotation = preview.localRotation; } } } } if (Input.GetMouseButtonUp(1)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (editBlocks) { BlockController block = hit.transform.GetComponent <BlockController>(); if (block != null) { BiomeController biome = hit.transform.parent.GetComponent <BiomeController>(); biome.RemoveBlock(hit.transform.name); } } else { ItemController item = hit.transform.GetComponent <ItemController>(); if (item != null) { Destroy(item.gameObject); } } } } }
public abstract void Update(BiomeController biome);
public override void Update(BiomeController biome) { }
public override void Generate(BiomeController biome) { for (int x = 0; x < Biome.XSize; x++) { for (int y = 0; y < Biome.YSize; y++) { for (int z = 0; z < Biome.ZSize; z++) { if (y == YSize - 2 && (z == 0 || z == ZSize - 1 || x == 0 || x == XSize - 1)) { BlockShape shape = BlockShape.Slope; // If we're on a corner if ((z == 0 && x == 0) || (z == 0 && x == XSize - 1) || (z == ZSize - 1 && x == 0) || (z == ZSize - 1 && x == XSize - 1)) { shape = BlockShape.SlopeAngle; } float yAngle = 0; if (z == ZSize - 1) { yAngle = 90; } if (x == XSize - 1) { yAngle = 180; } if (z == 0 && x != 0) { yAngle = 270; } biome.SetBlock(new Vector3Int(x, y, z), shape, BlockType.Sand).Rotate(new Vector3(0, yAngle, 0)); continue; } if (y == YSize - 1) { if (z == 0 || z == ZSize - 1 || x == 0 || x == XSize - 1) { continue; } if (z == 1 || z == ZSize - 2 || x == 1 || x == XSize - 2) { BlockShape shape = BlockShape.Slope; // If we're on a corner if ((z == 1 && x == 1) || (z == 1 && x == XSize - 2) || (z == ZSize - 2 && x == 1) || (z == ZSize - 2 && x == XSize - 2)) { shape = BlockShape.SlopeAngle; } float yAngle = 0; if (z == ZSize - 2) { yAngle = 90; } if (x == XSize - 2) { yAngle = 180; } if (z == 1 & x != 1) { yAngle = 270; } biome.SetBlock(new Vector3Int(x, y, z), shape, BlockType.Sand).Rotate(new Vector3(0, yAngle, 0)); continue; } } biome.SetBlock(new Vector3Int(x, y, z), BlockType.Sand); } } } }
public abstract void Generate(BiomeController biome);
public override void Generate(BiomeController biome) { biome.SetBlock(new Vector3Int(0, 0, 0), BlockType.Dirt); }