コード例 #1
0
    bool CreateDirectCorridor(CARoom roomA, CARoom roomB, Tile tileA, Tile tileB, bool dontCross = false)
    {
        List <Tile> line = TileTools.GetLine(tileA, tileB);

        if (dontCross)
        {
            for (int i = 2; i < line.Count - 2; i++)
            {
                if (map[line[i].tileX, line[i].tileY] == 0)
                {
                    return(false);
                }
            }
        }



        foreach (Tile c in line)
        {
            for (int x = c.tileX - 1; x <= c.tileX + 1; x++)
            {
                for (int y = c.tileY - 1; y <= c.tileY + 1; y++)
                {
                    map[x, y] = 0;
                    InstantiateFromArray(floorTiles, x, y);
                    //InstantiateFromArray(rubbleTiles, x, y);
                }
            }
        }

        CARoom.ConnectRooms(roomA, roomB);
        return(true);
    }
コード例 #2
0
ファイル: MapGenerator.cs プロジェクト: newtdogg/zmobies
 void Start()
 {
     shop            = GameObject.Find("Shop");
     map             = gameObject.GetComponent <Map>();
     craftingStation = GameObject.Find("CraftingStation");
     shadowBlock     = GameObject.Find("Shadow");
     player          = GameObject.Find("Player");
     // mapToCreate = GameObject.Find("GameController").GetComponent<GameController>().activeMap;
     // mapToCreate = new DebugMap().map;
     // mapToCreate = new SurvivalMap().map;
     mapToCreate  = generateMapFromCells();
     tileTools    = GameObject.Find("TileTools").GetComponent <TileTools>();
     spawners     = new Dictionary <int, Spawner>();
     arenaWalls   = new Dictionary <int, List <List <Vector2Int> > >();
     spawnerCount = 0;
     shadowParent = transform.parent.GetChild(1).gameObject;
     borderShadow = transform.parent.GetChild(2).gameObject;
     if (generateRandomMap)
     {
         // CODE GOES HERE
     }
     else
     {
         simpleMapGeneration(mapToCreate);
         mapGenerated = true;
     }
 }
    public bool IsPlacedOnLand(int x, int y)
    {
        if (MapTools.IsOutOfBounds(x, y))
        {
            return(false);
        }
        for (int k = -1; k < 2; k++)
        {
            for (int l = -1; l < 2; l++)
            {
                if (MapTools.IsOutOfBounds(x + k, y + l))
                {
                    return(false);
                }
                if (!TileTools.IsLand(GameTools.Map.TileMapData[x + k, y + l]))
                {
                    return(false);
                }
                else
                {
                }
            }
        }

        return(true);
    }
コード例 #4
0
    void Start()
    {
        requestManager = GetComponent <PathRequestController>();
        var mapObject = GameObject.Find("MapGridObject");

        tilemap      = mapObject.transform.GetChild(0).gameObject.GetComponent <Tilemap>();
        mapGenerator = mapObject.GetComponent <MapGenerator>();
        map          = mapObject.GetComponent <Map>();
        tileTools    = GameObject.Find("TileTools").GetComponent <TileTools>();
    }
コード例 #5
0
 void Awake()
 {
     walls             = new List <List <Vector2Int> >();
     battleStarted     = false;
     empty             = true;
     zombieSourceClone = GameObject.Find("SpawnerSource");
     zombieTypes       = getSpawnerObjectsOfType("Zombies");
     minibossTypes     = getSpawnerObjectsOfType("MiniBosses");
     wallClone         = GameObject.Find("Wall");
     wallNodeClone     = GameObject.Find("WallNode");
     lootController    = GameObject.Find("LootController").GetComponent <LootController>();
     zombiesList       = transform.GetChild(0);
     tileTools         = GameObject.Find("TileTools").GetComponent <TileTools>();
 }
    public void MoveRandomly()
    {
        int newX = 0, newY = 0;

        list_directions = new List <Direction>();
        for (int i = 0; i < 10; i++)
        {
            Direction d = (Direction)Random.Range(1, 5);
            switch (d)
            {
            case Direction.Right:
                newX = Map_position_x + 1;
                newY = Map_position_y;
                break;

            case Direction.Left:
                newX = Map_position_x - 1;
                newY = Map_position_y;
                break;

            case Direction.Up:
                newX = Map_position_x;
                newY = Map_position_y + 1;
                break;

            case Direction.Down:
                newX = Map_position_x;
                newY = Map_position_y - 1;
                break;

            default:
                Debug.LogError("Defaulted");
                break;
            }
            if (!MapTools.IsOutOfBounds(newX, newY) &&
                (GameTools.Map.map_unit_occupy[newX, newY] == null &&
                 (GameTools.Player.Map_position_x != newX || GameTools.Player.Map_position_y != newY) &&
                 TileTools.IsLand(GameTools.Map.TileMapData[newX, newY])))
            {
                list_directions.Add(d);
                GameTools.Map.map_unit_occupy[Map_position_x, Map_position_y] = null;
                GameTools.Map.map_unit_occupy[newX, newY] = this;
                Map_position_x = newX;
                Map_position_y = newY;
                break;
            }
        }
    }
    protected override void InitMapPosition()
    {
        if (Map_position_x == 0 && Map_position_y == 0)
        {
            Map_position_x = Random.Range(0, GameTools.Map.size_x);
            Map_position_y = Random.Range(0, GameTools.Map.size_z);

            while (GameTools.Map.map_unit_occupy[Map_position_x, Map_position_y] != null ||
                   (!TileTools.IsLand(GameTools.Map.TileMapData[Map_position_x, Map_position_y])) ||
                   GraphSearch.fromPosition(Map_position_x, Map_position_y).manhattanDistanceFromTarget(GameTools.Player.Map_position_x, GameTools.Player.Map_position_y) < 10)
            {
                Map_position_x = Random.Range(0, GameTools.Map.size_x);
                Map_position_y = Random.Range(0, GameTools.Map.size_z);
            }
        }
    }
コード例 #8
0
    private void GenerateBonusTiles()
    {
        BonusTileData = new BonusTile[size_x, size_z];

        for (int i = 0; i < size_x; i++)
        {
            for (int j = 0; j < size_z; j++)
            {
                if (TileTools.IsLand(TileMapData[i, j]))
                {
                    if (TileMapData[i, j] == TileType.DarkGreen)
                    {
                        if (Random.Range(1, 100) <= 5)
                        {
                            BonusTileData[i, j] = new BonusTile(i, j);
                        }
                    }
                }
            }
        }
    }
コード例 #9
0
    public void InitSpawners(int playerlevel, int difficultyChange)
    {
        Debug.Log("Difficulty change " + difficultyChange);
        int SpawnerCount = 10 + difficultyChange;

        if (SpawnerCount < 5)
        {
            SpawnerCount = 5;
        }
        if (SpawnerCount > 20)
        {
            SpawnerCount = 20;
        }
        Debug.Log("SpawnerCount " + SpawnerCount);
        while (SpawnerCount > 0)
        {
            int randX = Random.Range(0, size_x);
            int randY = Random.Range(0, size_z);
            if (GraphSearch.fromPosition(randX, randY)
                .manhattanDistanceFromTarget(GameTools.Player.Map_position_x, GameTools.Player.Map_position_y) <= 25)
            {
                continue;
            }
            if (TileTools.IsLand(TileMapData[randX, randY]))
            {
                if (BonusTileData[randX, randY] == null &&
                    SpawnerMap[randX, randY] == null)
                {
                    SpawnerCount--;
                    EnemySpawner e = new EnemySpawner(randX, randY, playerlevel, difficultyChange);
                    SpawnerMap[randX, randY] = e;
                    Spawners.Add(e);
                }
            }
        }
    }
コード例 #10
0
    public bool listenInput()
    {
        bool validInput = false;

        castedSpell = false;
        //Keyboard
        if (Input.GetKey("w"))
        {
            validInput     = true;
            current_target = Direction.Up;
        }
        else if (Input.GetKey("a"))
        {
            current_target = Direction.Left;
            validInput     = true;
        }
        else if (Input.GetKey("s"))
        {
            current_target = Direction.Down;
            validInput     = true;
        }
        else if (Input.GetKey("d"))
        {
            current_target = Direction.Right;
            validInput     = true;
        }
        else if (Input.GetKey("space"))         //skips turn
        {
            current_target = Direction.None;
            validInput     = true;
        }
        else if (Input.GetKeyUp("1"))
        {
            spellIndicator.toggleIndicator();
            PlayerCastIndicator.ToggleUnit(this);
            current_target = Direction.None;
        }
        else
        {
            current_target = Direction.None;
        }

        //Check to see if player is going somewhere invalid
        int newX = 0, newY = 0;

        switch (current_target)
        {
        case Direction.Down:
            newX = Map_position_x;
            newY = Map_position_y - 1;
            if (MapTools.IsOutOfBounds(newX, newY))
            {
                current_target = Direction.None;
                validInput     = false;
            }
            else
            {
                if ((GameTools.Map.map_unit_occupy[newX, newY] != null &&
                     !GameTools.Map.map_unit_occupy[newX, newY].IsEntityAbleToMoveHere(this)) ||
                    GameTools.Base.IsMovingOnTurret(newX, newY) ||
                    (!TileTools.IsLand(GameTools.Map.TileMapData[newX, newY])))
                {
                    current_target = Direction.None;
                    validInput     = false;
                }
            }
            break;

        case Direction.Up:
            newX = Map_position_x;
            newY = Map_position_y + 1;
            if (MapTools.IsOutOfBounds(newX, newY))
            {
                current_target = Direction.None;
                validInput     = false;
            }
            else
            {
                if ((GameTools.Map.map_unit_occupy[newX, newY] != null &&
                     !GameTools.Map.map_unit_occupy[newX, newY].IsEntityAbleToMoveHere(this)) ||
                    GameTools.Base.IsMovingOnTurret(newX, newY) ||
                    (!TileTools.IsLand(GameTools.Map.TileMapData[newX, newY])))
                {
                    current_target = Direction.None;
                    validInput     = false;
                }
            }
            break;

        case Direction.Left:
            newX = Map_position_x - 1;
            newY = Map_position_y;
            if (MapTools.IsOutOfBounds(newX, newY))
            {
                current_target = Direction.None;
                validInput     = false;
            }
            else
            {
                if ((GameTools.Map.map_unit_occupy[newX, newY] != null &&
                     !GameTools.Map.map_unit_occupy[newX, newY].IsEntityAbleToMoveHere(this)) ||
                    GameTools.Base.IsMovingOnTurret(newX, newY) ||
                    (!TileTools.IsLand(GameTools.Map.TileMapData[newX, newY])))
                {
                    current_target = Direction.None;
                    validInput     = false;
                }
            }
            break;

        case Direction.Right:
            newX = Map_position_x + 1;
            newY = Map_position_y;
            if (MapTools.IsOutOfBounds(newX, newY))
            {
                current_target = Direction.None;
                validInput     = false;
            }
            else
            {
                if ((GameTools.Map.map_unit_occupy[newX, newY] != null &&
                     !GameTools.Map.map_unit_occupy[newX, newY].IsEntityAbleToMoveHere(this)) ||
                    GameTools.Base.IsMovingOnTurret(newX, newY) ||
                    (!TileTools.IsLand(GameTools.Map.TileMapData[newX, newY])))
                {
                    current_target = Direction.None;
                    validInput     = false;
                }
            }
            break;

        case Direction.None:
            break;
        }

        //Mouse
        if (Input.GetMouseButtonDown(0))
        {
            if (spellIndicator.IsShowingIndicator)
            {
                validInput = CastMainSpell();
            }
        }
        return(validInput);
    }
コード例 #11
0
    private void GenerateHeightMap(DataTileMap map)
    {
        int[,] tempIntMap = (int[, ])map.Map_data_passable.Clone();
        PassableMapData   = (int[, ])map.Map_data_passable.Clone();

        //Figure out which is ocrean water and which tiles is pool water
        int count = GraphSearch.fromPosition(0, 0).DepthFirstFlood(tempIntMap, new CheckPassable(GraphSearch.DefaultNotPassable), new ActionOnVisit(MarkAsOceanWater)).CountedTiles;

        for (int i = 0; i < size_x; i++)
        {
            for (int j = 0; j < size_z; j++)
            {
                if (tempIntMap[i, j] == -1)
                {
                    TileMapData[i, j] = TileTools.OceanTile;
                }
                else if (tempIntMap[i, j] == 0)
                {
                    TileMapData[i, j] = TileTools.PoolTile;
                }
                else if (tempIntMap[i, j] > 0)
                {
                    TileMapData[i, j] = TileTools.InnerLandTile;
                }
            }
        }

        bool changed    = false;
        int  debugCount = 0;

        do
        {
            changed = false;
            debugCount++;
            if (debugCount > 1000)
            {
                Debug.LogError("Infinite loop in here");
                return;
            }
            for (int i = 0; i < size_x; i++)
            {
                for (int j = 0; j < size_z; j++)
                {
                    if (TileTools.IsLand(TileMapData[i, j]))
                    {
                        int newX;
                        int newY;
                        newX = i + 1;
                        newY = j;
                        if (!MapTools.IsOutOfBounds(newX, newY))
                        {
                            if (TileTools.IsHigherByMoreThanOne(TileMapData[i, j], TileMapData[newX, newY]))
                            {
                                TileMapData[i, j] = TileTools.HeightMappingIncreaseTile(TileMapData[newX, newY]);
                                changed           = true;
                            }
                        }
                        newX = i - 1;
                        newY = j;
                        if (!MapTools.IsOutOfBounds(newX, newY))
                        {
                            if (TileTools.IsHigherByMoreThanOne(TileMapData[i, j], TileMapData[newX, newY]))
                            {
                                TileMapData[i, j] = TileTools.HeightMappingIncreaseTile(TileMapData[newX, newY]);
                                changed           = true;
                            }
                        }
                        newX = i;
                        newY = j + 1;
                        if (!MapTools.IsOutOfBounds(newX, newY))
                        {
                            if (TileTools.IsHigherByMoreThanOne(TileMapData[i, j], TileMapData[newX, newY]))
                            {
                                TileMapData[i, j] = TileTools.HeightMappingIncreaseTile(TileMapData[newX, newY]);
                                changed           = true;
                            }
                        }
                        newX = i;
                        newY = j - 1;
                        if (!MapTools.IsOutOfBounds(newX, newY))
                        {
                            if (TileTools.IsHigherByMoreThanOne(TileMapData[i, j], TileMapData[newX, newY]))
                            {
                                TileMapData[i, j] = TileTools.HeightMappingIncreaseTile(TileMapData[newX, newY]);
                                changed           = true;
                            }
                        }
                    }
                }
            }
        } while (changed);

        Debug.Log("HeightMap complete");
    }