Exemplo n.º 1
0
    internal void SetControllerNumber(int number)
    {
        controllerNumber    = number;
        horizontalAxis      = "J" + controllerNumber + "Horizontal";
        verticalAxis        = "J" + controllerNumber + "Vertical";
        horizontalRightAxis = "J" + controllerNumber + "RightHorizontal";
        verticalRightAxis   = "J" + controllerNumber + "RightVertical";
        aButton             = "J" + controllerNumber + "A";
        xButton             = "J" + controllerNumber + "X";
        rightTriggerButton  = "J" + controllerNumber + "RightTrigger";
        startButton         = "J" + controllerNumber + "Start";

        // Set all controls
        GameObject PCBinding = GameObject.Find("PCBinding");
        ControllerPlayerBinding cpBinding = PCBinding.GetComponent <ControllerPlayerBinding>();

        Crosshair player_tank_crosshair_script = player_tank_crosshair.GetComponent <Crosshair>();

        if (cpBinding.getControllerBinding(tank_number) == 5)
        {
            isKeyboard = true;
        }
        player_tank_crosshair_script.SetCrosshairControls(horizontalRightAxis, verticalRightAxis, isKeyboard);

        player_tank_gun_script = player_tank_gun.GetComponent <PlayerGun>();
        print(player_tank_gun_script);
        player_tank_gun_script.SetGunController(xButton, rightTriggerButton);
    }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        isDead      = false;
        gameManager = FindObjectOfType(typeof(GameManager)) as GameManager;
        healthMax   = 100; // temp
        health      = healthMax;
        GameObject PCBinding = GameObject.Find("PCBinding");
        ControllerPlayerBinding cpBinding = PCBinding.GetComponent <ControllerPlayerBinding>();

        SetControllerNumber(cpBinding.getControllerBinding(tank_number));
        rb             = GetComponent <Rigidbody2D>();
        rb.constraints = RigidbodyConstraints2D.FreezeRotation;
        groundmap      = GameObject.Find("GroundGrid").GetComponent <Tilemap>();
    }
Exemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        countdownUI.SetActive(true);

        SaveSystem.Init();

        // Get player controller bindings
        GameObject PCBinding = GameObject.Find("PCBinding");
        ControllerPlayerBinding cpBinding = PCBinding.GetComponent <ControllerPlayerBinding>();

        //player_info = cpBinding.getPlayerInfo();

        /* Possibly use constructor (maybe not a good idea) http://ilkinulas.github.io/development/unity/2016/05/30/monobehaviour-constructor.html
         * for (int i = 0; i < 0; i++)
         * {
         *  if (player_info[i, 0] != 0)
         *  {
         *      player = new PlayerController(player_info[i, 0], player_info[i, 1], player_info[i, 2]);
         *  }
         * }*/

        // Used to load specific map

        /*
         * if (cpBinding.getLevelPath() != null) MapSystem.Play_Selected_Map(tilemapGround, tilemapWall, tilemapObjects, tilemapTop, cpBinding.getLevelPath(), tile_prefab_array, ground_tiles_array, wall_tiles_array, objects_tiles_array, top_tiles_array);
         * else SceneManager.LoadScene("MenuScene");
         */
        currentLevelIndex = MapSystem.Play_Map(tilemapGround, tilemapWall, tilemapObjects, tilemapTop, -1, tile_prefab_array, ground_tiles_array, wall_tiles_array, objects_tiles_array, top_tiles_array);
        if (currentLevelIndex == -1)
        {
            Debug.Log("Couldn't find a map to load. (2)");
            SceneManager.LoadScene("MenuScene");
        }

        spawnPlayersFromLobby(cpBinding);

        centerCamera();
    }
Exemplo n.º 4
0
    void spawnPlayersFromLobby(ControllerPlayerBinding playerControllerBinding)
    {
        PlayerSpawnArray = GameObject.FindGameObjectsWithTag("PlayerSpawn"); // Find all spawnpoints and put them in an array
        player_spawned   = new bool[PlayerSpawnArray.Length];                // Array

        for (int i = 0; i < 4; i++)
        {
            if (playerControllerBinding.getControllerBinding(i + 1) != 0 && PlayerSpawnArray.Length > 0)
            {
                // If not enough spawnpoints for players return to the main menu
                if (PlayerSpawnArray.Length <= playingPlayers)
                {
                    Debug.Log("PlayerSpawnArray length is too short for the amount of players. (1)");
                    SceneManager.LoadScene("MenuScene");
                }
                else
                {
                    playingPlayers++;

                    // Create GameObjects
                    GameObject tank;
                    GameObject tank_crosshair;

                    // Get random spawn spot
                    int spawn_spot = RandomPlayerSpawn();
                    if (spawn_spot == -1)
                    {
                        Debug.Log("Couldn't get free spawn_spot. (1) Level index: " + currentLevelIndex);
                        SceneManager.LoadScene("MenuScene");
                    }

                    // Spawn crosshair and tank on player spawn
                    tank_crosshair = Instantiate(crosshairs[i], PlayerSpawnArray[spawn_spot].transform.position, Quaternion.identity);
                    tank           = Instantiate(tanks[i], PlayerSpawnArray[spawn_spot].transform.position, Quaternion.identity);

                    allplayers[i] = tank;

                    tank.GetComponent <PlayerController>().SetCrosshair(tank_crosshair);
                    tank.GetComponent <PlayerController>().SetHealthBar(health_bars[i]);
                    //tank.GetComponent<PlayerController>().SendPlayerInfo(player_info);
                }
            }
            else
            {
                health_bars[i].SetActive(false);
            }
        }

        // If not enough players joined return to the main menu
        if (playingPlayers < 2)
        {
            Debug.Log("Not enough players joined (less than 2)");
            SceneManager.LoadScene("MenuScene");
        }

        // Destroy all Spawns
        for (int i = 0; i < PlayerSpawnArray.Length; i++)
        {
            Destroy(PlayerSpawnArray[i]);
        }
    }