Beispiel #1
0
    public void Setup(GameState.PlayerState playerState, Transform spawnPoint)
    {
        transform.position = spawnPoint.position;
        transform.rotation = spawnPoint.rotation;

        brain = playerState.PlayerInfo.Brain;
        SetColor(playerState.PlayerInfo.Color);

        player           = playerState;
        playerState.Tank = this;

        enabled = true;
    }
Beispiel #2
0
    public GameState.PlayerState CreatePlayerState()
    {
        GameState.PlayerState newPlayerState = new GameState.PlayerState();
        newPlayerState.PlayerIndex = PlayerIndex;

        newPlayerState.PlayerPosition = this.transform.position;
        newPlayerState.Health         = CurrentHealth;
        newPlayerState.ChipDamage     = CurrentChipDamage;
        newPlayerState.ComboDamage    = ComboDamage;
        newPlayerState.SpecialMeter   = SpecialMeter;

        newPlayerState.InputData = new PlayerInputPacket.PlayerInputData();
        newPlayerState.InputData.InputPattern = CommandInterpreter.GetPlayerInputByte();

        return(newPlayerState);
    }
Beispiel #3
0
    public void ApplyPlayerState(GameState.PlayerState playerState)
    {
        this.transform.position = playerState.PlayerPosition;

        CurrentHealth     = playerState.Health;
        CurrentChipDamage = playerState.ChipDamage;
        ComboDamage       = playerState.ComboDamage;
        SpecialMeter      = playerState.SpecialMeter;

        Anim.SetInteger(SpecialMeterParameter, (int)(SpecialMeter / SpecialMeterStockCount));

        OnCharacterHealthChanged.Invoke();
        OnMoveExecuted.Invoke();

        CommandInterpreter.ClearPlayerInputQueue();
    }
    private GameState CreateNewGameState()
    {
        GameState NewGameState = new GameState();

        NewGameState.RoundCount   = RoundCount;
        NewGameState.FrameCount   = FrameCount;
        NewGameState.RoundTime    = (ushort)RoundTime;
        NewGameState.PlayerStates = new List <GameState.PlayerState>();

        foreach (PlayerController player in Overseer.Instance.Players)
        {
            GameState.PlayerState state = player.CharacterStats.CreatePlayerState();

            NewGameState.PlayerStates.Add(state);
        }

        return(NewGameState);
    }
    // Update is called once per frame
    void Update()
    {
        bool isInGame = false;

        foreach (GameState.PlayerState player in GameState.playerStates)
        {
            if (player.playerId == playerId)
            {
                isInGame       = true;
                playerState    = player;
                textMesh.text  = "Player " + (playerId + 1) + ": " + playerState.score;
                textMesh.color = playerState.color;

                break;
            }
        }

        if (!isInGame)
        {
            gameObject.SetActive(false);
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        numberOfPlayers = GameSettings.playerCount;

        playerColors = new Dictionary <int, Color>();
        playerColors.Add(0, new Color(25f, 0f, 0f, 255f));
        playerColors.Add(1, new Color(0f, 25f, 0f, 255f));
        playerColors.Add(2, new Color(0f, 0f, 25f, 255f));
        playerColors.Add(3, new Color(0f, 25f, 25f, 255f));
        playerColors.Add(4, new Color(25f, 25f, 0f, 255f));
        playerColors.Add(5, new Color(25f, 0f, 25f, 255f));
        playerColors.Add(6, new Color(0, 0f, 0, 255f));
        playerColors.Add(7, new Color(0f, 25f, 25f, 255f));

        float xLoc = Constants.DISTANCE_BETWEEN_CARS * (numberOfPlayers + Constants.ADDITONAL_CARS) / 2 + 0.5f;

        engine = Instantiate(enginePrefab, new Vector3(xLoc - 1.7f, 0.4f, 0), Quaternion.identity);
        engine.transform.localScale = new Vector3(0.8f, 0.8f, 1f);

        maxPoints = numberOfPlayers * (int)gameTotalTime * 5;
        train     = Instantiate(trainPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        train.GetComponent <Train>().numberOfCars = numberOfPlayers + Constants.ADDITONAL_CARS;

        playersObjects = new List <GameObject>();
        players        = new List <Player>();

        GameState.playerStates = new List <GameState.PlayerState>();

        int gamePadCount  = Gamepad.all.Count;
        int keyboardCount = 1;

        for (int i = 0; i < numberOfPlayers; i++)
        {
            xLoc = Constants.DISTANCE_BETWEEN_CARS * (i - numberOfPlayers / 2);
            GameObject player = Instantiate(playerPrefab, new Vector3(xLoc, 0, 0), Quaternion.identity);

            player.GetComponent <SpriteRenderer>().color = playerColors[i];

            if (gamePadCount > 0)
            {
                player.GetComponent <PlayerInput>().currentActionMap.devices = new InputDevice[] { Gamepad.all[i] };
                gamePadCount--;
            }
            else if (keyboardCount <= 4)
            {
                player.GetComponent <PlayerInput>().SwitchCurrentActionMap("Keys_" + keyboardCount);
                keyboardCount++;
            }
            playersObjects.Add(player);
            Player playerScript = player.GetComponent <Player>();
            playerScript.setCurrentPosition(new Vector2(xLoc, 0));

            // Create a new player state and add it to the player
            GameState.PlayerState playerState = new GameState.PlayerState();
            playerState.playerId = i;
            playerState.color    = playerColors[i];
            GameState.playerStates.Add(playerState);
            playerScript.playerState = GameState.playerStates[GameState.playerStates.Count - 1];
            players.Add(playerScript);
        }
    }