void Start() { //connect with level controller and script levelController = GameObject.Find("LevelController"); levelControllerScript = levelController.GetComponent <LevelControllerScript> (); //find the rows and columns in of the level grid mapRows = levelControllerScript.GetMapRows(); mapCols = levelControllerScript.GetMapCols(); //calculate maximum camera zoom //Orthographic size = ((Vert Resolution)/(PPUScale * PPU)) * 0.5 cameraCurrentZoom = ((Screen.height) / (ppuScale * 32)) * 0.5000f; cameraZoomMax = cameraCurrentZoom; Camera.main.orthographicSize = cameraCurrentZoom; //make the camera less sensitive as we zoom in cameraSpeedCutBy = originalCameraSpeedCutBy * (cameraCurrentZoom / cameraZoomMax); //czm is for viewing only czm = cameraCurrentZoom; //get the dimensions of the camera (screen resolution), save values in max variables camHeight = 2f * cam.orthographicSize; camWidth = camHeight * cam.aspect; maxCamWidth = camWidth; maxCamHeight = camHeight; }
// Use this for initialization void Start() { //load prefabs corridor = Resources.Load("Prefabs/Environment/Corridor") as GameObject; floor = Resources.Load("Prefabs/Environment/Floor") as GameObject; wall = Resources.Load("Prefabs/Environment/Wall") as GameObject; door = Resources.Load("Prefabs/Environment/Door") as GameObject; unused = Resources.Load("Prefabs/Environment/Unused") as GameObject; //grab enemies from prefabs vagrant = Resources.Load("Prefabs/NPCs/Vagrant") as GameObject; //find levelController levelControllerScript = GameObject.Find("LevelController").GetComponent <LevelControllerScript> (); myX = levelControllerScript.GetMapCols(); myY = levelControllerScript.GetMapRows(); ChangeLevel(0, 0); for (int i = 0; i < 10; ++i) { int x = Random.Range(0, _width); int y = Random.Range(0, _height); Debug.Log(x + ", " + y); if (levelControllerScript.GetLevelGrid()[x, y].GetComponent <TileScript> ().IsGround()) { levelControllerScript.SpawnLivingThing(vagrant, x, y); } } levelControllerScript.FillNPCList(); }
// Use this for initialization protected void Start() { levelControllerScript = GameObject.Find("LevelController").GetComponent <LevelControllerScript>(); levelGrid = levelControllerScript.GetLevelGrid(); mapCols = levelControllerScript.GetMapCols(); mapRows = levelControllerScript.GetMapRows(); }
// Use this for initialization void Start() { woodTile = Resources.Load("Prefabs/Environment/WoodWall") as GameObject; item = Resources.Load("Prefabs/Items/Item") as GameObject; levelController = GameObject.Find("LevelController") as GameObject; levelControllerScript = levelController.GetComponent <LevelControllerScript>(); mapRows = levelControllerScript.GetMapRows(); mapCols = levelControllerScript.GetMapCols(); levelControllerScript.ReplaceTile(0, 0, woodTile); GenerateLevel(); }
// Use this for initialization void Start () { if (xmax % 2 == 0) {oddColAdjustment = -.5f;} if (ymax % 2 == 0) {oddRowAdjustment = -.5f;} levelControllerScript = GameObject.Find ("LevelController").GetComponent<LevelControllerScript> (); ymax = levelControllerScript.GetMapCols (); xmax = levelControllerScript.GetMapRows (); _levelGrid = levelControllerScript.GetLevelGrid (); corridorTile = Resources.Load ("Prefabs/Environment/Corridor") as GameObject; floorTile = Resources.Load("Prefabs/Environment/Floor") as GameObject; wallTile = Resources.Load("Prefabs/Environment/Wall") as GameObject; doorTile = Resources.Load("Prefabs/Environment/Door") as GameObject; unusedTile = Resources.Load("Prefabs/Environment/Unused") as GameObject; woodWallTile = Resources.Load("Prefabs/Environment/WoodWall") as GameObject; //GameObject sut = Instantiate(unusedTile, new Vector3(0, 0, -1), Quaternion.identity) as GameObject; //levelControllerScript.ReplaceTile(0, 0, unusedTile); CreateDungeon(xmax, ymax, 100); //Initialize(); levelControllerScript.SetLevelGrid(_levelGrid); }
public bool CreateDungeon(int inx, int iny, int inobj) { this._objects = inobj < 1 ? 10 : inobj; // adjust the size of the map, if it's smaller or bigger than the limits if (inx < 3) this._xsize = 3; else if (inx >= xmax) this._xsize = xmax; else this._xsize = inx; if (iny < 3) this._ysize = 3; else if (iny >= ymax) this._ysize = ymax; else this._ysize = iny; //Console.WriteLine(MsgXSize + this._xsize); //Console.WriteLine(MsgYSize + this._ysize); //Console.WriteLine(MsgMaxObjects + this._objects); // redefine the map var, so it's adjusted to our new map size //this._dungeonMap = new Tile[this._xsize * this._ysize]; this._levelGrid = new GameObject[levelControllerScript.GetMapCols(), levelControllerScript.GetMapRows()]; // start with making the "standard stuff" on the map this.Initialize(); /******************************************************************************* And now the code of the random-map-generation-algorithm begins! *******************************************************************************/ // start with making a room in the middle, which we can start building upon this.MakeRoom(this._xsize / 2, this._ysize / 2, 8, 6, RandomDirection()); // getrand saken f????r att slumpa fram riktning p?? rummet // keep count of the number of "objects" we've made int currentFeatures = 1; // +1 for the first room we just made // then we sart the main loop for (int countingTries = 0; countingTries < 1000; countingTries++) { //Debug.Log("try counted"); --we made it here // check if we've reached our quota if (currentFeatures == this._objects) { //Debug.Log ("enough features, breaking out"); break; } // start with a random wall int newx = 0; int xmod = 0; int newy = 0; int ymod = 0; Direction? validTile = null; // 1000 chances to find a suitable object (room or corridor).. for (int testing = 0; testing < 1000; testing++) { //Debug.Log("testing counted"); -made it here newx = this.GetRand(1, this._xsize - 1); newy = this.GetRand(1, this._ysize - 1); //Debug.Log ("testing tile at" + newx + " " + newy); /* if (GetCellType (newx, newy).GetType() == unusedTile.GetType()) { // Debug.Log ("found unused"); }else if(GetCellType (newx, newy).GetType() == floorTile.GetType() || GetCellType (newx, newy).GetType() == corridorTile.GetType()){ Debug.Log ("found floor"); }else { Debug.Log ("wall"); }*/ //GetCellType (newx, newy).GetType (); if (GetCellType(newx, newy).GetType() == wallTile.GetType() || GetCellType(newx, newy).GetType() == corridorTile.GetType()) { //HERE WE ARE //Debug.Log("wall or corr"); //!!! List<PointI> surroundings = this.GetSurroundings(new PointI() { X = newx, Y = newy }); // check if we can reach the place //var canReach = surroundings.FirstOrDefault(s => s.Item3 == Tile.Corridor || s.Item3 == Tile.DirtFloor); PointI canReach = new PointI { }; List<PointI> validSurroundings = new List<PointI>(); foreach(PointI p in surroundings) { if(p.pointTile.GetType() == corridorTile.GetType() || p.pointTile.GetType() == floorTile.GetType() || p.pointTile.GetType() ==unusedTile.GetType()) { validSurroundings.Add(p); } } canReach = validSurroundings[UnityEngine.Random.Range(0, validSurroundings.Count)]; if (canReach == null) { //Debug.Log ("found no canReach"); continue; } validTile = canReach.direction; switch (validTile) { case Direction.NORTH: //Debug.Log ("n"); xmod = 0; ymod = -1; break; case Direction.EAST: //Debug.Log ("e"); xmod = 1; ymod = 0; break; case Direction.SOUTH: //Debug.Log ("s"); xmod = 0; ymod = 1; break; case Direction.WEST: //Debug.Log ("w"); xmod = -1; ymod = 0; break; default: throw new InvalidOperationException(); } if (validTile.HasValue) { //Debug.Log ("WORKS HERE-----------"); } // check that we haven't got another door nearby, so we won't get alot of openings besides // each other /* if (GetCellType (newx, newy + 1).GetType () == doorTile.GetType ()) { // north //Debug.Log ("Found a north door"); validTile = null; } else if (GetCellType (newx - 1, newy).GetType () == doorTile.GetType ()) { // east validTile = null; //Debug.Log ("Found an east door"); } else if (GetCellType (newx, newy - 1).GetType () == doorTile.GetType ()) { // south //Debug.Log ("Found a south door"); validTile = null; } else if (GetCellType (newx + 1, newy).GetType () == doorTile.GetType ()) { // west validTile = null; //Debug.Log ("Found a west door"); } */ // if we can, jump out of the loop and continue with the rest if (validTile.HasValue) { //Debug.Log ("WORKS HERE TOO-----------"); break; } } } if (validTile.HasValue) { // Debug.Log("has value"); // choose what to build now at our newly found place, and at what direction int feature = this.GetRand(0, 100); if (feature <= ChanceRoom) { // a new room // Debug.Log("new room!"); if (this.MakeRoom(newx + xmod, newy + ymod, 8, 6, validTile.Value)) { currentFeatures++; // add to our quota // then we mark the wall opening with a door //this.SetCell(newx, newy, doorTile); // clean up infront of the door so we can reach it this.SetCell(newx + xmod, newy + ymod, floorTile); } } else if (feature >= ChanceRoom) { // new corridor if (this.MakeCorridor(newx + xmod, newy + ymod, 6, validTile.Value)) { // same thing here, add to the quota and a door currentFeatures++; //this.SetCell(newx, newy, doorTile); } } } } /******************************************************************************* All done with the building, let's finish this one off *******************************************************************************/ //AddSprinkles(); // all done with the map generation, tell the user about it and finish // Console.WriteLine(MsgNumObjects + currentFeatures); return true; }