Mountain Grid

>Mountain has a grid
>King can place on the mountain
>Objects are proberly rotated
>KingGrid has begun to be cleaned up
>Grid Reveal no longer cuts off rows
This commit is contained in:
Katherine
2022-03-21 12:26:27 -05:00
parent b8dbb271c6
commit 9ce623bda0
7 changed files with 554732 additions and 843650 deletions

View File

@@ -7,10 +7,10 @@ public class GridReveal : MonoBehaviour
private GameObject[] Rows;
private float TempKingPos = 0;
private int Index = 0;
private int ROSCount = 100;
private int ROSCount = 105;
private int BoxSize = 20;
private int ValleyStr = -670;
private int MountainStr = -2960;
private int MountainStr = -3700;
void Start() {
List<GameObject> RowsList = new List<GameObject>();
@@ -40,7 +40,7 @@ public class GridReveal : MonoBehaviour
}
else if (MovDir >= 0) { //Moving Right
Rows[Index].SetActive(false);//Deactivates Leftmost
if (Index <= (Rows.Length - 1) - ROSCount) {//Prevents OfB error
if (Index <= (Rows.Length) - ROSCount) {//Prevents OfB error
Rows[Index + ROSCount].SetActive(true);//Activates Rightmost
Index++;
}

View File

@@ -11,6 +11,7 @@ public class HailArea : MonoBehaviour
private float Zmax = -85f;
private float Zmin = -115f;
private int Ytop = 600;
int Lifetime = 0;
public GameObject Hail;
@@ -31,9 +32,9 @@ public class HailArea : MonoBehaviour
//Random pos X Xmax-radius -> Xmin+radius
//Random pos Z Zmax-radius -> Zmin+radius
Vector3 position = new Vector3(Random.Range(Xmin + radius, Xmax - radius), 100, Random.Range(Zmin + radius, Zmax - radius));//Finds where the hail will spawn in the air
Vector3 position = new Vector3(Random.Range(Xmin + radius, Xmax - radius), Ytop, Random.Range(Zmin + radius, Zmax - radius));//Finds where the hail will spawn in the air
if (Physics.Raycast(position, transform.TransformDirection(Vector3.down), out hit, float.MaxValue, LayerMask)) {//Raycasts to find where the ground is
height = 100 - hit.distance;
height = Ytop - hit.distance;
}
position = new Vector3(position.x, 100+height, position.z); //find ground and set y occordingly

View File

@@ -14,6 +14,7 @@ public class KingPlace : NetworkBehaviour
public GameObject HailObject;
public GameObject Slime;
private GameObject Grid;
private GameObject MountGrid;
public GameObject Panel;
private GameObject Place;
private GameObject PlaceTemp = null;
@@ -32,6 +33,10 @@ public class KingPlace : NetworkBehaviour
private KingAbility KAHail = new KingAbility(2, 15);
private KingAbility KAThund = new KingAbility(2, 10);
private float[] MountPlats = { 303.41f, 315.5f, 330.5f, 345.5f, 360.5f, 400.5f, 415.5f, 430.5f, 470.5f, 485.5f, 500.5f };
private float[] MountxOffsets = { -50f, -73.4f, -100f, -127f, -134.7f, -130f, -34f, 14.5f, 91.2f, 129f, 129.5f };
private float[] MountzOffsets = { 130f, 120f, 97f, 56.6f, 32f, -50f, -135.5f, -138.5f, -105f, -52.5f, 50f };
public GameObject Thunderstorm;
//Is called when the King clicks on the Thunderstorm button
public void OnThunderClicked()
@@ -50,6 +55,7 @@ public class KingPlace : NetworkBehaviour
void Awake()
{
Grid = GameObject.FindGameObjectWithTag("KingGrid");
MountGrid = Grid.transform.Find("MountainGrid").gameObject;
}
bool Avaliable;
@@ -72,6 +78,7 @@ public class KingPlace : NetworkBehaviour
}
if (Avaliable == true) {
MenuOff();
Panel.GetComponent<RadialMenu>().PlaceObj(ID);
//Create the object that will follow the Mouse
PlaceTemp = Instantiate(Place);
//Layout the grid
@@ -109,6 +116,7 @@ public class KingPlace : NetworkBehaviour
}
if (Input.GetMouseButtonUp(0)) {//Reads the player releasing the left mouse button
CreateHail();
MenuOff();
KAHail.UseItem();
}
}
@@ -120,6 +128,7 @@ public class KingPlace : NetworkBehaviour
child.gameObject.SetActive(false);
}
SlimePlacing = false;
MenuOff();
KASlime.UseItem();
}
}
@@ -138,11 +147,45 @@ public class KingPlace : NetworkBehaviour
int xOffset = 101;
int zOffset = 906;
int boxsize = 20;
float MountxOffset = -50f;
float MountzOffset = 130f;
private GameObject Row;
private GameObject Platform;
Vector3 spawnLoc;
private void FindGridBox() {
int RowNumb = 0, Box = 0, x = 0, z = 0;
if (PlaceTemp.transform.position.x < MontStr.x) {//King is trying to place on the mountain
Debug.Log("Mount Place");
Platform = null;
bool found = false;
for(int i = 0; i < MountPlats.Length; i++) {
if (MountPlats[i] == PlaceTemp.transform.position.y) {//Finds the platform by comparing y values
Platform = MountGrid.transform.Find("Platform" + i).gameObject;//Sets the platform and offsets for that platform
MountxOffset = MountxOffsets[i];
MountzOffset = MountzOffsets[i];
break;//Breaks out when it finds the platform
}
}
if (Platform != null) {//Makes sure it found a platform, so there are no null refs
foreach (Transform row in Platform.transform) { //Looks through every row on the platform
foreach (Transform box in row) {//Looks at every Box in the row
if (PlaceTemp.transform.position.x <= (box.transform.position.x-MountxOffset) + boxsize / 2 && PlaceTemp.transform.position.x >= (box.transform.position.x-MountxOffset) - boxsize / 2) {//Sees if the x fits within the box
if (PlaceTemp.transform.position.z <= (box.transform.position.z-MountzOffset) + boxsize / 2 && PlaceTemp.transform.position.z >= (box.transform.position.z-MountzOffset) - boxsize / 2) {//Sees if the z fits within the box
found = true;
Vector3 rot = row.transform.rotation.eulerAngles;
PlaceTemp.transform.Rotate(0, (rot.y-90), 0);//Sets the object's rotation to the rows rotation
spawnLoc = new Vector3(box.transform.position.x-MountxOffset, PlaceTemp.transform.position.y, box.transform.position.z-MountzOffset);//Sets the object's location
break;//Breaks out from the loops when found
}
}
}
if (found == true) {//Stops it from going through all the rows
Grid.GetComponent<GridReveal>().GridSwitch(false); //Switch off the grid
FirstPlacing = false;
break;
}
}
}
}
else {
float i = ((PlaceTemp.transform.position.x) - xOffset) / -BoxSize; //Finds the Row the cursor is in
@@ -151,14 +194,14 @@ public class KingPlace : NetworkBehaviour
Box = (int)y; //Rounds it down
x = (RowNumb * -BoxSize) + xOffset;//Sets it's X to the X of the Row
z = (Box * -BoxSize) + zOffset;//Sets its Z to the Z of the Box
// Grid Check first for valid location
GridCheck(RowNumb, Box, ref FirstPlacing);//Makes sure the Box is a valid position
// Calculate the position to spawn at
spawnLoc = new Vector3(x, PlaceTemp.transform.position.y, z);
}
// Grid Check first for valid location
GridCheck(RowNumb, Box, ref FirstPlacing);//Makes sure the Box is a valid position
// Instantiate a networked box at the position
if (FirstPlacing == false) {
// Calculate the position to spawn at
Vector3 spawnLoc = new Vector3(x, PlaceTemp.transform.position.y, z);
if (FirstPlacing == false) {
PlaceTemp.transform.position = spawnLoc;
@@ -168,6 +211,7 @@ public class KingPlace : NetworkBehaviour
// Remove the reference to PlaceTemp
Destroy(PlaceTemp);
MenuOff();
KABlock.UseItem();
}
@@ -204,15 +248,58 @@ public class KingPlace : NetworkBehaviour
}
}
private void CreateHail() {//TODO make sure it makes a box/actually make the Hail Area
float i = ((HailCorner.transform.position.x) - xOffset) / -BoxSize; //Finds the Row the cursor is in
int RowNumb = (int)i; //Rounds it down
float y = ((HailCorner.transform.position.z) - zOffset) / -BoxSize; //Finds the Box in the Row the cursor is in
int Box = (int)y; //Rounds it down
int x = (RowNumb * -BoxSize) + xOffset;//Sets it's X to the X of the Row
int z = (Box * -BoxSize) + zOffset;//Sets its Z to the Z of the Box
HailCorner.transform.position = new Vector3(x, HailCorner.transform.position.y, z);//fully snaps it to the grid
GridCheck(RowNumb, Box, ref HailPlacing);//Makes sure the Box is a valid position
private void CreateHail() {
if (PlaceTemp.transform.position.x < MontStr.x)
{//King is trying to place on the mountain
Platform = null;
bool found = false;
for (int i = 0; i < MountPlats.Length; i++)
{
if (MountPlats[i] == PlaceTemp.transform.position.y)
{//Finds the platform by comparing y values
Platform = MountGrid.transform.Find("Platform" + i).gameObject;//Sets the platform and offsets for that platform
MountxOffset = MountxOffsets[i];
MountzOffset = MountzOffsets[i];
break;//Breaks out when it finds the platform
}
}
if (Platform != null)
{//Makes sure it found a platform, so there are no null refs
foreach (Transform row in Platform.transform)
{ //Looks through every row on the platform
foreach (Transform box in row)
{//Looks at every Box in the row
if (HailCorner.transform.position.x <= (box.transform.position.x - MountxOffset) + boxsize / 2 && HailCorner.transform.position.x >= (box.transform.position.x - MountxOffset) - boxsize / 2)
{//Sees if the x fits within the box
if (HailCorner.transform.position.z <= (box.transform.position.z - MountzOffset) + boxsize / 2 && HailCorner.transform.position.z >= (box.transform.position.z - MountzOffset) - boxsize / 2)
{//Sees if the z fits within the box
found = true;
Vector3 rot = row.transform.rotation.eulerAngles;
HailCorner.transform.position = new Vector3(box.transform.position.x - MountxOffset, HailCorner.transform.position.y, box.transform.position.z - MountzOffset);//Sets the object's location
break;//Breaks out from the loops when found
}
}
}
if (found == true)
{//Stops it from going through all the rows
Grid.GetComponent<GridReveal>().GridSwitch(false); //Switch off the grid
HailPlacing = false;
break;
}
}
}
}
else
{
float i = ((HailCorner.transform.position.x) - xOffset) / -BoxSize; //Finds the Row the cursor is in
int RowNumb = (int)i; //Rounds it down
float y = ((HailCorner.transform.position.z) - zOffset) / -BoxSize; //Finds the Box in the Row the cursor is in
int Box = (int)y; //Rounds it down
int x = (RowNumb * -BoxSize) + xOffset;//Sets it's X to the X of the Row
int z = (Box * -BoxSize) + zOffset;//Sets its Z to the Z of the Box
HailCorner.transform.position = new Vector3(x, HailCorner.transform.position.y, z);//fully snaps it to the grid
GridCheck(RowNumb, Box, ref HailPlacing);//Makes sure the Box is a valid position
}
//Instanciate HailArea based on PlaceTemp = Top Left and HailCorner = Bottom Right
if (HailPlacing == false) {
GameObject Temp;

View File

@@ -1,12 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RadialMenu : MonoBehaviour
{
bool UIOn = false;
public GameObject King;
[SerializeField]
private Text UItext;
// Update is called once per frame
void Update()
{
@@ -26,6 +29,7 @@ public class RadialMenu : MonoBehaviour
private void MenuOn()
{
UItext.text = "Press E to Close Menu";
foreach (Transform child in transform) { //Turns on all of the different buttons attached to this panel and stops it from moving
child.gameObject.SetActive(true);
UIOn = true;
@@ -34,9 +38,26 @@ public class RadialMenu : MonoBehaviour
public void MenuOff()
{
UItext.text = "Press Q to Open Menu";
foreach (Transform child in transform) { //Turns off all of the different buttons attached to this panel and starts it moving again
child.gameObject.SetActive(false);
UIOn = false;
}
}
public void PlaceObj(int ID)
{
switch (ID)
{//Parses in the button clicked into the right object that the King is placing
case 0:
UItext.text = "Click to Place the Block";
break;
case 1:
UItext.text = "Click and Hold to Resize the Hail's Area";
break;
case 2:
UItext.text = "Click and Hold to Determine the Slime's Direction";
break;
}
}
}