Beispiel #1
0
    public void Continue()
    {
        List <Sprite> sp  = new List <Sprite>();
        List <int>    ids = new List <int>();

        for (int i = 0; i < characterSprites.Length; i++)
        {
            if (SaveHandler.GetSave(i) != null)
            {
                sp.Add(characterSprites[i]);
                ids.Add(i);
            }
        }

        SliderHandler.OpenScene(sp, (i) => {
            if (i != -1)
            {
                MapGenerator.saveid = ids[i];
                Sprite[] ff         = new Sprite[1];
                ff[0] = FunfactSprites[Random.Range(0, FunfactSprites.Length)];
                DialogHandler.OpenDialogScene(ff, () => UnityEngine.SceneManagement.SceneManager.LoadScene("GameScene"), 0);
                //UnityEngine.SceneManagement.SceneManager.LoadScene("GameScene");
            }
            else
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene("Menu");
            }
        });
    }
Beispiel #2
0
    public void LoadGame()
    {
        Save save = SaveHandler.GetSave(saveid);

        if (save != null)
        {
            width  = save.width;
            height = save.height;
            float sin60 = Mathf.Sin(60 * Mathf.Deg2Rad);

            float gw     = (save.width + 1.5f) * 2 * sin60;
            float gh     = (save.height + 1) * 0.5f;
            float radius = Mathf.Min(gw, gh) / 2;


            for (int i = 0; i < cells.Count; i++)
            {
                Destroy(cells[i]);
            }
            cells.Clear();
            //Debug.Log(sin60);
            for (int i = 0; i < save.height; i++)
            {
                for (int j = 0; j < save.width; j++)
                {
                    Vector3 pos = Vector3.zero;
                    pos.x += (j - save.width / 2f) * 2 * sin60;
                    if (i % 2 == 1)
                    {
                        pos.x += sin60;
                    }
                    pos.y = (i - save.height / 2f) * .5f + 0.4f;

                    if (pos.magnitude <= radius)
                    {
                        if (save.ids.IndexOf(i * height + j) != -1)
                        {
                            //  Debug.Log(pos);
                            GameObject c = GameObject.Instantiate(cell, transform);
                            c.transform.localPosition = pos;

                            c.GetComponent <Cell>().id = save.ids[save.ids.IndexOf(i * height + j)];
                            // Debug.Log("ID" + save.ids[save.ids.IndexOf(i * height + j)]);
                            c.GetComponent <Cell>().CellType = save.cts[save.ids.IndexOf(i * height + j)];
                            c.GetComponent <Cell>().HP       = save.hps[save.ids.IndexOf(i * height + j)];
                            cells.Add(c);
                            sums[(int)c.GetComponent <Cell>().CellType]++;
                        }
                    }
                }
            }

            cells.ForEach(x => x.GetComponent <Cell>().findNeighbours());
            cells.ForEach(x => x.GetComponent <Cell>().Spread());

            float size = radius * 2.8f;
            float diff = 2 / size;
            transform.localScale = new Vector3(diff, diff, 1);
        }
    }