Advertisement
JJCUBER

Untitled

Dec 29th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.33 KB | None | 0 0
  1. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*\
  2. |                                                               |
  3. |          Made by Jason Helman © Jason Tech And Games          |
  4. |   I do not condone the use of my work without my permission   |
  5. |                                                               |
  6. \*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  7.  
  8. using System;
  9. using UnityEngine;
  10.  
  11. public class LevelController : MonoBehaviour
  12. {
  13.     public GameObject[,] board;
  14.     public GameObject upLeft, upRight, downLeft, downRight, up, down, left, right, middle;
  15.     // public GameObject scriptHolder;
  16.     public Transform parent;
  17.  
  18.     private MovementController movementController;
  19.     private BulletCreator bulletCreator;
  20.     private System.Random random;
  21.  
  22.  
  23.     public void Start()
  24.     {
  25.         movementController = GetComponent<MovementController>(); // this is going on the scriptHolder so doesn't need anything (it is technically a this.* etc)
  26.         bulletCreator = GetComponent<BulletCreator>();
  27.         CreateLevel(6, 5);
  28.     }
  29.  
  30.     public void CallFromEditor()
  31.     {
  32.         CreateLevel(5, 6);
  33.     }
  34.  
  35.     public void CreateLevel(int length, int width)
  36.     {
  37.         if(board != null)
  38.             foreach (GameObject obj in board)
  39.                 Destroy(obj);
  40.         board = new GameObject[length, width];
  41.  
  42.         int randomPos = UnityEngine.Random.Range(0, 2);
  43.         Color color = UnityEngine.Random.ColorHSV();
  44.         switch (randomPos)
  45.         {
  46.             case 0:
  47.                 color.r = 1.0f;
  48.                 color.b = 1.0f - color.g;
  49.                 break;
  50.             case 1:
  51.                 color.g = 1.0f;
  52.                 color.b = 1.0f - color.r;
  53.                 break;
  54.             default:
  55.                 color.b = 1.0f;
  56.                 color.g = 1.0f - color.r;
  57.                 break;
  58.         }
  59.         Vector3 temp = new Vector3(0,0,0);
  60.         Color.RGBToHSV(color, out temp.x, out temp.y, out temp.z);
  61.         // temp[0] += 0.5f;
  62.         // temp[0] %= 1f;
  63.         temp[1] -= 0.25f;
  64.         temp[2] -= 0.5f;
  65.         Color bgColor = Color.HSVToRGB(temp.x, temp.y, temp.z);
  66.  
  67.         /*Color color = new Color(1f, 1f, 1f, 1f);
  68.         if (randomPos == 0)
  69.         {
  70.             color[1] = Random.Range(0f, 1f);
  71.             color[2] = Random.Range(0f, 1f);
  72.         }
  73.         else if (randomPos == 1)
  74.         {
  75.             color[0] = Random.Range(0f, 1f);
  76.             color[2] = Random.Range(0f, 1f);
  77.  
  78.         }
  79.         else
  80.         {
  81.             color[0] = Random.Range(0f, 1f);
  82.             color[1] = Random.Range(0f, 1f);
  83.         }*/
  84.  
  85.         // Color bgColor = color;
  86.         // bgColor[randomPos] -= 0.25f;
  87.         Camera.main.backgroundColor = bgColor; // new Color(color[0] - 0.5f, color[1] - 0.5f, color[2] - 0.5f); // bgColor;
  88.         float moveAmountLength = (-length / 2);
  89.         if (length % 2 == 0)
  90.             moveAmountLength += 0.5f;
  91.         float moveAmountWidth = (width / 2);
  92.         if (width % 2 == 0)
  93.             moveAmountWidth -= 0.5f;
  94.         for (int x = 0; x < length; x++)
  95.         {
  96.             for (int y = 0; y < width; y++)
  97.             {
  98.                 board[x, y] =
  99.                     x == 0 && y == 0 ?
  100.                         Instantiate(upLeft, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
  101.                             x == length - 1 && y == 0 ?
  102.                                 Instantiate(upRight, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
  103.                                     x == 0 && y == width - 1 ?
  104.                                         Instantiate(downLeft, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
  105.                                             x == length - 1 && y == width - 1 ?
  106.                                                 Instantiate(downRight, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
  107.                                                     y == 0 ?
  108.                                                         Instantiate(up, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
  109.                                                             y == width - 1 ?
  110.                                                                 Instantiate(down, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
  111.                                                                     x == 0 ?
  112.                                                                         Instantiate(left, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
  113.                                                                             x == length - 1 ?
  114.                                                                                 Instantiate(right, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
  115.                                                                                     Instantiate(middle, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent);
  116.  
  117.  
  118.                 /*Color color = new Color(255, 255, 255, 255);
  119.                 if(randomPos == 0)
  120.                 {
  121.                     color[1] = Random.Range(0, 255);
  122.                     color[2] = Random.Range(0, 255);
  123.                 }
  124.                 else if(randomPos == 1)
  125.                 {
  126.                     color[0] = Random.Range(0, 255);
  127.                     color[2] = Random.Range(0, 255);
  128.  
  129.                 }
  130.                 else
  131.                 {
  132.                     color[0] = Random.Range(0, 255);
  133.                     color[1] = Random.Range(0, 255);
  134.                 }*/
  135.  
  136.  
  137.                 board[x, y].GetComponent<SpriteRenderer>().color = color;
  138.             }
  139.         }
  140.         movementController.CreatePlayerBoard(length, width);
  141.         ChangeRandom();
  142.         ThinkOfName(length, width);
  143.         ThinkOfName(length, width);
  144.         ThinkOfName(length, width);
  145.         ThinkOfName(length, width);
  146.     }
  147.  
  148.     public void ChangeRandom()
  149.     {
  150.         random = new System.Random(010101); // system random is different than unity random, system is able to have obj like this, but unity on is 100% static / one instantiate obj (for this case I didn't want to affect Random globally)
  151.     }
  152.  
  153.     public void ThinkOfName(int length, int width)
  154.     {
  155.         // below should have a random seed of the level to make the level be the same each playthrough, 3 sets of 2 digits for world -- group -- level
  156.         // random.Next(length * width);
  157.        
  158.         /*
  159.         int side = random.Next(4); // 0 is top, rest go clockwise
  160.         bool isVertical = side % 2 == 0;
  161.         int pos = isVertical ? random.Next(length) : random.Next(width);
  162.         Vector3 refObjLocation = isVertical ? board[pos, 0].transform.position : board[0, pos].transform.position;
  163.         Vector3 locationToSpawnAt = isVertical ? ; // vert should be -6 or +6 for spawning and -10 or 10 for horizontal
  164.         */
  165.  
  166.         int isLength = random.Next(2);
  167.         int isPositive = random.Next(2);
  168.         int pos = isLength == 0 ? random.Next(length) : random.Next(width);
  169.         Vector3 spawnLocation;
  170.         Vector3 moveDirection;
  171.         if (isLength == 0)
  172.         {
  173.             if (isPositive == 0)
  174.             {
  175.                 spawnLocation = new Vector3(board[pos, 0].transform.position.x, -6f, 0f);
  176.                 moveDirection = Vector3.up;
  177.             }
  178.             else
  179.             {
  180.                 spawnLocation = new Vector3(board[pos, 0].transform.position.x, 6f, 0f);
  181.                 moveDirection = Vector3.down;
  182.             }
  183.         }
  184.         else if(isPositive == 0)
  185.         {
  186.             spawnLocation = new Vector3(-10f, board[0, pos].transform.position.y, 0f);
  187.             moveDirection = Vector3.right;
  188.         }
  189.         else
  190.         {
  191.             spawnLocation = new Vector3(10f, board[0, pos].transform.position.y, 0f);
  192.             moveDirection = Vector3.left;
  193.         }
  194.  
  195.  
  196.         bulletCreator.CreateBullet(spawnLocation, moveDirection, 1f * 0.25f); // Last number is bullet move speed, which should be based off of the level #!!!
  197.         // FunctionThatSpawnsAndMoves((vec3) spawnPos, (vec3) moveDir)
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement