Exemplo n.º 1
0
 // Use this for initialization
 public void setup()
 {
     worldScript = GameObject.Find("World").GetComponent<World>();
     terrainScript = GameObject.Find("World").GetComponent<TerrainScript>();
     chunkSize = terrainScript.chunkSizeDefault;
     y = terrainScript.planetSize;
 }
Exemplo n.º 2
0
    public void moveTo(Vector2 spot)
    {
        // rxl244: prevent unit from moving twice
        if(alreadyMoved){
            return;
        }else{
            alreadyMoved = true;
        }
        terrain = ground.grid[(int)location.y, (int)location.x].GetComponent<TerrainScript>();
        terrain.SendMessage("switchOccupied");
        ground.grid[(int)location.y, (int)location.x].renderer.material.color = Color.white;
        terrain = ground.grid[(int)spot.y, (int)spot.x].GetComponent<TerrainScript>();
        terrain.SendMessage("switchOccupied");
        Vector3 destination = ground.grid[(int)spot.y, (int)spot.x].transform.localPosition;
        destination.y += 5;
        location = spot;
        gameObject.transform.localPosition = destination;

        // rxl244: so the player can win (AI does this in the AI Master script
        if(unitType == "radioChild" && team == 1){
            foreach(Vector2 goalLocation in ground.goalLocations){
                if(location.x == goalLocation.x && location.y == goalLocation.y){
                    ground.grid[(int)goalLocation.y,(int)goalLocation.x].GetComponent<TerrainScript>().SendMessage("setTaken",1);
                }
            }
        }
    }
Exemplo n.º 3
0
 void kill()
 {
     Object.Destroy(gameObject);
     ground.grid[(int)location.y, (int)location.x].renderer.material.color = Color.white;
     terrain = ground.grid[(int)location.y, (int)location.x].GetComponent<TerrainScript>();
     terrain.occupied = false;
     hp = 100;
 }
Exemplo n.º 4
0
 // Use this for initialization
 void Start () {
     movement = 2;
     x = 1;
     y = 1;
     name = "Derp";
     GameObject map = GameObject.Find("Map");
     terrain = map.GetComponent<TerrainScript>();
     entities = map.GetComponent<EntityMapScript>();
     entities.addObject(gameObject, x, y);
 }
Exemplo n.º 5
0
    //private string state;

	// Use this for initialization
	void Start () {
        //x 0 at origin, more positive to the right
        x = 0;
        //y 0 at origin, more positive down
        y = 0;
        horizontalDown = false;
        verticalDown = false;
        GameObject map = GameObject.Find("Map");
        terrain = map.GetComponent<TerrainScript>();
        entities = map.GetComponent<EntityMapScript>();
        //state = "default";
	}
Exemplo n.º 6
0
    void OnMouseDown()
    {
        storeColor = gameObject.renderer.material.color;
            gameObject.renderer.material.color = Color.white;
        // rxl244: added if statement to prevent this unit from looking like it can move when it may not be able to
        if(!alreadyMoved){
            terrain = ground.grid[(int)location.y, (int)location.x].GetComponent<TerrainScript>();
            terrain.SendMessage("UnitSelected", gameObject);
            interaction.SendMessage("NewUnitSelected", gameObject);
        }

        // rxl244: update interface when unit is clicked on
        gameMaster.SendMessage("updateUnitInfo",new float[]{this.hp,this.atkPower,this.moveSpeed,this.team});
        gameMaster.SendMessage("updateName",this.unitType);
    }
Exemplo n.º 7
0
 public static void RemoveTrees(TerrainScript terrain, Vector3 position, bool clearSelectedOnly)
 {
     float radius = brushSize /2;
     terrain.RemoveTrees(position, radius, !clearSelectedOnly ? -1 : selectedTree);
 }
Exemplo n.º 8
0
    public static void PlaceTrees(TerrainScript terrain, Vector3 position, Vector3 normal, int selectedTree)
    {
        if (terrain.treePrototypes.Count != 0)
        {
            if (true)
            {

                int num = 0;
                MyTreeInstance instance = new MyTreeInstance();
                instance.position = position;
                instance.rotation = GetTreeRotation(normal);
                instance.color = GetTreeColor();
                instance.lightmapColor = Color.white;
                instance.prototypeIndex = selectedTree;
                instance.widthScale = GetTreeWidth();
                instance.heightScale = GetTreeHeight();
                if (((Event.current.type != EventType.MouseDrag) && (brushSize <= 1f)) || TerrainFunctions.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, spacing))
               	{
                 	terrain.AddTreeInstance(instance);
                    num++;
                }

                Vector3 prototypeExtent = Vector3.one;
                prototypeExtent.y = 0f;
                float num2 = brushSize / ((prototypeExtent.magnitude * spacing) * 0.5f);
                int num3 =(int) ((num2 * num2) * 0.5f);
                num3 = Mathf.Clamp(num3, 0, 100);
                for (int i = 1; (i < num3) && (num < num3); i++)
                {
                    Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle;
                    insideUnitCircle.x *= (brushSize*100) / terrain.getSizeOfMesh().x;
                    insideUnitCircle.y *= (brushSize*100) / terrain.getSizeOfMesh().y;

                    Vector3 off = new Vector3(insideUnitCircle.x, 0, insideUnitCircle.y);
                    Vector3 pos = Vector3.Cross(normal, off);
                    Vector3 position2 = position + pos;
                    Vector3 nom = position2 - (position2 + normal*10);

                    Ray ray = new Ray(position2, nom);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit)) {

                    //if (terrain.isInsideOfBounds(position2)) {
                        if (true) {
                            if (TerrainFunctions.CheckTreeDistance(terrain.terrainData, hit.point, instance.prototypeIndex, spacing))
                            {
                                instance = new MyTreeInstance();
                                instance.position = hit.point;
                                instance.rotation = GetTreeRotation(hit.normal);
                                instance.color = GetTreeColor();
                                instance.lightmapColor = Color.white;
                                instance.prototypeIndex = selectedTree;
                                instance.widthScale = GetTreeWidth();
                                instance.heightScale = GetTreeHeight();
                                terrain.AddTreeInstance(instance);
                                num++;
                            }
                        }
                    }

                }

            }
        }
    }
Exemplo n.º 9
0
    void team1Make()
    {
        //		Debug.Log ("Team1");
        Vector2[] start = ground.player1StartLocations;
        Vector3 location = Vector3.zero;
        team1 = new GameObject[teamSize];
        int[] unitTypes = {radioChild, rogue, bomber, brain, brute};

        int loopMax = start.Length;
        if(teamSize < start.Length)
            loopMax = teamSize;
        for(int i = (loopMax - 1); i >= 0 ; i--){
            terrain = ground.grid[(int)start[i].y, (int)start[i].x].GetComponent<TerrainScript>();
            terrain.SendMessage("switchOccupied");
            location = ground.grid[(int)start[i].y, (int)start[i].x].transform.localPosition;
            location.y += 5;
            UnitScript u;
            if(unitTypes[0] > 0){
                team1[i] = Instantiate(RadioChild) as GameObject;
                team1[i].transform.localPosition = location;
                u = team1[i].AddComponent("UnitScript") as UnitScript;
                setUnit(team1[i], "radioChild");
                unitTypes[0]--;
            }else if(unitTypes[1] > 0){
                team1[i] = Instantiate(Rogue) as GameObject;
                team1[i].transform.localPosition = location;
                u = team1[i].AddComponent("UnitScript") as UnitScript;
                setUnit(team1[i], "rogue");
                unitTypes[1]--;
            }else if(unitTypes[2] > 0){
                team1[i] = Instantiate(Bomber) as GameObject;
                team1[i].transform.localPosition = location;
                u = team1[i].AddComponent("UnitScript") as UnitScript;
                setUnit(team1[i], "bomber");
                unitTypes[2]--;
            }else if(unitTypes[3] > 0){
                team1[i] = Instantiate(Brain) as GameObject;
                team1[i].transform.localPosition = location;
                u = team1[i].AddComponent("UnitScript") as UnitScript;
                setUnit(team1[i], "brain");
                unitTypes[3]--;
            }else {
                team1[i] = Instantiate(Brute) as GameObject;
                team1[i].transform.localPosition = location;
                u = team1[i].AddComponent("UnitScript") as UnitScript;
                setUnit(team1[i], "brute");
            }
            u.location = start[i];
            setTeam (team1[i], 1);

        //			team1[i].renderer.material.color = Color.blue;
        }
        //		Debug.Log("Team1Complete");
    }
Exemplo n.º 10
0
    //goes through and adds hills, rubbles and forests in random spots based off of amount given to make
    void addFeatures()
    {
        int xRand, zRand;
        int hillsLeft, rubblesLeft, forestsLeft;

        hillsLeft = hills;

        //picks a random spot and adds hilss until they are all gone
        while(hillsLeft > 0)
        {
            xRand = Random.Range(0, xLength - 1);
            zRand = Random.Range(0, zLength - 1);

            terrainScript = grid[zRand,xRand].gameObject.GetComponent("TerrainScript") as TerrainScript;
            if(terrainScript.terrainType != "Goal" && terrainScript.terrainType != "Start" && terrainScript.terrainType != "Hill")
            {
                hillsLeft--;
                setTerrainBlock(xRand, zRand, "Hill", false);
            }
        }

        //adds rubble until they are all made
        rubblesLeft = rubbles;
        GameObject rubblesClone;
        while(rubblesLeft > 0)
        {
            xRand = Random.Range(0, xLength - 1);
            zRand = Random.Range(0, zLength - 1);

            terrainScript = grid[zRand,xRand].gameObject.GetComponent("TerrainScript") as TerrainScript;
            if(terrainScript.terrainType != "Goal" && terrainScript.terrainType != "Start" && terrainScript.terrainType != "Hill"  && terrainScript.terrainType != "Rubble")
            {
                rubblesLeft--;
                setTerrainBlock(xRand, zRand, "Rubble", false);
            }
        }

        //adds forests until they are all made
        forestsLeft = forests;
        while(forestsLeft > 0)
        {
            xRand = Random.Range(0, xLength - 1);
            zRand = Random.Range(0, zLength - 1);

            terrainScript = grid[zRand,xRand].gameObject.GetComponent("TerrainScript") as TerrainScript;
            if(terrainScript.terrainType != "Goal" && terrainScript.terrainType != "Start" && terrainScript.terrainType != "Hill" && terrainScript.terrainType != "Rubble" && terrainScript.terrainType != "Forest")
            {
                setTerrainBlock(xRand, zRand, "Forest", false);
                forestsLeft--;
            }
        }
    }
Exemplo n.º 11
0
    private void UpdatePreviewBrush()
    {
        TerrainScript targetScript = ((TerrainScript)target);

        if ((targetScript.treePrototypes.Count > 0) && (previewMesh != null))
        {
            previewMesh.UpdatePreviewMesh(targetScript.terrainData.treeInstances,
                                          targetScript.treePrototypes[0].prefab.renderer.bounds.size.y);
        }


        Vector3   normal = Vector3.zero;
        Vector3   hitPos = Vector3.zero;
        Vector2   vector;
        Vector3   vector2          = Vector3.zero;
        float     m_Size           = 16 * brushSize;
        Projector previewProjector = currentTextureBrush.GetPreviewProjector();
        float     num = 1f;

        float num2 = mixMap.width / mixMap.height;

        Vector2 size = targetScript.getSizeOfMesh(); // terrain.getSizeOfMesh();

        int terrainSizeX = (int)size.x;
        int terrainSizeZ = (int)size.y;

        Transform PPtransform = previewProjector.transform;
        bool      flag        = true;

        Vector2 newMousePostion = Event.current.mousePosition;

        newMousePostion.y = Screen.height - (Event.current.mousePosition.y + 35);
        Ray        ray = Camera.current.ScreenPointToRay(newMousePostion);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 1000f))
        {
            vector2 = hit.point;
            hitPos  = hit.point;
            normal  = hit.normal;
            float num4           = ((m_Size % 2) != 0) ? 0.5f : 0f;
            int   alphamapWidth  = 64;
            int   alphamapHeight = 64;
            vector.x  = (Mathf.Floor(hit.textureCoord.x * alphamapWidth) + num4) / ((float)alphamapWidth);
            vector.y  = (Mathf.Floor(hit.textureCoord.y * alphamapHeight) + num4) / ((float)alphamapHeight);
            vector2.x = vector.x * -terrainSizeX + (terrainSizeX / 2);
            vector2.z = vector.y * -terrainSizeZ + (terrainSizeZ / 2);
            vector2  += Selection.activeGameObject.transform.position;
            num       = ((m_Size * 0.5f) / ((float)alphamapWidth)) * terrainSizeX;
            num2      = ((float)alphamapWidth) / ((float)alphamapHeight);
        }
        else
        {
            flag = false;
        }

        previewProjector.enabled = flag;
        if (flag)
        {
            PPtransform.position = hitPos + (normal * 100);
            PPtransform.rotation = Quaternion.LookRotation(normal);
        }
        previewProjector.orthographicSize = num / num2;
        previewProjector.aspectRatio      = num2;
    }
Exemplo n.º 12
0
 public void clicked(TerrainScript script)
 {
     _clicked = script;
     player.terrainClick();
 }
Exemplo n.º 13
0
	void Start()
    {
        ts = FindObjectOfType<TerrainScript>();
        previous = transform.position;
	}
Exemplo n.º 14
0
    private void Initialize(TerrainScript parent, Vector3 pos, string n)
    {
        willFall                = true;
        pos.x                  += 10;
        gm                      = FindObjectOfType <RestrictionScript> ();
        obs                     = GameObject.FindGameObjectWithTag("Respawn");
        terrain                 = parent.terrain;
        transform.parent        = parent.transform;
        transform.localScale    = Vector3.one;
        transform.localPosition = pos;
        posName                 = n;

        int x = 0;

        TerrainScript[] ps = FindObjectsOfType <TerrainScript> ();
        foreach (TerrainScript p in ps)
        {
            if (transform.position == p.transform.position)
            {
                x++;
                if (x == 2)
                {
                    Destroy(gameObject);                           //Destroy duplicates
                }
            }
        }



        if (gm.rNum >= 4)
        {
            float distance = Random.Range(0.05f, 0.165f);
            if (transform.position.x > 0)
            {
                pos.x += distance;
            }
            else
            {
                pos.x -= distance;
            }
            transform.localPosition = pos;             //Platform distance
        }

        if (gm.rNum >= 3)
        {
            float xpos = Random.Range(-0.425f, 0.425f);
            float ypos = Random.Range(0.3f, 1.5f);
            pos = new Vector3(xpos, ypos, 0);
            GameObject ob = Instantiate(obs, Vector3.zero, Quaternion.identity, gameObject.transform);              //Spawn obstacle
            ob.transform.localPosition = pos;
        }

        if (x < 2)
        {
            float r1 = Random.Range(0, 10);
            float r2 = Random.Range(0, 10);
            float r3 = Random.Range(0, 10);
            if (r1 <= 4)
            {
                gm.SpawnStuff(1, transform.position);
            }
            if (r2 <= 6)
            {
                gm.SpawnStuff(2, transform.position);
            }
            if (r3 <= 4)
            {
                gm.SpawnStuff(3, transform.position);                    //Spawn stuff
            }
        }
    }
Exemplo n.º 15
0
    public static void PlaceTrees(TerrainScript terrain, Vector3 position, Vector3 normal, int selectedTree)
    {
        if (terrain.treePrototypes.Count != 0)
        {
            if (true)
            {
                int            num      = 0;
                MyTreeInstance instance = new MyTreeInstance();
                instance.position       = position;
                instance.rotation       = GetTreeRotation(normal);
                instance.color          = GetTreeColor();
                instance.lightmapColor  = Color.white;
                instance.prototypeIndex = selectedTree;
                instance.widthScale     = GetTreeWidth();
                instance.heightScale    = GetTreeHeight();
                if (((Event.current.type != EventType.MouseDrag) && (brushSize <= 1f)) || TerrainFunctions.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, spacing))
                {
                    terrain.AddTreeInstance(instance);
                    num++;
                }

                Vector3 prototypeExtent = Vector3.one;
                prototypeExtent.y = 0f;
                float num2 = brushSize / ((prototypeExtent.magnitude * spacing) * 0.5f);
                int   num3 = (int)((num2 * num2) * 0.5f);
                num3 = Mathf.Clamp(num3, 0, 100);
                for (int i = 1; (i < num3) && (num < num3); i++)
                {
                    Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle;
                    insideUnitCircle.x *= (brushSize * 100) / terrain.getSizeOfMesh().x;
                    insideUnitCircle.y *= (brushSize * 100) / terrain.getSizeOfMesh().y;

                    Vector3 off       = new Vector3(insideUnitCircle.x, 0, insideUnitCircle.y);
                    Vector3 pos       = Vector3.Cross(normal, off);
                    Vector3 position2 = position + pos;
                    Vector3 nom       = position2 - (position2 + normal * 10);

                    Ray        ray = new Ray(position2, nom);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        //if (terrain.isInsideOfBounds(position2)) {
                        if (true)
                        {
                            if (TerrainFunctions.CheckTreeDistance(terrain.terrainData, hit.point, instance.prototypeIndex, spacing))
                            {
                                instance                = new MyTreeInstance();
                                instance.position       = hit.point;
                                instance.rotation       = GetTreeRotation(hit.normal);
                                instance.color          = GetTreeColor();
                                instance.lightmapColor  = Color.white;
                                instance.prototypeIndex = selectedTree;
                                instance.widthScale     = GetTreeWidth();
                                instance.heightScale    = GetTreeHeight();
                                terrain.AddTreeInstance(instance);
                                num++;
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 16
0
    public static void RemoveTrees(TerrainScript terrain, Vector3 position, bool clearSelectedOnly)
    {
        float radius = brushSize / 2;

        terrain.RemoveTrees(position, radius, !clearSelectedOnly ? -1 : selectedTree);
    }