Ejemplo n.º 1
0
 public void OnDrawGizmos()
 {
     if (m_clusterColorKey != "")
     {
         Gizmos.color = cubeGrid.GetSphereColorByKey(m_clusterColorKey);
         foreach (ClickableCube cube in m_Cubes)
         {
             Vector3 pos = new Vector3(cube.coord.x, cube.coord.y, 1.0f) - cubeGrid.transform.position;
             Gizmos.DrawCube(pos, Vector3.one);
         }
     }
 }
Ejemplo n.º 2
0
 public void Initialize(Vector3[] a_endPoint, Vector2Int a_destinationCoord, string a_colorKey, float a_sphereSpeed, CubeGrid a_cubeGrid, Turret a_turret)
 {
     m_positions        = a_endPoint;
     m_endPoint         = m_positions[0];
     m_colorKey         = a_colorKey;
     m_destinationCoord = a_destinationCoord;
     m_sphereSpeed      = a_sphereSpeed;
     m_cubeGrid         = a_cubeGrid;
     m_turret           = a_turret;
     m_startPoint       = transform.position;
     GetComponent <Renderer>().material.color = m_cubeGrid.GetSphereColorByKey(a_colorKey);
     m_posIndex = 0;
 }
Ejemplo n.º 3
0
    public void Fire()
    {
        if (m_nextSphereColorKey != "")
        {
            string colorKey = m_nextSphereColorKey;

            bool           coordFound = false;
            List <Vector3> positions  = new List <Vector3>();
            positions.Add(muzzle.transform.position);
            Vector3 rayDir   = muzzle.transform.forward;
            Vector3 rayStart = muzzle.transform.position;

            while (!coordFound)
            {
                RaycastHit outHit = new RaycastHit();
                if (Physics.SphereCast(rayStart, 0.1f, rayDir, out outHit, 100.0f, LayerMask.GetMask("ClickableCube")))
                {
                    Vector3 endPoint = outHit.point + outHit.normal * 0.5f;
                    positions.Add(endPoint);

                    if (outHit.collider.gameObject.tag == "Jewel")
                    {
                        Vector2Int destinationCoord = outHit.collider.gameObject.GetComponent <ClickableCube>().coord;
                        Vector2    fnormal          = new Vector2(outHit.normal.x, outHit.normal.y);
                        if (fnormal.x != 0 && fnormal.y != 0)
                        {
                            if (Mathf.Abs(fnormal.x) >= Mathf.Abs(fnormal.y))
                            {
                                fnormal.y = 0;
                            }
                            else
                            {
                                fnormal.x = 0;
                            }
                        }
                        Vector2Int adjustment = new Vector2Int(Mathf.RoundToInt(fnormal.x), Mathf.RoundToInt(fnormal.y));
                        destinationCoord += adjustment;

                        Sphere sphere = Instantiate(spherePrefab, muzzle.transform.position, muzzle.transform.rotation, null).GetComponent <Sphere>();
                        //Call initialize on Sphere passing in the coord, the endPoint, the collor, the sphereSpeed, the cubeGrid reference and the turret reference
                        sphere.Initialize(positions.ToArray(), destinationCoord, colorKey, sphereSpeed, cubeGrid, this);
                        coordFound = true;
                    }
                    if (outHit.collider.gameObject.tag == "Bouncer")
                    {
                        Vector3 projection = Vector3.Project(rayDir, outHit.normal);
                        rayDir  -= 2 * projection;
                        rayStart = endPoint;
                    }
                    if (outHit.collider.gameObject.tag == "Root")
                    {
                        IntVector2 temp             = outHit.collider.gameObject.GetComponent <RootRail>().RootCoord;
                        Vector2Int destinationCoord = new Vector2Int(temp.x, temp.y);
                        Sphere     sphere           = Instantiate(spherePrefab, muzzle.transform.position, muzzle.transform.rotation, null).GetComponent <Sphere>();
                        //Call initialize on Sphere passing in the coord, the endPoint, the collor, the sphereSpeed, the cubeGrid reference and the turret reference
                        sphere.Initialize(positions.ToArray(), destinationCoord, colorKey, sphereSpeed, cubeGrid, this);
                        coordFound = true;
                    }
                }
                else
                {
                    break;
                }
            }
            if (coordFound)
            {
                gohstJewel.gameObject.SetActive(false);
                m_nextSphereColorKey = "";
                jewel.GetComponent <Renderer>().material.color = cubeGrid.GetSphereColorByKey(m_nextSphereColorKey);
            }
        }
    }