示例#1
0
 public void getDirection()
 {
     townCentre = MetaScript.getTownCenter();
     if (townCentre != null)
     {
         travelDirection = (townCentre.transform.position - transform.position).normalized;
     }
 }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (tc == null)
        {
            tc = MetaScript.getTownCenter();
        }

        Vector3 targetPosLocal = tc.transform.InverseTransformPoint(player.transform.position);
        var     targetAngle    = -Mathf.Atan2(targetPosLocal.x, targetPosLocal.z) * Mathf.Rad2Deg + 180;

        needle.transform.eulerAngles = new Vector3(needle.transform.eulerAngles.x, 0, targetAngle);
    }
示例#3
0
    /// <summary>
    /// Converts NPC to be an owned NPC and immediately starts gathering wood
    /// </summary>
    public void TakeSoul()
    {
        MetaScript.GetNPC().addNPC(gameObject);
        gameObject.tag = "OwnedNPC";
        //teleport to town
        transform.position = MetaScript.getTownCenter().transform.position + new Vector3(0.5f, 0, 0);
        transform.SetParent(MetaScript.getMetaObject().transform);


        gameObject.GetComponent <collect>().enabled = true;
        gameObject.GetComponent <collect>().startCollecting(ResourceTypes.WOOD);
        Destroy(this);
        //GetComponent<NavMeshAgent>().enabled = true;
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        if (controls.keyDown(controls.TownPortal))
        {
            bool inBuilding = false;
            if (buildingCheck != null)
            {
                inBuilding = buildingCheck.getPlayerInBuilding();
            }

            if (MetaScript.getRes().hasResource(costType, resourceCost) && !inBuilding)
            {
                MetaScript.getRes().addResource(costType, -resourceCost);
                MetaScript.preTeleport();
                transform.parent.transform.position = MetaScript.getTownCenter().transform.position + new Vector3(0.5f, 0, -0.5f);
                MetaScript.postTeleport();
                MetaScript.Poof(MetaScript.getPlayer().transform.position);
            }
        }
    }
示例#5
0
    // Use this for initialization
    void Start()
    {
        added = new Dictionary <string, bool>();
        tc    = MetaScript.getTownCenter();
        //tg = GameObject.Find("Terrain Generator").GetComponent<terrainGenerator>();
        if (tc != null)
        {
            int tcx = (int)tc.transform.position.x;
            int tcz = (int)tc.transform.position.z;

            for (int i = -1; i < 2; i = i + 2)
            {
                for (int j = -1; j < 2; j = j + 2)
                {
                    if (!added.ContainsKey((i * 2 + tcx) + " " + (j * upgradeLevel + tcz)))
                    {
                        Instantiate(plot, new Vector3(i * 2 + tcx, 0, j * upgradeLevel + tcz), Quaternion.identity);
                        Instantiate(buildingSign, new Vector3(i * 2 + tcx, 0, j * upgradeLevel + tcz), Quaternion.identity);
                        added[(i * 2 + tcx) + " " + (j * upgradeLevel + tcz)] = true;
                    }

                    if (!added.ContainsKey((i * upgradeLevel + tcx) + " " + (j * 2 + tcz)))
                    {
                        Instantiate(plot, new Vector3(i * upgradeLevel + tcx, 0, j * 2 + tcz), Quaternion.identity);
                        Instantiate(buildingSign, new Vector3(i * upgradeLevel + tcx, 0, j * 2 + tcz), Quaternion.identity);
                        added[(i * upgradeLevel) + " " + (j * 2 + tcz)] = true;
                    }
                }
                if (upgradeLevel == 0)
                {
                    Instantiate(plot, new Vector3(2 + tcx, 0, tcz), Quaternion.identity);
                    Instantiate(buildingSign, new Vector3(2 + tcx, 0, tcz), Quaternion.identity);
                    break;
                }
            }
        }
    }
示例#6
0
    public void flight()
    {
        if (prevState == state.UNSET)
        {
            prevState = state.FLEE;
        }
        GameObject safety = collect.findClosestTag("Shelter", gameObject);

        if (safety != null)
        {
            GetComponent <NavMeshAgent>().SetDestination(safety.transform.position);
            curState = state.FLEE;
        }
        else
        {
            // Frozen in terror
            // Debug.Log("NPC:\""+name+"\" couldn't find a nearby shelter and is now frozen in terror");
            // GetComponent<NavMeshAgent>().SetDestination(transform.position);

            // Run to town center
            Debug.Log("NPC:\"" + name + "\" couldn't find a nearby shelter and is running to town center");
            GetComponent <NavMeshAgent>().SetDestination(MetaScript.getTownCenter().transform.position);
        }
    }
示例#7
0
    // Use this for initialization
    public void Awake()
    {
        //GameObject player = GameObject.FindGameObjectWithTag("Player");
        //player.transform.position = new Vector3(xPlayerChunkPos + xPlayerPos, 0, yPlayerChunkPos + yPlayerPos);
        RenderSettings.ambientLight = Color.black;
        loadedChunks = new Dictionary <string, Chunk>();
        terrainMap   = new Dictionary <string, terrain>();
        resourceMap  = new Dictionary <string, resource>();
        int tempx = getxPlayerChunkPos() * Chunk.SIZE + getxPlayerPos();
        int tempy = getyPlayerChunkPos() * Chunk.SIZE + getyPlayerPos();

        waterAmount    = PlayerPrefs.GetFloat("water");
        terrainAmount  = PlayerPrefs.GetFloat("terrain");
        resourceAmount = PlayerPrefs.GetFloat("resource");
        if (!testing)
        {
            setterrainSeed(Random.Range(0, 100));
            setterrainSeed2(Random.Range(0, 100));
            while (getterrainSeed() == getterrainSeed2())
            {
                setterrainSeed(Random.Range(0, 100));
            }
            setresourceSeed(Random.Range(0, 100));
            setresourceSeed2(Random.Range(0, 100));
            while (getresourceSeed() == getresourceSeed2())
            {
                setterrainSeed(Random.Range(0, 100));
            }
            setwaterSeed(Random.Range(0, 100));
        }


        for (int i = (tempx - 3); i < (tempx + 4); i++)
        {
            for (int j = (tempy - 3); j < (tempy + 4); j++)
            {
                string key = i + " " + j;
                if (resourceMap.ContainsKey(key))
                {
                    resourceMap[key] = resource.NONE;
                }
                else
                {
                    resourceMap.Add(key, resource.NONE);
                }
            }
        }
        for (int i = xChunk - chunksLoaded; i < xChunk + chunksLoaded + 1; i++)
        {
            for (int j = yChunk - chunksLoaded; j < yChunk + chunksLoaded + 1; j++)
            {
                generateChunk(i, j);
                //if(i == xChunk+chunksLoaded && j == yChunk + chunksLoaded)
                //{

                //  GameObject.FindGameObjectWithTag("TownCenter").GetComponent<NavMeshBuildFunction>().build();
                //}
            }
        }

        MetaScript.getTownCenter().GetComponentInChildren <NavMeshBuildFunction>().build();
        //}


        Debug.LogWarning("Seed Info, S:" + SEED + " cis:" + chunkIntervalSeed + " w:" + waterSeed + " r1:" + resourceSeed + " r2:" + resourceSeed2 + " t1:" + terrainSeed + " t2:" + terrainSeed2);
    }
示例#8
0
 // Use this for initialization
 void Start()
 {
     tc     = MetaScript.getTownCenter().transform.position;
     player = MetaScript.getPlayer();
 }