using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class VoxelSpace : MonoBehaviour { public int sizeX = 10; public int sizeY = 10; public int animationFrames = 30; public int fermonsWeakenTime = 500; public int relocateFoodTime = 2000; public int numberOfAnts = 5; public float voxelScale = 1.0f; public GameObject previewShape; public Ant antShape; public GameObject food; public byte[,] voxels; Ant[] ants; GameObject[,] lights; Settings settings; int frame; // -------------------------------------------------------- // -------------------------------------------------------- // ----------------funkcje-do-zadan------------------------ // -------------------------------------------------------- // -------------------------------------------------------- void createVoxelSpace() { //zadanie 2.1 } public Vector3Int positionInVoxelSpace(Vector3 worldPosition) { // zadanie 2.2 a return new Vector3Int(0,0,0); } public Vector3 positionInWorld(Vector3 voxelPosition) { // zadanie 2.2 b return new Vector3(0,0,0); } public int getPheromoneAt(float x, float y) { //zadanie 2.3 return -1; } void updateVoxelSpace() { //zadanie 2.5 } // -------------------------------------------------------- // -------------------------------------------------------- // ----------------koniec-zadan---funkcje pomocnicze------- // -------------------------------------------------------- // -------------------------------------------------------- // Start is called before the first frame update void Start() { loadSettings(); frame = 0; setTableScale(); createVoxelSpace(); // placeFood(); addAnts(); } // Update is called once per frame void Update() { Debug.Log("max="+maxVoxel()); Debug.Log("start: "+(new Vector3(3.5f,5.5f,4.5f))); Debug.Log("midle: "+(positionInVoxelSpace(new Vector3(3.5f,5.5f,4.5f)))); Debug.Log("endin: "+(positionInWorld(positionInVoxelSpace(new Vector3(3.5f,5.5f,4.5f))))); Debug.Log("zeroo: "+(positionInWorld(new Vector3(0,0,0)))); if(frame%animationFrames == 0) { foreach(Ant ant in ants) { ant.sniff(); } updateLights(); GameObject.Find("anthill").transform.position = positionInWorld(new Vector3(-1,0,-1));// gameObject.transform.position - (gameObject.transform.localScale)/2.0f; } else { foreach(Ant ant in ants) { ant.go(); } } if(frame%fermonsWeakenTime == 0) { updateVoxelSpace(); } if(frame%relocateFoodTime == 0) { placeFood(); } frame++; if (Input.GetKeyUp(KeyCode.Escape)) { SceneManager.LoadScene (sceneName:"menu"); } } int maxVoxel() { int m = 0; for(int i = 0; i 0.51f) { lights[i,j].transform.GetChild(0).GetComponent().enabled=true; lights[i,j].transform.GetChild(0).GetComponent().intensity = newScale*3.0f; } else { lights[i,j].transform.GetChild(0).GetComponent().enabled=false; } } } } Vector2 foodPos; void placeFood() { if(foodPos != null) { voxels[(int)(foodPos.x),(int)(foodPos.y)] = 0; } int x = (int)Random.Range(4,sizeX-1); int y = (int)Random.Range(4,sizeY-1); food.transform.position = positionInWorld(new Vector3(x,0,y)); foodPos = new Vector2(x,y); voxels[x,y] = 255; } void setTableScale() { gameObject.transform.localScale = new Vector3(sizeX+2.0f,sizeY+2.0f, 12.0f); Vector3 randomMove = new Vector3(Random.Range(-10.0f, 10.0f), 0, Random.Range(-10.0f, 10.0f)); gameObject.transform.position = new Vector3(sizeX/2.0f, -0.1f, sizeY/2.0f)+randomMove; GameObject camera = GameObject.Find("Main Camera"); camera.transform.position = new Vector3(sizeX/2.0f, sizeX/2.0f+sizeY/2.0f+1.0f, sizeY/2.0f)+randomMove; } void loadSettings() { if(SettingsMenu.settings != null) { settings = SettingsMenu.settings; sizeX = settings.sizeX; sizeY = settings.sizeY; animationFrames = settings.fps; fermonsWeakenTime = settings.weakenPheromones; relocateFoodTime = settings.refreshFood; numberOfAnts = settings.antsCount; } } }