Beispiel #1
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);
    }
Beispiel #2
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);
    }