Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. void MapGeneration()
  2. {
  3. //Seed Rand
  4. rand = new System.Random(System.DateTime.Now.Millisecond);
  5.  
  6. //Generate Floor
  7. List<Vector3> verts = new List<Vector3>();
  8. verts.Add(new Vector2(levelLength, -mapHeight));
  9. verts.Add(new Vector2(0, -mapHeight));
  10.  
  11. float max = mapHeight - 1;
  12.  
  13. verts.Add(new Vector2(0, -max));
  14. float lastY = -max;
  15. float currentX = 0;
  16.  
  17. int randVal;
  18.  
  19. while (currentX < levelLength - 2 * max)
  20. {
  21. randVal = rand.Next(10, 50);
  22.  
  23. currentX += randVal;
  24. verts.Add(new Vector2(currentX, lastY));
  25.  
  26.  
  27. randVal = (rand.Next() % 4);
  28. float newY = 0;
  29. switch (randVal)
  30. {
  31. case (0):
  32. newY = -max;
  33. break;
  34. case (1):
  35. newY = -max / 2;
  36. break;
  37. case (2):
  38. newY = 0;
  39. break;
  40. case (3):
  41. newY = max / 2;
  42. break;
  43. }
  44.  
  45. currentX += Mathf.Abs(lastY - newY);
  46. verts.Add(new Vector2(currentX, newY));
  47. lastY = newY;
  48. }
  49.  
  50. if (lastY == -max)
  51. {
  52. verts.Add(new Vector2(levelLength, -max));
  53. }
  54.  
  55. if(lastY > -max)
  56. {
  57. //verts.Add(new Vector2(currentX + (lastY + max), -max));
  58. verts.Add(new Vector2(levelLength, -max));
  59. }
  60.  
  61. GameObject g = new GameObject();
  62. g.AddComponent<PolygonGenerator>().vertices = verts.ToArray();
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement