Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*\
- | |
- | Made by Jason Helman © Jason Tech And Games |
- | I do not condone the use of my work without my permission |
- | |
- \*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- using System;
- using UnityEngine;
- public class LevelController : MonoBehaviour
- {
- public GameObject[,] board;
- public GameObject upLeft, upRight, downLeft, downRight, up, down, left, right, middle;
- // public GameObject scriptHolder;
- public Transform parent;
- private MovementController movementController;
- private BulletCreator bulletCreator;
- private System.Random random;
- public void Start()
- {
- movementController = GetComponent<MovementController>(); // this is going on the scriptHolder so doesn't need anything (it is technically a this.* etc)
- bulletCreator = GetComponent<BulletCreator>();
- CreateLevel(6, 5);
- }
- public void CallFromEditor()
- {
- CreateLevel(5, 6);
- }
- public void CreateLevel(int length, int width)
- {
- if(board != null)
- foreach (GameObject obj in board)
- Destroy(obj);
- board = new GameObject[length, width];
- int randomPos = UnityEngine.Random.Range(0, 2);
- Color color = UnityEngine.Random.ColorHSV();
- switch (randomPos)
- {
- case 0:
- color.r = 1.0f;
- color.b = 1.0f - color.g;
- break;
- case 1:
- color.g = 1.0f;
- color.b = 1.0f - color.r;
- break;
- default:
- color.b = 1.0f;
- color.g = 1.0f - color.r;
- break;
- }
- Vector3 temp = new Vector3(0,0,0);
- Color.RGBToHSV(color, out temp.x, out temp.y, out temp.z);
- // temp[0] += 0.5f;
- // temp[0] %= 1f;
- temp[1] -= 0.25f;
- temp[2] -= 0.5f;
- Color bgColor = Color.HSVToRGB(temp.x, temp.y, temp.z);
- /*Color color = new Color(1f, 1f, 1f, 1f);
- if (randomPos == 0)
- {
- color[1] = Random.Range(0f, 1f);
- color[2] = Random.Range(0f, 1f);
- }
- else if (randomPos == 1)
- {
- color[0] = Random.Range(0f, 1f);
- color[2] = Random.Range(0f, 1f);
- }
- else
- {
- color[0] = Random.Range(0f, 1f);
- color[1] = Random.Range(0f, 1f);
- }*/
- // Color bgColor = color;
- // bgColor[randomPos] -= 0.25f;
- Camera.main.backgroundColor = bgColor; // new Color(color[0] - 0.5f, color[1] - 0.5f, color[2] - 0.5f); // bgColor;
- float moveAmountLength = (-length / 2);
- if (length % 2 == 0)
- moveAmountLength += 0.5f;
- float moveAmountWidth = (width / 2);
- if (width % 2 == 0)
- moveAmountWidth -= 0.5f;
- for (int x = 0; x < length; x++)
- {
- for (int y = 0; y < width; y++)
- {
- board[x, y] =
- x == 0 && y == 0 ?
- Instantiate(upLeft, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
- x == length - 1 && y == 0 ?
- Instantiate(upRight, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
- x == 0 && y == width - 1 ?
- Instantiate(downLeft, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
- x == length - 1 && y == width - 1 ?
- Instantiate(downRight, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
- y == 0 ?
- Instantiate(up, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
- y == width - 1 ?
- Instantiate(down, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
- x == 0 ?
- Instantiate(left, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
- x == length - 1 ?
- Instantiate(right, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent) :
- Instantiate(middle, new Vector3(x + moveAmountLength, -y + moveAmountWidth, 0), Quaternion.identity, parent);
- /*Color color = new Color(255, 255, 255, 255);
- if(randomPos == 0)
- {
- color[1] = Random.Range(0, 255);
- color[2] = Random.Range(0, 255);
- }
- else if(randomPos == 1)
- {
- color[0] = Random.Range(0, 255);
- color[2] = Random.Range(0, 255);
- }
- else
- {
- color[0] = Random.Range(0, 255);
- color[1] = Random.Range(0, 255);
- }*/
- board[x, y].GetComponent<SpriteRenderer>().color = color;
- }
- }
- movementController.CreatePlayerBoard(length, width);
- ChangeRandom();
- ThinkOfName(length, width);
- ThinkOfName(length, width);
- ThinkOfName(length, width);
- ThinkOfName(length, width);
- }
- public void ChangeRandom()
- {
- 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)
- }
- public void ThinkOfName(int length, int width)
- {
- // 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
- // random.Next(length * width);
- /*
- int side = random.Next(4); // 0 is top, rest go clockwise
- bool isVertical = side % 2 == 0;
- int pos = isVertical ? random.Next(length) : random.Next(width);
- Vector3 refObjLocation = isVertical ? board[pos, 0].transform.position : board[0, pos].transform.position;
- Vector3 locationToSpawnAt = isVertical ? ; // vert should be -6 or +6 for spawning and -10 or 10 for horizontal
- */
- int isLength = random.Next(2);
- int isPositive = random.Next(2);
- int pos = isLength == 0 ? random.Next(length) : random.Next(width);
- Vector3 spawnLocation;
- Vector3 moveDirection;
- if (isLength == 0)
- {
- if (isPositive == 0)
- {
- spawnLocation = new Vector3(board[pos, 0].transform.position.x, -6f, 0f);
- moveDirection = Vector3.up;
- }
- else
- {
- spawnLocation = new Vector3(board[pos, 0].transform.position.x, 6f, 0f);
- moveDirection = Vector3.down;
- }
- }
- else if(isPositive == 0)
- {
- spawnLocation = new Vector3(-10f, board[0, pos].transform.position.y, 0f);
- moveDirection = Vector3.right;
- }
- else
- {
- spawnLocation = new Vector3(10f, board[0, pos].transform.position.y, 0f);
- moveDirection = Vector3.left;
- }
- bulletCreator.CreateBullet(spawnLocation, moveDirection, 1f * 0.25f); // Last number is bullet move speed, which should be based off of the level #!!!
- // FunctionThatSpawnsAndMoves((vec3) spawnPos, (vec3) moveDir)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement