void OnTriggerEnter(Collider other)
 {
     if (photonView.isMine && isColliderEnabled)
     {
         //Debug.Log("going in");
         GameObject obj = other.gameObject;
         //Debug.Log(obj.tag);
         //Debug.Log(obj.name);
         //Debug.Log(obj);
         if (obj.tag == "avatar")
         {
             //Debug.Log("shuriken hit player");
             PlayerNetworkController parent = obj.GetComponentInParent <PlayerNetworkController>();
             if (parent != null)
             {
                 parent.dealDamage(20);
             }
             else
             {
                 Debug.Log("ERROR playernetworkcontroller not found");
             }
         }
         else if (obj.tag == "shield")
         {
             //Debug.Log ("shuriken hit shield");
             obj.SetActive(false);
         }
         PhotonNetwork.Destroy(this.gameObject);
         //Debug.Log("shuriken destroyed");
     }
 }
    void Start()
    {
        if (!isLocalPlayer())
        {
            return;
        }

        // Find game objects
        disc = GameObject.Find("Disc");
        GameObject energySliderObject   = GameObject.Find("/HUD/Canvas/IngameDisplay/EnergyBar");
        GameObject interactSliderObject = GameObject.Find("/HUD/Canvas/IngameDisplay/InteractBar");

        // Show HUD
        energySlider   = energySliderObject.GetComponent <Slider>();
        interactSlider = interactSliderObject.GetComponent <Slider>();

        // Hide self in FP camera
        MoveToLayer(transform, 8);

        animator                = GetComponent <Animator>();
        discController          = disc.GetComponent <DiscController>();
        playerNetworkController = GetComponentInParent <PlayerNetworkController>();

        energy = maxEnergy;
        energySlider.maxValue   = maxEnergy;
        nextInteractTime        = Time.time;
        interactSlider.maxValue = interactRecovery;
    }
Exemple #3
0
    //Map network data to player animator
    private void NetworkAnimator(string guestName, float v, float h, float f, bool isC, bool isJ, Vector3 pos, Vector3 rot, string pow, bool isHider)
    {
        if (guests.Count == 0)
        {
            return;
        }

        foreach (Guest g in guests)
        {
            if (g.guestName.Equals(guestName))
            {
                PlayerNetworkController p = g.playerController;
                p.setVerticalAxis(v);
                p.setHorizontalAxis(h);
                p.setFallDistance(f);
                p.IsCrouching(isC);
                p.IsJumping(isJ);
                p.setPosition(pos);
                p.setRotation(rot);
                p.setPower(pow);
                p.setMatchRole(isHider);
                p.setScore(g.getScore());
                return;
            }
        }
    }
Exemple #4
0
 // Player snake growth needs to handle zooming out the camera, and updating the score text
 public override void GrowSnake()
 {
     base.GrowSnake();
     // zoom out
     if (tail.Count > GetStartingLength())
     {
         PlayerNetworkController parentScript = this.transform.parent.GetComponent <PlayerNetworkController>();
         parentScript.ZoomCamera(1.0f);
         //ZoomCamera(1.0f);
     }
     lengthText.text = "Length: " + tail.Count.ToString();
 }
    /////////////////////
    //COLLISION CHECKER//
    /////////////////////
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Zombie") || other.gameObject.CompareTag("Player"))
        {
            var otherPlayer           = other.gameObject;
            var otherPlayerAttributes = otherPlayer.GetComponent <PlayerAttributes>();
            var playerAttributes      = GetComponent <PlayerAttributes>();
            Debug.Log("PlayerMass" + otherPlayerAttributes.playerMass);
            Debug.Log("MyselfMass" + playerAttributes.playerMass);
            // If main player is smaller
            if (otherPlayerAttributes.playerMass > playerAttributes.playerMass)
            {
                PlayerNetworkController.Kill(playerAttributes.id, GetComponent <Transform>().position.x, GetComponent <Transform>().position.z);
            }

            // If other player is smaller
            else if (otherPlayerAttributes.playerMass < playerAttributes.playerMass)
            {
                PlayerNetworkController.Kill(otherPlayerAttributes.id, other.GetComponent <Transform>().position.x, other.GetComponent <Transform>().position.z);
                Debug.Log(GameAttributes.mainPlayer.GetComponent <PlayerAttributes>().id + " " + playerAttributes.id);
                if (GameAttributes.mainPlayer.GetComponent <PlayerAttributes>().id == playerAttributes.id)
                {
                    particles.Play();
                }
                if (other.gameObject.CompareTag("Zombie"))
                {
                    ZombieSpawner.ZombieCollide(other.gameObject.transform.parent.gameObject);
                }
            }
        }

        if (other.gameObject.CompareTag("Obstacle"))
        {
            var playerId   = GetComponent <PlayerAttributes>().id;
            var obstacleId = other.GetComponent <ObstacleController>().id;
            // Debug.Log(id);
            KnickKnackNetworkController.ObstacleCollision(playerId, obstacleId);
            GetComponent <PlayerMovement>().HitObstacle();
        }

        if (other.gameObject.CompareTag("Food"))
        {
            var playerId = GetComponent <PlayerAttributes>().id;
            var foodId   = other.GetComponent <FoodController>().id;
            // Debug.Log(id);
            KnickKnackNetworkController.FoodEaten(playerId, foodId);
        }
    }
Exemple #6
0
    // a thread to drop tail links while boosted
    IEnumerator DropTailLinks()
    {
        while (true)
        {
            yield return(new WaitForSeconds(0.9f));

            if (boosted && tail.Count > startingLength)
            {
                ShrinkSnake();
                PlayerNetworkController parentScript = this.transform.parent.GetComponent <PlayerNetworkController>();
                parentScript.ZoomCamera(-1.0f);
                //ZoomCamera(-1.0f);
                lengthText.text = "Length: " + tail.Count.ToString();
            }
            else
            {
                break;
            }
        }
        StopCoroutine(DropTailLinks());
    }
    ////////////////////////////
    // Unity Built-in Methods //
    ////////////////////////////

    // Initialization
    public virtual void Start()
    {
        particles        = GameAttributes.camera.GetComponentInChildren <ParticleSystem>();
        body             = GetComponent <Rigidbody>();
        playerAttributes = GetComponent <PlayerAttributes>();

        // Additional setup only for main player
        if (playerAttributes.mainPlayer || playerAttributes.zombiePlayer)
        {
            playerNetworkController = GameObject.Find("Network").GetComponent <PlayerNetworkController>();

            // Set up direction and state monitoring
            InvokeRepeating("UpdateAndSendPlayerDirection", 0f, 0.2f);
            InvokeRepeating("SendMainPlayerState", 0f, 0.2f);

            // Set up for computer controlled main player
            if (GameAttributes.computerControlledMainPlayer || playerAttributes.zombiePlayer)
            {
                InvokeRepeating("UpdateComputerControlledDirection", 2.5f, 5f);
            }
        }
        NetworkController.OnReady(delegate() {
            RaycastHit hit = new RaycastHit();
            if (Physics.Raycast(transform.position, Vector3.down, out hit))
            {
                transform.position -= new Vector3(0, hit.distance - 10, 0);
            }
        });

        NetworkController.OnReady(delegate() {
            GetComponent <Rigidbody>().useGravity = true;
        });

        if (gameObject == GameAttributes.mainPlayer)
        {
            SetupBoost();
        }
    }
    //What to do when message is received from host
    private void OnIncomingData(string data)
    {
        string[] dataInfo = data.Split('/');

        if (dataInfo[0] == "animator")
        {
            NetworkAnimator(dataInfo[1],
                            float.Parse(dataInfo[2]),
                            float.Parse(dataInfo[3]),
                            float.Parse(dataInfo[4]),
                            bool.Parse(dataInfo[5]),
                            bool.Parse(dataInfo[6]),
                            new Vector3(float.Parse(dataInfo[7]), float.Parse(dataInfo[8]), float.Parse(dataInfo[9])),
                            new Vector3(float.Parse(dataInfo[10]), float.Parse(dataInfo[11]), float.Parse(dataInfo[12])),
                            dataInfo[13],
                            bool.Parse(dataInfo[14]));
        }
        else if (dataInfo[0] == "state")
        {
            int curState = int.Parse(dataInfo[1]);
            switch (curState)
            {
            case 1:
                match.setState(curState);
                match.setHidingElapsedTime(int.Parse(dataInfo[2]));
                break;

            case 2:
                match.setState(curState);
                match.setSeekingElapsedTime(int.Parse(dataInfo[2]));
                break;

            case 3:
                match.setState(curState);
                match.setMatchElapsedTime(int.Parse(dataInfo[2]));
                match.setZoneCenter(new Vector3(float.Parse(dataInfo[3]), float.Parse(dataInfo[4]), float.Parse(dataInfo[5])));
                match.setZoneScale(new Vector3(float.Parse(dataInfo[6]), float.Parse(dataInfo[7]), float.Parse(dataInfo[8])));
                break;

            case 4:
                match.setState(curState);
                match.setScoreboardElapsedTime(int.Parse(dataInfo[2]));
                break;

            case 5:
                goto case 1;

            case 6:
                goto case 2;

            case 7:
                goto case 3;

            case 8:
                goto case 4;
            }
        }
        else if (dataInfo[0] == "start")
        {
            match       = new MatchOrchestrator();
            isHider     = bool.Parse(dataInfo[1]);
            gameStarted = true;
        }
        else if (dataInfo[0] == "caught")
        {
            if (dataInfo[1].Equals(guestName))
            {
                isCaught = true;
            }
            else
            {
                foreach (PlayerNetworkController p in players)
                {
                    if (p.getGuestName().Equals(dataInfo[1]))
                    {
                        p.setIsCaught(true);
                        removedPlayersQueue.Add(p.getGuestName());
                        break;
                    }
                }
            }
        }
        else if (dataInfo[0] == "stop")
        {
            endGameFlag = true;
            match.stop();
            match       = null;
            gameStarted = false;
        }
        else
        {
            newHost = dataInfo[0];

            List <string> guestNames = new List <string>();
            for (int i = 1; i < dataInfo.Length; i++)
            {
                string[] playerInfo = dataInfo[i].Split('\\');

                if (guestName.Equals(playerInfo[0]))
                {
                    score = int.Parse(playerInfo[1]);
                    continue;
                }

                guestNames.Add(playerInfo[0]);
                if (players.Count == 0)
                {
                    PlayerNetworkController playerNC = new PlayerNetworkController(playerInfo[0], int.Parse(playerInfo[1]));
                    players.Add(playerNC);
                    Debug.Log(playerInfo[0] + " joined");
                    continue;
                }

                for (int j = 0; j < players.Count; j++)
                {
                    if (players[j].getGuestName().Equals(playerInfo[0]))
                    {
                        players[j].setScore(int.Parse(playerInfo[1]));
                        goto skipAdd;
                    }
                }
                PlayerNetworkController playernc = new PlayerNetworkController(playerInfo[0], int.Parse(playerInfo[1]));
                players.Add(playernc);
                Debug.Log(playerInfo[0] + " joined");
                skipAdd :;
            }
            updatePlayers(guestNames);
        }
    }