예제 #1
0
    /// <summary>
    /// Tries to move actor based on command.
    /// </summary>
    /// <param name="_actor">Actor to move</param>
    /// <param name="_command">Command to execute</param>
    /// <returns>Success or fail</returns>
    public bool TryCommand(Actor _actor, Commands _command)
    {
        if (_actor == null)
        {
            return(false);
        }

        TilePosition desiredPosition = BoardMethod.GetTileFromCommand(_actor, _command);

        if (!BoardMethod.isPositionEmpty(desiredPosition))
        {
            Debug.Log(_actor.actorName + " Desired position isn't empty");
            Actor _actorInPosition = BoardMethod.GetActorInPosition(desiredPosition);
            if (_actorInPosition != null)
            {
                _actor.Attack(_actorInPosition);
                return(true);
            }
            return(false);
        }

        _actor.currentPosition = desiredPosition;
        Debug.Log(_actor.actorName + " command is valid, let's try moving");
        Vector3 _newTilePosition = mapTiles[desiredPosition.x, desiredPosition.y].transform.position;

        _actor.transform.DOMove(_newTilePosition, 0.25f).SetEase(Ease.OutBack);
        return(true);
    }
예제 #2
0
    /// <summary>
    /// Spawn player for the desired username using ObjectPool pooling system.
    /// Find a random empty spot on the board and move the newly spawned player there.
    /// </summary>
    /// <param name="username">desired username for player</param>
    /// <returns>Spawned Player Prefab.</returns>
    public Actor SpawnPlayer(string username)
    {
        //If there is already a player with that username don't spawn it.
        if (playerDictionary.ContainsKey(username))
        {
            return(null);
        }

        //Spawn Player Object.
        ActorPlayer spawnedPlayer = playerPrefab.Spawn();

        //Set position.
        spawnedPlayer.currentPosition = BoardMethod.GetRandomTile();
        Tile emptyTile = BoardMethod.GetTile(spawnedPlayer.currentPosition);

        spawnedPlayer.transform.position = emptyTile.transform.position;

        spawnedPlayer.spriteRenderer.color = Color.white;

        //Set username.
        spawnedPlayer.actorName = username;

        //Add to dictionary so we can reference it later by username.
        playerDictionary.Add(username, spawnedPlayer);

        return(spawnedPlayer);
    }
예제 #3
0
    public override void Tick()
    {
        if (votedCommands.Count > 0)
        {
            NextCommand = votedCommands.Keys.OrderByDescending(x => votedCommands[x]).First();
            votedCommands.Clear();
        }
        else
        {
            if (GameManager.playerDictionary.Count > 0)
            {
                ActorPlayer desiredPlayer = BoardMethod.GetClosestPlayer(currentPosition);
                if (desiredPlayer != null)
                {
                    NextCommand = BoardMethod.GetCommandTowardsTile(currentPosition, desiredPlayer.currentPosition);
                }
            }
            else
            {
                NextCommand = (Commands)Random.Range(0, 5);
            }
        }

        base.Tick();
    }
예제 #4
0
    public Actor SpawnEnemy()
    {
        //Spawn Player Object.
        ActorEnemy spawnedPlayer = enemyPrefab.Spawn();

        //Set position.
        spawnedPlayer.currentPosition = BoardMethod.GetRandomTile();
        Tile emptyTile = BoardMethod.GetTile(spawnedPlayer.currentPosition);

        spawnedPlayer.transform.position = emptyTile.transform.position;

        spawnedPlayer.spriteRenderer.color = Color.red;

        //Set username.
        spawnedPlayer.actorName = GetEnemyName();

        //Add to dictionary so we can reference it later by username.
        enemyDictionary.Add(spawnedPlayer.actorName, spawnedPlayer);

        return(spawnedPlayer);
    }
예제 #5
0
    /// <summary>
    /// Sets up the outer walls and floor (background) of the game board.
    /// </summary>
    public IEnumerator DOBoardSetup()
    {
        boardReady = false;
        GameManager.ResetAll();

        //Set our map/maptiles array size.
        map      = new TType[rows + 1, columns + 1];
        mapTiles = new Tile[rows + 1, columns + 1];

        //Go over each spot on the array and make them all walls.
        for (int y = 0; y < map.GetLength(1); y++)
        {
            for (int x = 0; x < map.GetLength(0); x++)
            {
                map[x, y] = TType.Wall;
            }
        }

        //Go over the whole map and spawn tiles, and assign the tile values based on the map.
        for (int x = 0; x < map.GetLength(0); x++)
        {
            for (int y = 0; y < map.GetLength(1); y++)
            {
                Tile _tileref = testTile.Spawn();
                mapTiles[x, y]              = _tileref;
                _tileref.tilePosition       = new TilePosition(x, y);
                _tileref.transform.position = new Vector3((Mathf.Floor(rows / 2) * tileSize) - (x * tileSize), (Mathf.Floor(columns / 2) * tileSize) - (y * tileSize), 0);
                PaintTile(x, y);
                _tileref.gameObject.name = "Tile " + x + "/" + y;
                _tileref.transform.SetParent(transform);
            }
        }

        yield return(null);

        //Get a random position to start our tunneler.
        TilePosition centerPos = new TilePosition(Mathf.FloorToInt(map.GetLength(0) * 0.5f), Mathf.FloorToInt(map.GetLength(1) * 0.5f));

        List <TilePosition> aroundCenterPos = BoardMethod.GetTilesAroundTile(centerPos, 4, TType.Wall);

        TilePosition tunnelerPos = aroundCenterPos[Random.RandomRange(0, aroundCenterPos.Count)];

        int amountToDig = Mathf.FloorToInt((map.GetLength(0) - 2) * (map.GetLength(1) - 2) * digTilePct);

        yield return(null);

        Commands tunnelerCommand = (Commands)Random.Range(1, 5);

        while (amountToDig > 0)
        {
            yield return(null);

            if (BoardMethod.getTileType(tunnelerPos.x, tunnelerPos.y) == TType.Wall)
            {
                float roomChance = 0.05f;
                if (BoardMethod.CountTilesAlignedAroundTile(tunnelerPos, 3, TType.Floor) == 2)
                {
                    roomChance = 0.55f;
                }
                if (Random.value < roomChance)
                {
                    var tilesAllAround = BoardMethod.GetTilesAroundTile(tunnelerPos, 1, TType.Wall);
                    amountToDig -= 3;
                    foreach (TilePosition _tilePosition in tilesAllAround)
                    {
                        TurnToFloor(_tilePosition);
                    }
                }
                else
                {
                    amountToDig--;
                    TurnToFloor(tunnelerPos);
                }
            }
            TilePosition possibleTunnelerPos = BoardMethod.GetTileFromCommand(tunnelerPos, tunnelerCommand);
            if (BoardMethod.isPositionValid(possibleTunnelerPos))
            {
                tunnelerPos = possibleTunnelerPos;
            }
            else
            {
                tunnelerCommand = Random.value < 0.5
                    ? BoardMethod.GetNextCommand(tunnelerCommand)
                    : BoardMethod.GetPrevCommand(tunnelerCommand);
            }

            if (Random.value < 0.25f)
            {
                tunnelerCommand = Random.value < 0.5
                    ? BoardMethod.GetNextCommand(tunnelerCommand)
                    : BoardMethod.GetPrevCommand(tunnelerCommand);
            }
        }

        boardReady = true;

        for (int i = 0; i < 3; i++)
        {
            GameManager.get.SpawnEnemy();
        }
    }