Пример #1
0
        /// <summary>
        /// Add a tile on the next tile, next to the tileInBetween
        /// </summary>
        private void AddNextTile()
        {
            //Add the path to the next tile, and check if keys / doors need to be placed.
            tileToAdd = new FloorTile();

            // Add a key if the time has come
            foreach (int keyNode in keyNodes)
            {
                if (nodesDone == keyNode)
                {
                    // Once a key has been placed, a door can be placed.
                    tileToAdd = new KeyTile();
                    (tileToAdd as KeyTile).SecondarySpriteColor = ChooseColor(keysPlaced);
                    keyBehindDoorInfo[keysPlaced] = behindDoorInfo[next.X, next.Y];
                    foreach (behindDoorFlags flag in Enum.GetValues(typeof(behindDoorFlags)))
                    {
                        if ((flag & behindDoorInfo[next.X, next.Y]) != 0)
                        {
                            keyBehindDoorInfo[keysPlaced] |= keyBehindDoorInfo[(int)Math.Log((int)flag, 2)];
                        }
                    }
                    keysPlaced++;
                    placeDoors = true;
                    // Choosing a random position next time generally makes it harder to find keys
                    randomNext = true;
                }
            }

            // Exitscore is higher the further you are from the start, following the paths.
            UpdateBestExitScore(current, 1, next);

            // Only place portals if we haven't placed a key
            if (randomChance(portalChance) && !randomNext)
            {
                Point secondPortalPosition = DetermineSecondPortalPosition();
                if (tiles.GetType(secondPortalPosition) == TileType.Wall)
                {
                    tileToAdd = new PortalTile();
                    (tileToAdd as PortalTile).PortalIndex = portalsPlaced;
                    tiles.Add(tileToAdd, secondPortalPosition.X, secondPortalPosition.Y);
                    tileToAdd = new PortalTile();
                    (tileToAdd as PortalTile).PortalIndex = portalsPlaced;
                    // Tile will be added below

                    portalsPlaced++;
                    nodesToDo.Add(secondPortalPosition);
                    UpdateBestExitScore(next, portalScore, secondPortalPosition);
                    UpdateBestExit(secondPortalPosition);
                    behindDoorInfo[secondPortalPosition.X, secondPortalPosition.Y] = behindDoorInfo[next.X, next.Y];
                }
            }

            tiles.Add(tileToAdd, next.X, next.Y);
        }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D))
        {
            playerManager.StepsTaken++;
            Vector3 OldPos = transform.position;
            MovePos();

            if (OldPos != transform.position)
            {
                if (StandingTile.ToggleType)
                {
                    PressurePlate pressurePlate = StandingTile.GetComponent <PressurePlate>();
                    pressurePlate.ToggleState();
                }
                else if (StandingTile.SpikeType)
                {
                    SpikeTile spike = StandingTile.GetComponent <SpikeTile>();
                    if (spike.State)
                    {
                        playerManager.GetHurt();
                    }
                }
                else if (StandingTile.KeyType)
                {
                    KeyTile key = StandingTile.GetComponent <KeyTile>();
                    TotalKeys = key.ToggleState(TotalKeys);
                }
                else if (StandingTile.ChestType)
                {
                    LockedChest chest = StandingTile.GetComponent <LockedChest>();
                    TotalKeys = chest.ToggleState(TotalKeys);
                }
                else if (StandingTile.EndType)
                {
                    EndTile Finish = StandingTile.GetComponent <EndTile>();
                    Finish.ToggleState();
                    MyFiredArrows?.Invoke();
                }
            }
        }
    }
Пример #3
0
    /// <summary>
    /// This method will create the labyrinth.
    /// </summary>
    public void CreateLabyrinth(int sizeX, int sizeZ)
    {
        labyrinthSizeX = sizeX;
        labyrinthSizeZ = sizeZ;

        // labyrinth map
        labyrinthTiles = new LabyrinthTile[labyrinthSizeX, labyrinthSizeZ];

        // list of non-completed tiles
        List <LabyrinthTile> activeTiles = new List <LabyrinthTile>();

        // add the first tile
        activeTiles.Add(NewTile(0, 0));

        // add other tiles
        while (activeTiles.Count > 0)
        {
            ModifyActiveTiles(activeTiles);
        }

        // start tiles
        labyrinthStartInstance = Instantiate(labyrinthTileStartPref, transform) as LabyrinthTileStart;
        labyrinthStartInstance.transform.Translate(-2, 0, 0);
        labyrinthTiles[0, 0].HideWall(2);
        labyrinthTiles[0, 1].HideWall(2);

        // finish tiles
        labyrinthTileFinishInstance = Instantiate(labyrinthTileFinishPref, transform) as LabyrinthTileFinish;
        labyrinthTileFinishInstance.transform.Translate(-labyrinthSizeX - 1, 0, -labyrinthSizeZ + 1);
        labyrinthTiles[labyrinthSizeX - 1, labyrinthSizeZ - 1].HideWall(1);
        labyrinthTiles[labyrinthSizeX - 1, labyrinthSizeZ - 2].HideWall(1);

        // Scale labyrinth
        transform.localScale = new Vector3(10, 5, 10);
        navSurface.BuildNavMesh();

        // Generate key
        keyInstance      = Instantiate(keyPrefab, GameObject.Find("LabyrinthObjects").transform) as KeyTile;
        keyInstance.name = "Key";
        GameObject[] spawnPoints;
        spawnPoints = GameObject.FindGameObjectsWithTag("Tile");
        int index = Random.Range(0, spawnPoints.Length);

        keyInstance.transform.Translate(spawnPoints[index].transform.position);
        keyInstance.ActivateKeyCollider();

        // Generate treasure
        treasureInstance      = Instantiate(treasurePrefab, GameObject.Find("LabyrinthObjects").transform) as Treasure;
        treasureInstance.name = "Treasure";
        treasureInstance.transform.Translate(GameObject.Find("LabyrinthTileFinish(Clone)").transform.position);

        // Spawn character
        characterInstance      = Instantiate(characterPrefab, GameObject.Find("LabyrinthObjects").transform) as Character;
        characterInstance.name = "Character";
        characterInstance.transform.Translate(GameObject.Find("LabyrinthTileStart(Clone)").transform.position);

        // Spawn monsters
        int spawnedMonsters = 0;

        GameObject[] WayPoints;
        WayPoints = GameObject.FindGameObjectsWithTag("Waypoint");

        while (spawnedMonsters < sizeX)
        {
            int indexM = GameObject.Find("GameController").GetComponent <GameController>().GetRandomInt(0, WayPoints.Length);
            if (WayPoints[indexM].transform.parent.GetComponent <LabyrinthTile>().hasMonster == false)
            {
                Monster monster;
                monster = Instantiate(monsterPrefab, GameObject.Find("LabyrinthObjects").transform) as Monster;
                monster.GetComponent <NavMeshAgent>().enabled = false;
                monster.transform.Translate(WayPoints[indexM].transform.position);
                WayPoints[indexM].transform.parent.GetComponent <LabyrinthTile>().hasMonster = true;
                monster.GetComponent <NavMeshAgent>().enabled = true;
                spawnedMonsters++;
            }
        }
    }