void Start() { //items [1].Alloc (new Vector2 (5, 10)); //items [1].Alloc (new Vector2 (5, 10)); //items [3].Alloc (new Vector2 (Hero.inst.xform.position.x - 3, 10)); //generate grid tiles = new Tile[width, height]; for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { tiles[x,y] = (y == height - 1 ? grassTile : dirtTile).AllocAtCoord(x,y); } //put caverns in (small medium and large for(int y = 0 ; y < height - 5; y++) { for(int x = 0 ; x < width ; x++) { int r = rand.Next () % 30; if(r == 0) { if (IsTileAt(x,y)) { tiles[x,y].Release(); } SafeDestroy(x,y+1); SafeDestroy(x,y-1); SafeDestroy(x+1,y); SafeDestroy(x-1,y); int holeWidth = 1 + rand.Next () % 5; for(int i = 0 ; i < holeWidth ; i++) { SafeDestroy(x+1 + i,y+1); SafeDestroy(x+1 + i,y-1); SafeDestroy(x+2 + i,y); } } } } //set up stone tiles for (int y = 0; y < height - 5; y++) { for(int x = 1 ; x < width - 1 ; x++) { //put in stone tiles, there are a few patterns to use int r = rand.Next () % 30; if(r == 0) { int p = rand.Next() % 5; if(p > 0) { int stoneWidth = 3 + rand.Next () % 6; for(int i = 0 ; i < stoneWidth ; i++) { if( rand.Next() % 100 < 80) TryPlaceStone(x + i - 1,y +1); if( rand.Next() % 100 < 80) TryPlaceStone(x + i,y); if( rand.Next() % 100 < 80) TryPlaceStone(x + i - 1,y -1); } } else if(p == 0) { int stoneHeight = 2 + rand.Next () % 4; for(int i = 0 ; i < stoneHeight ; i++) { if( rand.Next() % 100 < 80) TryPlaceStone(x,y + i); if( rand.Next() % 100 < 80) TryPlaceStone(x - 1,y + i - 1); } } } } } // set up some worms for(int x=0; x<width; ++x) for(int y=0; y<height-60; ++y) { TryPlaceWorm(x,y); } //place stuff in the caverns for (int y = 0; y < height - 5; y++) { for (int x = 1; x < width - 1; x++) { if(tiles[x,y] == false) { //dinosaurs if( y < height - 30) { int r = rand.Next () % 30; if (r == 0) { { dinoPrefab.Alloc( Tile.CoordToWorld(x,y) ); } } } { //weapons int r = rand.Next()% 50; if(r == 0) { int w = 1 + rand.Next () % (items.Length-1); items[w].Alloc (Tile.CoordToWorld(x,y)); } } } } } //Add the earth's core earthCore = Dup (earthCorePrefab); earthCore.transform.position = new Vector3 (width / 2, -height - 25, 0); }
void Start() { //items [1].Alloc (new Vector2 (5, 10)); //items [1].Alloc (new Vector2 (5, 10)); //items [3].Alloc (new Vector2 (Hero.inst.xform.position.x - 3, 10)); //generate grid tiles = new Tile[width, height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { tiles[x, y] = (y == height - 1 ? grassTile : dirtTile).AllocAtCoord(x, y); } } //put caverns in (small medium and large for (int y = 0; y < height - 5; y++) { for (int x = 0; x < width; x++) { int r = rand.Next() % 30; if (r == 0) { if (IsTileAt(x, y)) { tiles[x, y].Release(); } SafeDestroy(x, y + 1); SafeDestroy(x, y - 1); SafeDestroy(x + 1, y); SafeDestroy(x - 1, y); int holeWidth = 1 + rand.Next() % 5; for (int i = 0; i < holeWidth; i++) { SafeDestroy(x + 1 + i, y + 1); SafeDestroy(x + 1 + i, y - 1); SafeDestroy(x + 2 + i, y); } } } } //set up stone tiles for (int y = 0; y < height - 5; y++) { for (int x = 1; x < width - 1; x++) { //put in stone tiles, there are a few patterns to use int r = rand.Next() % 30; if (r == 0) { int p = rand.Next() % 5; if (p > 0) { int stoneWidth = 3 + rand.Next() % 6; for (int i = 0; i < stoneWidth; i++) { if (rand.Next() % 100 < 80) { TryPlaceStone(x + i - 1, y + 1); } if (rand.Next() % 100 < 80) { TryPlaceStone(x + i, y); } if (rand.Next() % 100 < 80) { TryPlaceStone(x + i - 1, y - 1); } } } else if (p == 0) { int stoneHeight = 2 + rand.Next() % 4; for (int i = 0; i < stoneHeight; i++) { if (rand.Next() % 100 < 80) { TryPlaceStone(x, y + i); } if (rand.Next() % 100 < 80) { TryPlaceStone(x - 1, y + i - 1); } } } } } } // set up some worms for (int x = 0; x < width; ++x) { for (int y = 0; y < height - 60; ++y) { TryPlaceWorm(x, y); } } //place stuff in the caverns for (int y = 0; y < height - 5; y++) { for (int x = 1; x < width - 1; x++) { if (tiles[x, y] == false) { //dinosaurs if (y < height - 30) { int r = rand.Next() % 30; if (r == 0) { { dinoPrefab.Alloc(Tile.CoordToWorld(x, y)); } } } { //weapons int r = rand.Next() % 50; if (r == 0) { int w = 1 + rand.Next() % (items.Length - 1); items[w].Alloc(Tile.CoordToWorld(x, y)); } } } } } //Add the earth's core earthCore = Dup(earthCorePrefab); earthCore.transform.position = new Vector3(width / 2, -height - 25, 0); }