void Start() { r = new RandomSeed(DateTime.Now.Millisecond); //First we create the buffer. This will contain all our sprites buffer = new GameObject[NUM_LAYERS,WIDTH,HEIGHT]; //Second, we find a pointer to the level data LD_Cave ld = new LD_Cave(WIDTH, HEIGHT, r.getSeed(),new Vector2(0,0)); //LD_Dungeon ld = new LD_Dungeon(WIDTH, HEIGHT, r.getSeed(), new Vector2(0,0)); ld.generate(); //Next, we generate a color palette palette = new Palette(r); //Third, we translate the level into sprites for(int layer = 0; layer < NUM_LAYERS; layer++) { for(int y = 0; y < HEIGHT; y++) { for(int x = 0; x < WIDTH; x++) { buffer[layer,x,y] = makeSprite(x,y,ld.mapData[layer,x,y],layer); //ld.mapData[layer,x,y] }//for }//for }//for }
public void placeCaves(int number) { int numplaced = 0; while(numplaced < number) { //A - Find a random spot on the BASEMAP that isn't on the edge of the map Vector2 NULLVECTOR = new Vector2(-1,-1); Vector2 spot = NULLVECTOR; //while(spot == NULLVECTOR) spot = ld.findTileType(WALKABLE, LevelData.BASELAYER); int x = (int)spot.x; int y = (int)spot.y; //Debug.Log(findTypeInDirection(x,y,MOUNTAIN,NORTH)); if(ld.mapData[LevelData.BASELAYER, x,y] == WALKABLE) { double questSeed = r.getRandom() * double.MaxValue; //Move in a random direction until you reach the edge or find a mountain int dir = r.getIntInRange(NORTH,WEST); Vector2 questSpot = findTypeInDirection(x,y,MOUNTAIN, dir, LevelData.BASELAYER); x = (int)questSpot.x; y = (int)questSpot.y; Vector2 returnSpot = new Vector2((int)questSpot.x,(int)questSpot.y); //CREATE THE LEVEL LevelData theCave; bool isCave = r.getBoolean(); if(!isCave) { theCave = new LD_Dungeon(50,50,questSeed, returnSpot); } else { theCave = new LD_Cave(50,50,questSeed, returnSpot); } int index = LevelMaker.AddLevel(theCave); theCave.index = index; theCave.parentIndex = -1; int xx = Mathf.Clamp((int)questSpot.x,0,ld.width-1); int yy = Mathf.Clamp((int)questSpot.y,0,ld.height-1); if(xx != x || yy != y) { //Debug.Log("TRIED TO PLACE TILE OUT OF BOUNDS!" + x + "," + y); continue; //TRY AGAIN } if(isCave) { //Place the cave in mountain or edge spot you stop at ld.placeTile(xx, yy, CAVE, -1, true); } else { ld.placeTile(xx, yy, DUNGEON, -1, true); } //PLACE THE QUEST ld.questData[xx, yy] = (Quest)new LevelLoadQuest(-1,index,returnSpot); numplaced++; }//if else { //Debug.Log("CAVE PLACEMENT ERROR: NOT A VALID SPOT!" + x + "," + y); continue; //numplaced++; }//else }//while }