Пример #1
0
    // Use this for initialization
    void Start()
    {
        levelGen    = gameManager.GetComponent <scr_GameManager>().levelGen;
        levelScript = levelGen.GetComponent <scr_LevelGenerator>();
        level       = levelScript.level;

        //set camera start position
        //set random x,y
        //bool _temp = false;
        //do
        //{
        //    int _x = (int)Random.Range(0, levelScript.gridX);
        //    int _y = (int)Random.Range(0, levelScript.gridY);

        //    if (level[_x, _y] != 0)
        //    {
        //        x = _x;
        //        y = _y;
        //        _temp = true;
        //    }
        //} while (!_temp);

        //x = (int)Random.Range(0, levelScript.gridX);
        //y = (int)Random.Range(0, levelScript.gridY);
        //transform.position = new Vector3(Mathf.Clamp(x + 64 + 0.5f, 11 + 0.5f + 64, 53 - 0.3f + 64), Mathf.Clamp(y + 64 - 0.5f, 7.5f + 64, 54 + 0.5f + 64), -10);
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        audioSrc = GetComponent <AudioSource>();
        //audioSrc.clip = music;
        //audioSrc.loop = true;
        //audioSrc.Play();

        gameOver = false;

        //create level generator
        levelGen                = Instantiate(levelGenPrefab);
        levelScript             = levelGen.GetComponent <scr_LevelGenerator>(); //levelScript.level;
        levelScript.gameManager = this.gameObject;
        levelScript.cam         = cam;

        level = levelScript.level;

        CreateSaveFile();

        score = 0;

        maxStorage = 5000;
        extraRes   = 0;

        hasAcademy = false;
        hasWonder  = false;

        wood  = 5000;
        stone = 5000;
        gold  = 5000;

        Invoke("PlaceTownhall", 0.1f);

        //load highscore
        highScoreTxt = LoadHighscore();
    }
Пример #3
0
    // Use this for initialization
    void Start()
    {
        buildingType = buildings.none;
        isBuilding   = false;

        spriteRenderer = GetComponent <SpriteRenderer>();

        gameManager = GameObject.Find("GameManager");
        gmScript    = gameManager.GetComponent <scr_GameManager>();

        levelGen    = gameManager.GetComponent <scr_GameManager>().levelGen;
        levelScript = levelGen.GetComponent <scr_LevelGenerator>();
        level       = levelScript.level;


        //set sprite
        int _i;

        switch (tileType)
        {
        case tile.empty:

            _i = 0;
            if ((int)Random.Range(0, 10) == 0)
            {
                _i = (int)Random.Range(1, tileSea.Length);
                spriteRenderer.sprite = tileSea[_i];
            }
            else
            {
                spriteRenderer.sprite = tileSea[0];
            }

            break;

        case tile.floor:

            _i = 0;
            if ((int)Random.Range(0, 10) == 0)
            {
                _i = (int)Random.Range(0, tileDirt.Length);
                spriteRenderer.sprite = tileDirt[_i];
            }
            else
            {
                spriteRenderer.sprite = tileDirt[0];
            }

            break;

        case tile.forest:

            _i = (int)Random.Range(0, tileTree.Length);
            spriteRenderer.sprite = tileTree[_i];

            break;

        case tile.stone:
            spriteRenderer.sprite = tileStone;
            break;

        case tile.gold:
            spriteRenderer.sprite = tileGold;
            break;

        default:
            spriteRenderer.sprite = tileNULL;
            break;
        }

        GameObject go;

        #region SeaEdge
        //check Sea Edge
        if (level[x, y] == 0)
        {
            if (x != levelScript.gridX - 1)
            {
                if (level[x + 1, y] != 0)
                {
                    go = new GameObject("edge_Right");
                    go.AddComponent <SpriteRenderer>().sprite       = tileEdge[0];
                    go.GetComponent <SpriteRenderer>().sortingOrder = 1;
                    go.transform.position = transform.position;
                    go.transform.parent   = transform;
                }
            }

            if (x != 0)
            {
                if (level[x - 1, y] != 0)
                {
                    go = new GameObject("edge_Left");
                    go.AddComponent <SpriteRenderer>().sprite       = tileEdge[1];
                    go.GetComponent <SpriteRenderer>().sortingOrder = 1;
                    go.transform.position = transform.position;
                    go.transform.parent   = transform;
                }
            }

            if (y != levelScript.gridY - 1)
            {
                if (level[x, y + 1] != 0)
                {
                    go = new GameObject("edge_Top");
                    go.AddComponent <SpriteRenderer>().sprite       = tileEdge[2];
                    go.GetComponent <SpriteRenderer>().sortingOrder = 1;
                    go.transform.position = transform.position;
                    go.transform.parent   = transform;
                }
            }

            if (y != 0)
            {
                if (level[x, y - 1] != 0)
                {
                    go = new GameObject("edge_Bottom");
                    go.AddComponent <SpriteRenderer>().sprite       = tileEdge[3];
                    go.GetComponent <SpriteRenderer>().sortingOrder = 1;
                    go.transform.position = transform.position;
                    go.transform.parent   = transform;
                }
            }
        }
        #endregion
    }