示例#1
0
文件: Teams.cs 项目: Volday/NPlanet
        public void SetPartsOfPlanet(PartOfPlanet startPart, List <PartOfPlanet> mainland, int partCount, int teamIndex)
        {
            mainland.Remove(startPart);
            partsOfPlanet.Add(startPart);
            startPart.teamIndex = teamIndex;

            startPoint = startPart.GetPart().transform.position;

            Dictionary <float, PartOfPlanet> distanceAndParts = new Dictionary <float, PartOfPlanet>();

            float[] parts = new float[mainland.Count];
            for (int t = 0; t < mainland.Count; t++)
            {
                float distance = MyMath.sqrDistanceFromPointToPoint(startPart.GetPart().transform.position, mainland[t].GetPart().transform.position);
                if (distanceAndParts.ContainsKey(distance))
                {
                    distance = distance + 0.00101f;
                }
                parts[t] = distance;
                distanceAndParts.Add(distance, mainland[t]);
            }
            Array.Sort(parts);
            for (int t = 0; t < partCount; t++)
            {
                partsOfPlanet.Add(distanceAndParts[parts[t]]);
                distanceAndParts[parts[t]].teamIndex = teamIndex;
                mainland.Remove(distanceAndParts[parts[t]]);
            }
        }
示例#2
0
 public void Attack(PartOfPlanet partOfPlanet)
 {
     if (cooldown < currentCooldown)
     {
         if (MyMath.sqrDistanceFromPointToPoint(partOfPlanet.GetPart().transform.position, transform.position) < Range * Range)
         {
             currentCooldown = 0;
             GameObject newAirplane = Instantiate(airplane, transform.position, Quaternion.identity);
             newAirplane.GetComponent <Airplain>().partOfPlanet = partOfPlanet;
             newAirplane.GetComponent <Airplain>().teamIndex    = teamIndex;
             newAirplane.GetComponent <Move>().SetDirection(partOfPlanet.GetPart().gameObject.transform.position);
         }
     }
 }
示例#3
0
 private void Update()
 {
     currentCooldown += Time.deltaTime;
     rngMoveCooldown -= Time.deltaTime;
     if (GetComponent <Move>().target == Vector3.zero && toMove.Count != 0)
     {
         PartOfPlanet nextPartOfPlanet = toMove[toMove.Count - 1];
         toMove.RemoveAt(toMove.Count - 1);
         GetComponent <Move>().SetDirection(nextPartOfPlanet.GetPart().transform.position);
         currentPart = nextPartOfPlanet;
     }
     if (currentCooldown < cooldown)
     {
         airplaneOwn.SetActive(false);
     }
     else
     {
         airplaneOwn.SetActive(true);
     }
     if (teamIndex != 0 && rngMoveCooldown < 0)
     {
         MoveToTarget(planet.GetComponent <Teams>().Mix(planet.GetComponent <Teams>().water)
                      [Random.Range(0, planet.GetComponent <Teams>().water.Count)].GetPart());
         rngMoveCooldown = Random.Range(1, 20);
     }
 }
示例#4
0
文件: Port.cs 项目: Volday/NPlanet
    public void Respawn()
    {
        planet = GameObject.FindGameObjectWithTag("Planet");
        ship   = planet.GetComponent <Teams>().ship;
        if (partOfPlanet.GetNeighbors()[0].teamIndex == -1)
        {
            partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[0];
        }
        else
        {
            if (partOfPlanet.GetNeighbors()[1].teamIndex == -1)
            {
                partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[1];
            }
            else
            {
                partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[2];
            }
        }

        ship              = Instantiate(ship, partOfPlanetForSpawn.GetPart().transform.position, Quaternion.identity);
        carrier           = ship.GetComponent <Ship>();
        carrier.teamIndex = teamIndex;
        ship.GetComponent <Ship>().Spawn(partOfPlanetForSpawn, this);
        planet.GetComponent <Teams>().teams[teamIndex].carriers.Add(carrier);
        carrier.rngMoveCooldown = Random.Range(1, 20);
    }
示例#5
0
    public override void Create(PartOfPlanet partOfPlanet, int teamIndex)
    {
        GameObject planet = GameObject.FindGameObjectWithTag("Planet");

        if (planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].money >= 50000)
        {
            planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].money -= 50000;
            aeroportFull = planet.GetComponent <Teams>().aeroPortFull;
            GameObject created = Instantiate(aeroportFull, partOfPlanet.GetPart().transform.position, Quaternion.identity);
            planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].buildings.Add(created.GetComponent <Building>());
            partOfPlanet.full     = true;
            partOfPlanet.building = created.GetComponent <Building>();
            created.GetComponent <Building>().partOfPlanet = partOfPlanet;
            created.GetComponent <Building>().teamIndex    = teamIndex;
        }
    }
示例#6
0
 public void Spawn(PartOfPlanet partOfPlanet, Port myPort)
 {
     currentPart        = partOfPlanet;
     transform.position = currentPart.GetPart().transform.position;
     port = myPort;
 }
示例#7
0
文件: Nuke.cs 项目: Volday/NPlanet
    private void Update()
    {
        if (teamIndex != -2 && GetComponent <Move>().target == Vector3.zero)
        {
            GameObject planet = GameObject.FindGameObjectWithTag("Planet");
            Instantiate(planet.GetComponent <Teams>().NukeExplosion, transform.position, Quaternion.identity);

            if (partOfPlanet.teamIndex != teamIndex && partOfPlanet.teamIndex != -1)
            {
                planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].TakeDamage(planet.GetComponent <Teams>().nukeDamage, partOfPlanet, teamIndex);
            }

            List <GameObject> toDestroy = new List <GameObject>();
            for (int t = 0; t < planet.GetComponent <Teams>().teams.Length; t++)
            {
                for (int i = 0; i < planet.GetComponent <Teams>().teams[t].buildings.Count; i++)
                {
                    if (planet.GetComponent <Teams>().teams[t].buildings[i] != null &&
                        planet.GetComponent <Teams>().teams[t].buildings[i].teamIndex != teamIndex &&
                        MyMath.sqrDistanceFromPointToPoint(planet.GetComponent <Teams>().teams[t].buildings[i].transform.position,
                                                           partOfPlanet.GetPart().transform.position) < 4)
                    {
                        toDestroy.Add(planet.GetComponent <Teams>().teams[t].buildings[i].gameObject);
                    }
                }
            }

            for (int t = 0; t < planet.GetComponent <Teams>().teams.Length; t++)
            {
                for (int i = 0; i < planet.GetComponent <Teams>().teams[t].carriers.Count; i++)
                {
                    if (planet.GetComponent <Teams>().teams[t].carriers[i] != null &&
                        planet.GetComponent <Teams>().teams[t].carriers[i].teamIndex != teamIndex &&
                        MyMath.sqrDistanceFromPointToPoint(planet.GetComponent <Teams>().teams[t].carriers[i].transform.position,
                                                           partOfPlanet.GetPart().transform.position) < 5)
                    {
                        toDestroy.Add(planet.GetComponent <Teams>().teams[t].carriers[i].gameObject);
                    }
                }
            }

            for (int t = toDestroy.Count - 1; t > -1; t--)
            {
                if (toDestroy[t].GetComponent <Building>() != null)
                {
                    planet.GetComponent <Teams>().teams[toDestroy[t].GetComponent <Building>().teamIndex].buildings.Remove(toDestroy[t].GetComponent <Building>());
                    toDestroy[t].GetComponent <Building>().partOfPlanet.building = null;
                    toDestroy[t].GetComponent <Building>().partOfPlanet.full     = false;
                    toDestroy[t].GetComponent <Building>().LossBuilding();
                    toDestroy.RemoveAt(t);
                }
                else
                {
                    if (toDestroy[t].GetComponent <Ship>() != null)
                    {
                        toDestroy[t].GetComponent <Ship>().LossShip();
                        toDestroy.RemoveAt(t);
                    }
                }
            }
            Destroy(gameObject);
        }
    }
示例#8
0
    void Update()
    {
        if (!gameEnd)
        {
            if (planet.GetComponent <Teams>().teams[0].countries.Count <= 0)
            {
                youSuck.SetActive(true);
                gameEnd = true;
            }

            bool endTest = true;
            for (int t = 0; t < planet.GetComponent <Teams>().teams.Length; t++)
            {
                if (planet.GetComponent <Teams>().teams[t].countries.Count > 0)
                {
                    endTest = false;
                    break;
                }
            }

            if (endTest)
            {
                perfect.SetActive(true);
                gameEnd = true;
            }
        }
        else
        {
            if (timer > 0)
            {
                timer -= Time.deltaTime;
            }
        }

        if (timer <= 0)
        {
            perfect.SetActive(false);
            youSuck.SetActive(false);
        }

        money.text = "Money: " + planet.GetComponent <Teams>().teams[teamIndex].money;
        selectedCountryPopulation.text = "Selected Country Population: ";

        if (countrySelect)
        {
            RaycastHit hit;
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
            {
                GameObject   target             = hit.transform.gameObject;
                PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target);
                if (targetPartOfPlanet != null && targetPartOfPlanet.teamIndex >= 0)
                {
                    if (currentSelectedObject != null)
                    {
                        selectedCountryPopulation.text = "Selected Country Population: " + (int)currentSelectedObject.population;
                    }
                    if (currentSelectedObject != null && currentSelectedObject.parts.Contains(targetPartOfPlanet))
                    {
                    }
                    else
                    {
                        if (selectedCountry != null)
                        {
                            for (int t = 0; t < selectedCountry.Count; t++)
                            {
                                selectedCountry[t].GetPart().GetComponent <MeshRenderer>().sharedMaterial = planet.GetComponent <Teams>().teams[selectedCountry[t].teamIndex].material;
                            }
                        }
                        currentSelectedObject   = targetPartOfPlanet.country;
                        selectedCountry         = currentSelectedObject.parts;
                        currentSelectedMaterial = target.GetComponent <MeshRenderer>().sharedMaterial;
                        Vector4 newColor = new Vector4(0, 0, 0, 1);
                        newColor.x = currentSelectedMaterial.color.r + countrySelectColorShift;
                        newColor.y = currentSelectedMaterial.color.g + countrySelectColorShift;
                        newColor.z = currentSelectedMaterial.color.b + countrySelectColorShift;
                        selectedMaterial.SetColor("_BaseColor", newColor);
                        selectedMaterial.SetColor("_Color", newColor);
                        for (int t = 0; t < selectedCountry.Count; t++)
                        {
                            selectedCountry[t].GetPart().GetComponent <MeshRenderer>().sharedMaterial = selectedMaterial;
                        }
                    }
                }
                else
                {
                    currentSelectedObject = null;
                    if (selectedCountry != null)
                    {
                        for (int t = 0; t < selectedCountry.Count; t++)
                        {
                            selectedCountry[t].GetPart().GetComponent <MeshRenderer>().sharedMaterial = planet.GetComponent <Teams>().teams[selectedCountry[t].teamIndex].material;
                        }
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null)
        {
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    GameObject target = hit.transform.gameObject;
                    if (target.GetComponentInParent <Teams>() != null)
                    {
                        selectedUnit = null;
                        Destroy(currentWheel);
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ)
        {
            if (Input.GetMouseButtonDown(1) && selectedUnit == null)
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
                {
                    GameObject   target             = hit.transform.gameObject;
                    PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target);
                    if (targetPartOfPlanet.teamIndex == 0 && !targetPartOfPlanet.full)
                    {
                        GameObject newWheel = Instantiate(Wheel, targetPartOfPlanet.GetPart().transform.position, Quaternion.identity);
                        if (currentWheel != null)
                        {
                            Destroy(currentWheel);
                        }
                        selectedUnit      = null;
                        currentWheel      = newWheel;
                        wheelPartOfPlanet = targetPartOfPlanet;
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <Ship>() != null && selectedUnit.GetComponent <Ship>().teamIndex == 0)
        {
            if (Input.GetMouseButtonDown(1))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
                {
                    GameObject   target             = hit.transform.gameObject;
                    PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target);
                    bool         itsAShip           = false;
                    if (Physics.Raycast(ray, out hit, Mathf.Infinity) && hit.transform.gameObject.GetComponent <Ship>() != null &&
                        hit.transform.gameObject.GetComponent <Ship>().teamIndex == teamIndex)
                    {
                        itsAShip = true;
                    }
                    if (target.GetComponentInParent <Teams>() != null && (targetPartOfPlanet.teamIndex != -1 || itsAShip))
                    {
                        selectedUnit.GetComponent <Ship>().Attack(targetPartOfPlanet);
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <Ship>() != null && selectedUnit.GetComponent <Ship>().teamIndex == 0)
        {
            if (Input.GetMouseButtonDown(2))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
                {
                    GameObject   target             = hit.transform.gameObject;
                    PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target);
                    if (target.GetComponentInParent <Teams>() != null)
                    {
                        selectedUnit.GetComponent <Ship>().Attack(targetPartOfPlanet);
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <NukeSetap>() != null && selectedUnit.GetComponent <NukeSetap>().teamIndex == 0)
        {
            if (Input.GetMouseButtonDown(1))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
                {
                    GameObject target = hit.transform.gameObject;
                    if (target.GetComponentInParent <Teams>() != null)
                    {
                        PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target);
                        selectedUnit.GetComponent <NukeSetap>().Attack(targetPartOfPlanet);
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <Aeroport>() != null && selectedUnit.GetComponent <Aeroport>().teamIndex == 0)
        {
            if (Input.GetMouseButtonDown(1))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
                {
                    GameObject target = hit.transform.gameObject;
                    if (target.GetComponentInParent <Teams>() != null)
                    {
                        PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target);
                        selectedUnit.GetComponent <Aeroport>().Attack(targetPartOfPlanet);
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ&& currentWheel != null)
        {
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    GameObject target = hit.transform.gameObject;
                    if (target.GetComponent <wheel>() != null && wheelPartOfPlanet != null)
                    {
                        Destroy(currentWheel);
                        target.GetComponent <wheel>().Create(wheelPartOfPlanet, teamIndex);
                        wheelPartOfPlanet = null;
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <Ship>() != null)
        {
            if (Input.GetMouseButtonDown(1))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
                {
                    GameObject   target             = hit.transform.gameObject;
                    PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target);
                    if (targetPartOfPlanet.teamIndex == -1 &&
                        selectedUnit.GetComponent <Ship>().currentPart != targetPartOfPlanet)
                    {
                        selectedUnit.GetComponent <Ship>().MoveToTarget(target);
                    }
                }
            }
        }

        if (!Menu.GetComponent <Menu>().activ)
        {
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, unitsLayer))
                {
                    GameObject target = hit.transform.gameObject;
                    if ((target.GetComponent <Building>() != null && target.GetComponent <Building>().teamIndex == teamIndex) ||
                        (target.GetComponent <Ship>() != null && target.GetComponent <Ship>().teamIndex == teamIndex))
                    {
                        selectedUnit = target;
                    }
                }
            }
        }

        if (selectedUnit != null)
        {
            activAttackRangeSphire.transform.position   = selectedUnit.transform.position;
            activAttackRangeSphire.transform.localScale = new Vector3(1, 1, 1);
            activAttackRangeSphire.GetComponent <AutoRotate>().enabled = true;

            if (selectedUnit.GetComponent <Aeroport>() != null)
            {
                activAttackRangeSphire.transform.localScale = new Vector3(
                    selectedUnit.GetComponent <Aeroport>().Range,
                    selectedUnit.GetComponent <Aeroport>().Range *rangeScale,
                    selectedUnit.GetComponent <Aeroport>().Range) * 2;
            }
            if (selectedUnit.GetComponent <Ship>() != null)
            {
                activAttackRangeSphire.transform.localScale = new Vector3(
                    selectedUnit.GetComponent <Ship>().Range,
                    selectedUnit.GetComponent <Ship>().Range *rangeScale,
                    selectedUnit.GetComponent <Ship>().Range) * 2;
            }
            if (selectedUnit.GetComponent <NukeSetap>() != null)
            {
                activAttackRangeSphire.transform.localScale = new Vector3(
                    selectedUnit.GetComponent <NukeSetap>().Range,
                    selectedUnit.GetComponent <NukeSetap>().Range *rangeScale,
                    selectedUnit.GetComponent <NukeSetap>().Range) * 2;
            }
        }
        else
        {
            activAttackRangeSphire.GetComponent <AutoRotate>().enabled = false;
            activAttackRangeSphire.transform.localScale = new Vector3(1, 1, 1);
            activAttackRangeSphire.transform.position   = Vector3.zero;
        }

        //if (!Menu.GetComponent<Menu>().activ)
        //{
        //    if (Input.GetMouseButtonDown(0))
        //    {
        //        RaycastHit hit;
        //        Ray ray = cam.ScreenPointToRay(Input.mousePosition);
        //        if (Physics.Raycast(ray, out hit))
        //        {
        //            GameObject target = hit.transform.gameObject;
        //            if (target.GetComponentInParent<Teams>() != null) {
        //                selectedUnit = null;
        //            }
        //        }
        //    }
        //}
    }