示例#1
0
    void FindTree()
    {
        currenTree = null;
        Grid grid    = FindObjectOfType <Grid>();
        Node HutNode = grid.NodeFromWorldPoint(transform.position);

        foreach (GameObject tree in GameObject.FindGameObjectsWithTag("Tree"))
        {
            Node treeNode = grid.NodeFromWorldPoint(tree.transform.position);

            if (treeNode.gridX <= HutNode.gridX + Radius &&
                treeNode.gridX >= HutNode.gridX - Radius &&
                treeNode.gridY <= HutNode.gridY + Radius &&
                treeNode.gridY >= HutNode.gridY - Radius)

            {
                TreeScript   ts  = tree.GetComponent <TreeScript>();
                ObjectOnGrid oog = tree.GetComponent <ObjectOnGrid>();
                if (ts.available && oog.placed)
                {
                    currenTree   = tree;
                    ts.available = false;
                    return;
                }
            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (oog.placed)
        {
            if (currTime >= growthTime)
            {
                Debug.Log("YoungTree1 creates YoungTree2");
                GameObject youngTree2 = Instantiate(YoungTree2);
                youngTree2.transform.position = gameObject.transform.position;
                youngTree2.transform.rotation = gameObject.transform.rotation;
                ObjectOnGrid oog2 = youngTree2.GetComponent <ObjectOnGrid>();
                oog2.placed = true;
                oog2.SetNodes(oog.Nodes);

                //for (int i = 0; i < oog2.Nodes.GetLength(0); i++)
                //{
                //    for (int j = 0; j < oog2.Nodes.GetLength(1); j++)
                //    {
                //        //Debug.Log("i: " + i + " j: " + j + " | grid x:" + oog2.Nodes[i , j].gridX + " grid y: " + oog2.Nodes[i , j].gridY);
                //    }
                //}

                Destroy(gameObject);
            }
            else
            {
                currTime += Time.deltaTime;
            }
        }
    }
示例#3
0
    void FindRock()
    {
        currentRock = null;
        Grid grid    = FindObjectOfType <Grid>();
        Node HutNode = grid.NodeFromWorldPoint(transform.position);

        foreach (GameObject rock in GameObject.FindGameObjectsWithTag("Rock"))
        {
            Node rockNode = grid.NodeFromWorldPoint(rock.transform.position);

            if (rockNode.gridX <= HutNode.gridX + Radius &&
                rockNode.gridX >= HutNode.gridX - Radius &&
                rockNode.gridY <= HutNode.gridY + Radius &&
                rockNode.gridY >= HutNode.gridY - Radius)

            {
                RockScript   rs  = rock.GetComponent <RockScript>();
                ObjectOnGrid oog = rock.GetComponent <ObjectOnGrid>();
                if (rs.available && oog.placed)
                {
                    currentRock  = rock;
                    rs.available = false;
                    return;
                }
            }
        }
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        if (oog.placed)
        {
            if (currTime >= growthTime)
            {
                Debug.Log("YoungTree2 creates Tree");
                GameObject tree = Instantiate(Tree);
                tree.transform.position = gameObject.transform.position;
                tree.transform.rotation = gameObject.transform.rotation;
                ObjectOnGrid oogTree = tree.GetComponent <ObjectOnGrid>();
                oogTree.placed = true;

                for (int i = 0; i < oog.Nodes.GetLength(0); i++)
                {
                    for (int j = 0; j < oog.Nodes.GetLength(1); j++)
                    {
                        Debug.Log("i: " + i + " j: " + j + " | grid x:" + oog.Nodes[i, j].gridX + " grid y: " + oog.Nodes[i, j].gridY);
                    }
                }

                oogTree.SetNodes(oog.Nodes);
                Destroy(gameObject);
            }
            else
            {
                currTime += Time.deltaTime;
            }
        }
    }
示例#5
0
 // Use this for initialization
 void Start()
 {
     added          = false;
     statisticAdded = false;
     popc           = FindObjectOfType <PopulationManager>();
     oog            = gameObject.GetComponent <ObjectOnGrid>();
     rm             = gameObject.GetComponent <ResourceManager>();
 }
示例#6
0
 // Use this for initialization
 void Start()
 {
     oog              = GetComponent <ObjectOnGrid>();
     rm               = FindObjectOfType <ResourceManager>();
     PopManager       = FindObjectOfType <PopulationManager>();
     HappinessManager = FindObjectOfType <HappinessManager>();
     spawnTime        = baseSpawnTime;
     message          = "Fortress Upgrade\n" + upcostwood + " Wood " + upcoststone + " Stone";
 }
示例#7
0
 private void Start()
 {
     grid           = FindObjectOfType <Grid>();
     Fields         = new List <FieldScript>();
     oog            = gameObject.GetComponent <ObjectOnGrid>();
     sm             = FindObjectOfType <SoundManager>();
     statisticAdded = false;
     audio          = GetComponent <AudioSource>();
     audiotimer     = 0;
 }
示例#8
0
    public void TaskOnClick()
    {
        //buildingPlacement.currentBuilding = null;

        ObjectOnGrid ong = building.GetComponent <ObjectOnGrid>();

        if (rm.isEnough(ong.costWood, ong.costStone, 0))
        {
            buildingPlacement.SetItem(building);
        }
    }
示例#9
0
    public void TreeChoped()
    {
        ObjectOnGrid oog = currenTree.GetComponent <ObjectOnGrid>();

        oog.grid.SetWalkable(oog.gridPosX, oog.gridPosY);

        currenTree         = null;
        currentChopingTime = 0f;
        state = States.CarryingGoods;

        unit.MoveTo(wcc.InitialPosition.transform.position);
    }
示例#10
0
    public void RockCutted()
    {
        ObjectOnGrid oog = currentRock.GetComponent <ObjectOnGrid>();

        oog.grid.SetWalkable(oog.gridPosX, oog.gridPosY);

        currentRock       = null;
        currentMiningTime = 0f;
        state             = States.CarryingGoods;

        unit.MoveTo(mhc.InitialPosition.transform.position);
    }
示例#11
0
    private void OnGUI()
    {
        for (int i = 0; i < buildings.Length; i++)
        {
            if (GUI.Button(new Rect(20, 100 + i * 40, 100, 30), buildings[i].name))
            {
                ObjectOnGrid ong = buildings[i].GetComponent <ObjectOnGrid>();

                if (rm.isEnough(ong.costWood, ong.costStone, 0))
                {
                    buildingPlacement.SetItem(buildings[i]);
                }
            }
        }
    }
示例#12
0
    // Update is called once per frame
    void Update()
    {
        if (foodLeft == 0)
        {
            GameObject bushWithoutBerries = Instantiate(BushWithoutBerries);
            bushWithoutBerries.transform.position = gameObject.transform.position;
            bushWithoutBerries.transform.rotation = gameObject.transform.rotation;

            ObjectOnGrid oogNoBerryBush = bushWithoutBerries.GetComponent <ObjectOnGrid>();
            oogNoBerryBush.placed = true;
            oogNoBerryBush.SetNodes(GetComponent <ObjectOnGrid>().Nodes);

            Destroy(gameObject);
        }
    }
示例#13
0
 // Update is called once per frame
 void Update()
 {
     if (currTime >= growthTime)
     {
         GameObject berryBush = Instantiate(BerryBush);
         berryBush.transform.position = gameObject.transform.position;
         berryBush.transform.rotation = gameObject.transform.rotation;
         ObjectOnGrid oogBerryBush = berryBush.GetComponent <ObjectOnGrid>();
         oogBerryBush.placed = true;
         oogBerryBush.SetNodes(GetComponent <ObjectOnGrid>().Nodes);
         Destroy(gameObject);
     }
     else
     {
         currTime += Time.deltaTime;
     }
 }
示例#14
0
    public void PlantTree()
    {
        GameObject youngTree = Instantiate(fhs.YoungTree);

        youngTree.transform.position = newTreeLocation.transform.position;
        ObjectOnGrid oogNewTree = youngTree.GetComponent <ObjectOnGrid>();

        oogNewTree.placed = true;
        oogNewTree.SetNodes(new Node[, ] {
            { targetNode }
        });

        newTreeLocation = null;
        targetNode      = null;
        state           = States.CommingBack;

        unit.MoveTo(fhs.InitialPosition.transform.position);
    }
示例#15
0
    // Use this for initialization
    void Start()
    {
        buildingPlacement = GetComponent <BuildingPlacement>();
        rm       = FindObjectOfType <ResourceManager>();
        message += "\n";
        ObjectOnGrid ong = building.GetComponent <ObjectOnGrid>();

        if (ong.costWood != 0)
        {
            message += ong.costWood + " wood ";
        }
        if (ong.costStone != 0)
        {
            message += ong.costStone + " stone ";
        }
        if (ong.costStone == 0 && ong.costWood == 0)
        {
            message += "FREE";
        }
    }
示例#16
0
    void FindNearestTree()
    {
        currenTree = null;
        float dist    = float.MaxValue;
        Grid  grid    = FindObjectOfType <Grid>();
        Node  HutNode = grid.NodeFromWorldPoint(transform.position);

        foreach (GameObject tree in GameObject.FindGameObjectsWithTag("Tree"))
        {
            Node treeNode = grid.NodeFromWorldPoint(tree.transform.position);

            if (treeNode.gridX <= HutNode.gridX + Radius &&
                treeNode.gridX >= HutNode.gridX - Radius &&
                treeNode.gridY <= HutNode.gridY + Radius &&
                treeNode.gridY >= HutNode.gridY - Radius)

            {
                TreeScript   ts  = tree.GetComponent <TreeScript>();
                ObjectOnGrid oog = tree.GetComponent <ObjectOnGrid>();
                if (ts.available && oog.placed)
                {
                    float currTreeDist = Mathf.Sqrt(Mathf.Pow(treeNode.gridX - HutNode.gridX, 2) +
                                                    Mathf.Pow(treeNode.gridY - HutNode.gridY, 2));
                    if (currTreeDist < dist)
                    {
                        currenTree = tree;
                        dist       = currTreeDist;
                    }
                    //ts.available = false;
                    //return;
                }
            }
        }

        if (currenTree != null)
        {
            TreeScript ts = currenTree.GetComponent <TreeScript>();
            ts.available = false;
        }
    }
示例#17
0
    void FindNearestRock()
    {
        currentRock = null;
        float dist    = float.MaxValue;
        Grid  grid    = FindObjectOfType <Grid>();
        Node  HutNode = grid.NodeFromWorldPoint(transform.position);

        foreach (GameObject rock in GameObject.FindGameObjectsWithTag("Rock"))
        {
            Node rockNode = grid.NodeFromWorldPoint(rock.transform.position);

            if (rockNode.gridX <= HutNode.gridX + Radius &&
                rockNode.gridX >= HutNode.gridX - Radius &&
                rockNode.gridY <= HutNode.gridY + Radius &&
                rockNode.gridY >= HutNode.gridY - Radius)

            {
                RockScript   rs  = rock.GetComponent <RockScript>();
                ObjectOnGrid oog = rock.GetComponent <ObjectOnGrid>();
                if (rs.available && oog.placed)
                {
                    float currRockDist = Mathf.Sqrt(Mathf.Pow(rockNode.gridX - HutNode.gridX, 2) +
                                                    Mathf.Pow(rockNode.gridY - HutNode.gridY, 2));
                    if (currRockDist < dist)
                    {
                        currentRock = rock;
                        dist        = currRockDist;
                    }
                }
            }
        }

        if (currentRock != null)
        {
            RockScript rs = currentRock.GetComponent <RockScript>();
            rs.available = false;
        }
    }
示例#18
0
 // Use this for initialization
 void Start()
 {
     rm             = FindObjectOfType <ResourceManager>();
     oog            = gameObject.GetComponent <ObjectOnGrid>();
     statisticAdded = false;
 }
示例#19
0
    // Update is called once per frame
    void Update()
    {
        if (currentBuilding != null)
        {
            ObjectOnGrid data = currentBuilding.GetComponent <ObjectOnGrid>();

            RaycastHit hit = new RaycastHit();
            Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
            Physics.Raycast(ray, out hit, Mathf.Infinity);

            Vector3 pos = new Vector3(hit.point.x, 0, hit.point.z);

            Node            rayPointNode    = grid.NodeFromWorldPoint(hit.point);
            Vector3         rayPointNodePos = rayPointNode.worldPosition;
            ObjectOnGrid    oog             = currentBuilding.GetComponent <ObjectOnGrid>();
            NavMeshObstacle navMeshObstacle = currentBuilding.GetComponent <NavMeshObstacle>();

            currentBuilding.transform.position = rayPointNodePos + new Vector3((oog.takesSpaceX + 1) % 2 * grid.nodeDiameter / 2, 0.5f, (oog.takesSpaceY + 1) % 2 * grid.nodeDiameter / 2);

            FortressScript Fortress = FindObjectOfType <FortressScript>();

            if (Fortress == null)
            {
                ShowAvailableToBuild(currentBuilding.transform.position);
            }
            else
            {
                ShowAvailableToBuild(currentBuilding.transform.position, Fortress.transform.position, Fortress.Ranges[Fortress.Level - 1], oog.takesSpaceX, oog.takesSpaceY);
            }

            if (Input.GetMouseButtonDown(0))
            {
                Node node = grid.NodeFromWorldPoint(currentBuilding.position);

                if (Fortress != null)
                {
                    //Debug.Log("Checking distance...");
                    if (!grid.CheckDistance(rayPointNode.gridX, rayPointNode.gridY, data.takesSpaceX, data.takesSpaceY, Fortress.transform.position, Fortress.Ranges[Fortress.Level - 1]))
                    {
                        return;
                    }

                    //Debug.Log("Distance ok. Checking path...");
                    FortressPos = Fortress.SpawnPosition.position;
                    NavMeshPath path = new NavMeshPath();
                    NavMesh.CalculatePath(FortressPos, currentBuilding.transform.position, NavMesh.AllAreas, path);
                    if (path.status != NavMeshPathStatus.PathComplete)
                    {
                        return;
                    }
                    //Debug.Log("Path ok.");
                }

                if (grid.UpdateGrid(rayPointNode.gridX, rayPointNode.gridY, data.takesSpaceX, data.takesSpaceY))
                {
                    oog.SetNodes(grid.GetNodes(rayPointNode.gridX, rayPointNode.gridY, data.takesSpaceX, data.takesSpaceY));

                    data.gridPosX = node.gridX;
                    data.gridPosY = node.gridY;

                    rm.DecreaseResources(ResourceManager.Resources.Wood, oog.costWood);
                    rm.DecreaseResources(ResourceManager.Resources.Stone, oog.costStone);
                    oog.placed = true;
                    navMeshObstacle.enabled = true;
                    scoreManager.AddScore(oog.scoreBonus);

                    currentBuilding = null;
                    resetRest(0, 0);
                }

                if (oog.objectName == "Road")
                {
                    SetItem(lastBuilding);
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                Destroy(currentBuilding.gameObject);
                resetRest(0, 0);
            }

            if (Input.GetKeyDown("r"))
            {
                currentBuilding.Rotate(Vector3.forward, 90);
            }
        }
    }
示例#20
0
 private void Start()
 {
     oog = this.GetComponent <ObjectOnGrid>();
 }
示例#21
0
 private void Start()
 {
     oog            = gameObject.GetComponent <ObjectOnGrid>();
     statisticAdded = false;
 }