Esempio n. 1
0
    public static bool GetTileType(char tileId, out Declarations.TileType tileType, bool canHaveEmpty)
    {
        switch (tileId)
        {
        case '/':
            tileType = Declarations.TileType.Grass;
            break;

        case '#':
            tileType = Declarations.TileType.Path;
            break;

        case '$':
            tileType = Declarations.TileType.Objective;
            break;

        case '*':
            tileType = Declarations.TileType.Spawn;
            break;

        case 'x':
            tileType = Declarations.TileType.Environment;
            break;

        default:
            tileType = Declarations.TileType.Unknown;
            break;
        }
        return(tileType != Declarations.TileType.Unknown);
    }
Esempio n. 2
0
    //because unity does not support enum as parameter, maybe there is a better way
    public void SetTile(int index)
    {
        CurrentTileType = (Declarations.TileType)index;
        if (currentImage != null)
        {
            currentImage.color = new Color(1, 1, 1, 1);
        }
        switch (CurrentTileType)
        {
        case Declarations.TileType.Environment:
            currentImage = environmentImage;
            break;

        case Declarations.TileType.Grass:
            currentImage = grassImage;
            break;

        case Declarations.TileType.Path:
            currentImage = pathImage;
            break;

        case Declarations.TileType.Objective:
            currentImage = objectiveImage;
            break;

        case Declarations.TileType.Spawn:
            currentImage = spawnImage;
            break;
        }

        currentImage.color = new Color(1, 1, 0, 1);
    }
Esempio n. 3
0
 private GameObject GetObjectByTileType(Declarations.TileType tileType)
 {
     if (TilesMap.ContainsKey(tileType))
     {
         var tilesForType = TilesMap[tileType];
         var tileIndex    = UnityEngine.Random.Range(0, tilesForType.Length - 1);
         return(tilesForType[tileIndex]);
     }
     else
     {
         Debug.Log("no tiles for tile type" + tileType.ToString());
         return(null);//new GameObject();//so it does not crash and generates the other tiles of the map
     }
 }
    private static bool ReadMapData(XElement mapElement, out Declarations.IntVector2 mapSize, out Declarations.TileType[,] map, bool canHaveEmptyTiles)
    {
        var result = true;
        var width  = mapElement.Attribute(Constants.cst_Width);
        var height = mapElement.Attribute(Constants.cst_Height);

        if (width != null && height != null && !string.IsNullOrEmpty(width.Value) && !string.IsNullOrEmpty(height.Value))
        {
            mapSize = new Declarations.IntVector2(int.Parse(width.Value), int.Parse(height.Value));
            map     = new Declarations.TileType[mapSize.y, mapSize.x];

            var lines = mapElement.Value.Trim().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            if (lines.Count() == mapSize.y)
            {
                for (int row = 0; row < mapSize.y; row++)
                {
                    var line = lines[row].Trim();
                    if (line.Count() == mapSize.x)
                    {
                        for (int col = 0; col < mapSize.x; col++)
                        {
                            Declarations.TileType tileType;
                            if (Helpers.GetTileType(line[col], out tileType, canHaveEmptyTiles))
                            {
                                map[row, col] = tileType;
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
        mapSize = null;
        map     = null;
        return(result);
    }
Esempio n. 5
0
    public Declarations.TileType[,] GetMap()
    {
        var  result  = new Declarations.TileType[MapSize.y, MapSize.x];
        bool invalid = false;

        for (int row = 0; row < MapSize.y; row++)
        {
            for (int col = 0; col < MapSize.x; col++)
            {
                result[row, col] = Map[row, col].Type;
                if (Map[row, col].Type == Declarations.TileType.Unknown)
                {
                    invalid = true;
                }
            }
        }
        if (invalid)
        {
            Debug.Log("Map is invalid");
        }
        return(result);
    }
Esempio n. 6
0
    internal static string GetTileTypeChar(Declarations.TileType tileType)
    {
        switch (tileType)
        {
        case Declarations.TileType.Grass:
            return("/");

        case Declarations.TileType.Path:
            return("#");

        case Declarations.TileType.Objective:
            return("$");

        case Declarations.TileType.Spawn:
            return("*");

        case Declarations.TileType.Environment:
            return("x");

        default:
            Debug.Log("Unknown tile");
            return("");
        }
    }
Esempio n. 7
0
    public void CreateLevelClicked()
    {
        bool error          = false;
        var  invalidSymbols = new List <char> {
            '\\', '/', ':', '*', '?', '"', '<', '>', '|'
        };
        var name = newLevelPanel.transform.GetChild(2).GetChild(1).GetComponent <InputField>().text;
        int width;
        int height;
        int startMoney;
        int startHealth;

        if (string.IsNullOrEmpty(name) || name.Any(x => invalidSymbols.Contains(x)))
        {
            error = true;
            newLevelPanel.transform.GetChild(2).GetChild(1).GetComponent <Image>().sprite = TextFieldError;
        }
        else
        {
            newLevelPanel.transform.GetChild(2).GetChild(1).GetComponent <Image>().sprite = TextFieldNormal;
        }
        if (!int.TryParse(newLevelPanel.transform.GetChild(3).GetChild(1).GetComponent <InputField>().text, out startMoney) || startMoney <= 0)
        {
            error = true;
            newLevelPanel.transform.GetChild(3).GetChild(1).GetComponent <Image>().sprite = TextFieldError;
        }
        else
        {
            newLevelPanel.transform.GetChild(3).GetChild(1).GetComponent <Image>().sprite = TextFieldNormal;
        }
        if (!int.TryParse(newLevelPanel.transform.GetChild(4).GetChild(1).GetComponent <InputField>().text, out startHealth) || startHealth <= 0)
        {
            error = true;
            newLevelPanel.transform.GetChild(4).GetChild(1).GetComponent <Image>().sprite = TextFieldError;
        }
        else
        {
            newLevelPanel.transform.GetChild(4).GetChild(1).GetComponent <Image>().sprite = TextFieldNormal;
        }
        if (!int.TryParse(newLevelPanel.transform.GetChild(5).GetChild(1).GetComponent <InputField>().text, out width) || width < 10 || width > 50)
        {
            error = true;
            newLevelPanel.transform.GetChild(5).GetChild(1).GetComponent <Image>().sprite = TextFieldError;
        }
        else
        {
            newLevelPanel.transform.GetChild(5).GetChild(1).GetComponent <Image>().sprite = TextFieldNormal;
        }
        if (!int.TryParse(newLevelPanel.transform.GetChild(6).GetChild(1).GetComponent <InputField>().text, out height) || height < 10 || height > 50)
        {
            error = true;
            newLevelPanel.transform.GetChild(6).GetChild(1).GetComponent <Image>().sprite = TextFieldError;
        }
        else
        {
            newLevelPanel.transform.GetChild(6).GetChild(1).GetComponent <Image>().sprite = TextFieldNormal;
        }
        if (!error)
        {
            var map = new Declarations.TileType[height, width];
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    map[i, j] = Declarations.TileType.Grass;
                }
            }
            currentlyLoadedLevel = new Declarations.LevelData(name, new Declarations.IntVector2(width, height), map, new List <Declarations.WaveData>(), startMoney, startHealth);
            LoadLevel();
            newLevelPanel.SetActive(false);
            EnableDisablePanels(true);
        }
    }
Esempio n. 8
0
 private void Awake()
 {
     CurrentTileType = Declarations.TileType.Unknown;
 }
 public override void SetData(int row, int col, Declarations.TileType type)
 {
     base.SetData(row, col, type);
     rend.material = GameManager.instance.MapGenerator.TileMaterials[type];
 }
Esempio n. 10
0
 public virtual void SetData(int row, int col, Declarations.TileType type)
 {
     Row  = row;
     Col  = col;
     Type = type;
 }