Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MapGeneration()
- {
- //Seed Rand
- rand = new System.Random(System.DateTime.Now.Millisecond);
- //Generate Floor
- List<Vector3> verts = new List<Vector3>();
- verts.Add(new Vector2(levelLength, -mapHeight));
- verts.Add(new Vector2(0, -mapHeight));
- float max = mapHeight - 1;
- verts.Add(new Vector2(0, -max));
- float lastY = -max;
- float currentX = 0;
- int randVal;
- while (currentX < levelLength - 2 * max)
- {
- randVal = rand.Next(10, 50);
- currentX += randVal;
- verts.Add(new Vector2(currentX, lastY));
- randVal = (rand.Next() % 4);
- float newY = 0;
- switch (randVal)
- {
- case (0):
- newY = -max;
- break;
- case (1):
- newY = -max / 2;
- break;
- case (2):
- newY = 0;
- break;
- case (3):
- newY = max / 2;
- break;
- }
- currentX += Mathf.Abs(lastY - newY);
- verts.Add(new Vector2(currentX, newY));
- lastY = newY;
- }
- if (lastY == -max)
- {
- verts.Add(new Vector2(levelLength, -max));
- }
- if(lastY > -max)
- {
- //verts.Add(new Vector2(currentX + (lastY + max), -max));
- verts.Add(new Vector2(levelLength, -max));
- }
- GameObject g = new GameObject();
- g.AddComponent<PolygonGenerator>().vertices = verts.ToArray();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement