예제 #1
0
        private void LoadGrid()
        {
            string[] hexDescriptions = System.IO.File.ReadAllLines(MEConfig.mapLocation + MEConfig.mapName + MEConfig.mapFileType);

            foreach (string description in hexDescriptions)
            {
                //Parse file input
                string desc;
                string q = description.Substring(0, description.IndexOf(','));
                desc = description.Substring(description.IndexOf(',') + 1, description.Length - description.IndexOf(',') - 1);
                string r = desc.Substring(0, desc.IndexOf(','));
                desc = desc.Substring(desc.IndexOf(',') + 1, desc.Length - desc.IndexOf(',') - 1);
                string t = desc;

                int qVal;
                int rVal;
                if (int.TryParse(q, out qVal) && int.TryParse(r, out rVal))
                {
                    try {
                        Deft.Terrain terrain = (Deft.Terrain)Enum.Parse(typeof(Deft.Terrain), t);

                        //Instantiate in-game hexes
                        Vector2    hexCoords   = new Vector2(qVal, rVal);
                        Vector2    worldCoords = HexVectorUtil.worldPositionOfHexCoord(hexCoords);
                        GameObject hex         = (GameObject)Instantiate(meHex, new Vector3(worldCoords.x, worldCoords.y, 1), Quaternion.identity);
                        hex.transform.SetParent(transform);

                        HexGrid.Add(hexCoords, new MEHexEntry(hex, hexCoords, terrain));
                    } catch { }
                }
            }
        }
예제 #2
0
        private void InstantiateScreenScroll()
        {
            mainCamera   = GameObject.Find("Main Camera");
            screenWidth  = Screen.width;
            screenHeight = Screen.height;

            cameraXLeftBound   = 0;
            cameraXRightBound  = 0;
            cameraYBottomBound = 0;
            cameraYTopBound    = 0;

            foreach (MEHexEntry hex in meController.HexGrid.Values)
            {
                Vector2 hexCenter = HexVectorUtil.worldPositionOfHexCoord(hex.BoardPos);
                if (hexCenter.x < cameraXLeftBound)
                {
                    cameraXLeftBound = hexCenter.x;
                }
                if (hexCenter.x > cameraXRightBound)
                {
                    cameraXRightBound = hexCenter.x;
                }
                if (hexCenter.y < cameraYBottomBound)
                {
                    cameraYBottomBound = hexCenter.y;
                }
                if (hexCenter.y > cameraYTopBound)
                {
                    cameraYTopBound = hexCenter.y;
                }
            }

            Vector2 bottomLeft = mainCamera.GetComponent <Camera>().ViewportToWorldPoint(new Vector3(0, 0));
            Vector2 topRight   = mainCamera.GetComponent <Camera>().ViewportToWorldPoint(new Vector3(1, 1));

            cameraXLeftBound   -= bottomLeft.x;
            cameraXRightBound  -= topRight.x;
            cameraYBottomBound -= bottomLeft.y;
            cameraYTopBound    -= topRight.y;
            cameraXLeftBound   -= MEConfig.hexToEdgeBound;
            cameraXRightBound  += MEConfig.hexToEdgeBound;
            cameraYBottomBound -= MEConfig.hexToEdgeBound;
            cameraYTopBound    += MEConfig.hexToEdgeBound;
            if (cameraXLeftBound > 0)
            {
                cameraXLeftBound = 0;
            }
            if (cameraXRightBound < 0)
            {
                cameraXRightBound = 0;
            }
            if (cameraYBottomBound > 0)
            {
                cameraYBottomBound = 0;
            }
            if (cameraYTopBound < 0)
            {
                cameraYTopBound = 0;
            }
        }
예제 #3
0
        private void DirectPlayerAttention(HexEntry hex, UIAlertType alertType)
        {
            Vector2 targetPos = HexVectorUtil.worldPositionOfHexCoord(hex.BoardPos);

            alertObject = Instantiate(leftClickAlert, new Vector2(targetPos.x + (alertType == UIAlertType.FlippedX ? -0.14f : 0.14f), targetPos.y - 0.14f), Quaternion.identity);

            if (alertType == UIAlertType.Hover)
            {
                alertObject.transform.GetChild(1).gameObject.SetActive(false);
            }
            if (alertType == UIAlertType.FlippedX)
            {
                alertObject.transform.localScale = new Vector3(-alertObject.transform.localScale.x,
                                                               alertObject.transform.localScale.y, alertObject.transform.localScale.z);
            }
        }
예제 #4
0
        private void LoadGrid()
        {
            string mapName;

            if (Vaults.mapName != null)
            {
                mapName = Vaults.mapName;
            }
            else
            {
                mapName = Config.defaultMapName;
            }

            TextAsset map = (TextAsset)Resources.Load(Config.mapLocation + mapName, typeof(TextAsset));

            string[] hexDescriptions = map.text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (string description in hexDescriptions)
            {
                try {
                    //Parse file input
                    string desc;
                    string q = description.Substring(0, description.IndexOf(','));
                    desc = description.Substring(description.IndexOf(',') + 1, description.Length - description.IndexOf(',') - 1);
                    string r = desc.Substring(0, desc.IndexOf(','));
                    desc = desc.Substring(desc.IndexOf(',') + 1, desc.Length - desc.IndexOf(',') - 1);
                    string t = desc;

                    int qVal;
                    int rVal;
                    qVal = int.Parse(q);
                    rVal = int.Parse(r);
                    Deft.Terrain terrain = (Deft.Terrain)Enum.Parse(typeof(Deft.Terrain), t);

                    //Instantiate in-game hexes
                    Vector2    hexCoords   = new Vector2(qVal, rVal);
                    Vector2    worldCoords = HexVectorUtil.worldPositionOfHexCoord(hexCoords);
                    GameObject hex         = Instantiate(hexPrefab, new Vector3(worldCoords.x, worldCoords.y, 1), Quaternion.identity);
                    hex.transform.SetParent(hexContainer);
                    WSHexManager hexManager = hex.GetComponent <WSHexManager>();
                    hexManager.TerrainSprite = terrain;

                    _hexGrid.Add(hexCoords, hexManager);
                } catch { }
            }
        }
예제 #5
0
        private void CreateGrid()
        {
            for (int i = -MEConfig.gridRectHeight / 2; i <= MEConfig.gridRectHeight / 2; i++)
            {
                for (int j = -(MEConfig.gridRectWidth) / 2 + 1; j <= MEConfig.gridRectWidth / 2 + (Math.Abs(i) % 2 - 1); j++)
                {
                    int q = j - (i + Math.Abs(i) % 2) / 2;
                    int r = i;

                    Vector2    hexCoords   = new Vector2(q, r);
                    Vector2    worldCoords = HexVectorUtil.worldPositionOfHexCoord(hexCoords);
                    GameObject hex         = (GameObject)Instantiate(meHex, new Vector3(worldCoords.x, worldCoords.y, 1), Quaternion.identity);
                    hex.transform.SetParent(transform);

                    HexGrid.Add(hexCoords, new MEHexEntry(hex, hexCoords));
                }
            }
        }
예제 #6
0
 public void UnitCycle(MEHexEntry hex)
 {
     if (hex.Occupant == null)
     {
         hex.Occupant        = Instantiate(unit, HexVectorUtil.worldPositionOfHexCoord(hex.BoardPos), Quaternion.identity).GetComponent <MEUnitManager>();
         hex.Occupant.Player = 1;
         hex.Occupant.myHex  = hex;
     }
     else if (hex.Occupant.Player == 1)
     {
         hex.Occupant.Player = 2;
     }
     else if (hex.Occupant.Player == 2)
     {
         Destroy(hex.Occupant.gameObject);
         hex.Occupant = null;
     }
 }
예제 #7
0
        private void LoadUnitPositions()
        {
            string[] unitDescriptions = System.IO.File.ReadAllLines(MEConfig.mapLocation + MEConfig.mapName + MEConfig.unitMapExtension + MEConfig.mapFileType);

            foreach (string description in unitDescriptions)
            {
                try {
                    //Parse file input
                    string desc;
                    string q = description.Substring(0, description.IndexOf(','));
                    desc = description.Substring(description.IndexOf(',') + 1, description.Length - description.IndexOf(',') - 1);
                    string r = desc.Substring(0, desc.IndexOf(','));
                    desc = desc.Substring(desc.IndexOf(',') + 1, desc.Length - desc.IndexOf(',') - 1);
                    string t = desc;

                    int qVal;
                    int rVal;
                    qVal = int.Parse(q);
                    rVal = int.Parse(r);

                    int player = int.Parse(t);

                    Vector2 hexCoords = new Vector2(qVal, rVal);
                    HexGrid[hexCoords].Occupant        = ((GameObject)Instantiate(unit, HexVectorUtil.worldPositionOfHexCoord(hexCoords), Quaternion.identity)).GetComponent <MEUnitManager>();
                    HexGrid[hexCoords].Occupant.Player = player;
                    HexGrid[hexCoords].Occupant.myHex  = HexGrid[hexCoords];
                } catch { }
            }
        }