Example #1
0
    void Fire()
    {
        if (!hit)
        {
            return;
        }

        Player otherPlayer = hitInfo.transform.GetComponent <Player>();

        if (otherPlayer == null)
        {
            return;
        }

        ParticleSystem hitParticles = laserTarget.GetComponent <ParticleSystem>();

        hitParticles.Play();

        PlayerHealthPackage ps = new PlayerHealthPackage();

        ps.PlayerIP = otherPlayer.PlayerIP;
        ps.Value    = Options.HitDamage;
        ps.Hit      = true;
        NetworkManager.Instance.Client.SendData(ps);
    }
Example #2
0
    void Update()
    {
        if (IsDead && IsControlled)
        {
            transform.root.position = new Vector3(0, 0, 0);

            if (respawnTimer > 0)
            {
                respawnTimer -= Time.deltaTime;
            }
            else if (respawnTimer <= 0)
            {
                respawnTimer = 0;

                Health = 100;

                PlayerSpawnPackage psp = new PlayerSpawnPackage();
                NetworkManager.Instance.Client.SendData(psp);
            }
        }

        if (IsControlled)
        {
            if (transform.root.position.y < -50)
            {
                PlayerHealthPackage ps = new PlayerHealthPackage();
                ps.PlayerIP = PlayerIP;
                ps.Value    = -Health;
                ps.Hit      = true;
                NetworkManager.Instance.Client.SendData(ps);
            }
        }

        //direction is (pointB - pointA).normalized
        Vector3 start = calculateCentroid(eyesL.position, eyesR.position);
        Ray     r     = new Ray(start, (laserTarget.position - start).normalized);

        hit = Physics.Raycast(r, out hitInfo, Options.LaserTargetDistance);
        if (hit)
        {
            laserTarget.localPosition = new Vector3(laserTarget.localPosition.x, laserTarget.localPosition.y, hitInfo.distance);
        }
        else
        {
            laserTarget.localPosition = new Vector3(laserTarget.localPosition.x, laserTarget.localPosition.y, Options.LaserTargetDistance);
        }

        if (AlwaysFireLaserBeams)
        {
            SetLasersEnabled(true);
        }

        if (gangnamObject != null)
        {
            gangnamObject.transform.position = this.gameObject.transform.position;
            gangnamObject.transform.rotation = this.gameObject.transform.rotation;
        }
    }
        public override DataPackage CreateFromBody(string b)
        {
            string[] split = b.Split('|');

            PlayerHealthPackage fp = new PlayerHealthPackage();
            fp.PlayerIP = IPAddress.Parse(split[0]);
            fp.Value = int.Parse(split[1]);
            fp.Hit = bool.Parse(split[2]);
            return fp;
        }
Example #4
0
        public override DataPackage CreateFromBody(string b)
        {
            string[] split = b.Split('|');

            PlayerHealthPackage fp = new PlayerHealthPackage();

            fp.PlayerIP = IPAddress.Parse(split[0]);
            fp.Value    = int.Parse(split[1]);
            fp.Hit      = bool.Parse(split[2]);
            return(fp);
        }
Example #5
0
    public void OnDataReceived(DataPackage dp)
    {
        if (dp is TokenChangePackage)
        {
            if (sendCounter == 1)
            {
                resend      = true;
                sendCounter = 0;
            }
            else
            {
                sendCounter++;
            }
        }
        else if (dp is PlayerMovePackage && dp.SenderRemoteIPEndpoint.Address.Equals(PlayerIP))
        {
            PlayerMovePackage pmp = (PlayerMovePackage)dp;

            if (!pmp.RotationOnly)
            {
                //set position
                transform.root.position = pmp.Position;

                //set rotation
                float newRotX = pmp.Rotation.x - transform.root.rotation.eulerAngles.x;
                float newRotY = pmp.Rotation.y - transform.root.rotation.eulerAngles.y;
                float newRotZ = pmp.Rotation.z - transform.root.rotation.eulerAngles.z;
                transform.root.Rotate(newRotX, newRotY, newRotZ);

                //set direction
                if (pmp.Dir.Has(PlayerMovePackage.Direction.Stop))
                {
                    anim.SetFloat("Speed", 0);
                }
                if (pmp.Dir.Has(PlayerMovePackage.Direction.Up))
                {
                    anim.SetFloat("Speed", 1);
                }
                if (pmp.Dir.Has(PlayerMovePackage.Direction.Back))
                {
                    anim.SetFloat("Speed", -1);
                }

                if (pmp.Dir == PlayerMovePackage.Direction.Stop)
                {
                    setGangnamVisible(true);
                }
                else
                {
                    setGangnamVisible(false);
                }

                anim.speed = animSpeed;

                //float h = Input.GetAxis("Horizontal");				// setup h variable as our horizontal input axis
                //float v = Input.GetAxis("Vertical");				// setup v variables as our vertical input axis
                //print(h + " | " + v);
                //anim.SetFloat("Speed", v);							// set our animator's float parameter 'Speed' equal to the vertical input axis
                //anim.SetFloat("Direction", h);                        // set our animator's float parameter 'Direction' equal to the horizontal input axis
                //anim.speed = animSpeed;								// set the speed of our animator to the public variable 'animSpeed'
                //anim.SetLookAtWeight(lookWeight);					// set the Look At Weight - amount to use look at IK vs using the head's animation	}
            }
            else if (!IsControlled)
            {
                //set rotation
                float newRotX = pmp.Rotation.x - transform.root.rotation.eulerAngles.x;
                float newRotY = pmp.Rotation.y - transform.root.rotation.eulerAngles.y;
                float newRotZ = pmp.Rotation.z - transform.root.rotation.eulerAngles.z;
                transform.root.Rotate(newRotX, newRotY, newRotZ);
            }
        }
        else if (dp is FlagPackage && dp.SenderRemoteIPEndpoint.Address.Equals(PlayerIP))
        {
            FlagPackage fp = (FlagPackage)dp;
            if (fp.Event == FlagPackage.FlagEvent.Capture)
            {
                Score += 3;
            }
            else if (fp.Event == FlagPackage.FlagEvent.Drop)
            {
                Score--;
            }
        }
        else if (dp is FireWeaponPackage && dp.SenderRemoteIPEndpoint.Address.Equals(PlayerIP))
        {
            FireWeaponPackage fwp = (FireWeaponPackage)dp;

            //Set laser target
            Camera c       = GetComponentInChildren <Camera>();
            float  newRotX = fwp.Target - c.transform.rotation.eulerAngles.x;
            c.transform.Rotate(newRotX, 0, 0);

            startFiringPackageSent = false;
            stopFiringPackageSent  = false;
            firing    = fwp.Enabled;
            fireTimer = 0;
        }
        else if (dp is PlayerHealthPackage)
        {
            PlayerHealthPackage php = (PlayerHealthPackage)dp;
            if (!php.PlayerIP.Equals(PlayerIP))
            {
                return;
            }

            Health -= php.Value;

            if (IsDead)
            {
                Health = 0;
                Die();
            }
        }
        else if (dp is PlayerSpawnPackage && dp.SenderRemoteIPEndpoint.Address.Equals(PlayerIP))
        {
            setRobotVisible(true);
            setGangnamVisible(true);

            Health = 100;

            if (IsControlled)
            {
                GameManager.Instance.spawnRobot(PlayerIP);
            }
        }
    }
Example #6
0
    void Update()
    {
        if (IsDead && IsControlled)
        {
            transform.root.position = new Vector3(0, 0, 0);

            if (respawnTimer > 0)
                respawnTimer -= Time.deltaTime;
            else if (respawnTimer <= 0)
            {
                respawnTimer = 0;

                Health = 100;

                PlayerSpawnPackage psp = new PlayerSpawnPackage();
                NetworkManager.Instance.Client.SendData(psp);
            }
        }

        if (IsControlled)
        {
            if (transform.root.position.y < -50)
            {
                PlayerHealthPackage ps = new PlayerHealthPackage();
                ps.PlayerIP = PlayerIP;
                ps.Value = -Health;
                ps.Hit = true;
                NetworkManager.Instance.Client.SendData(ps);
            }
        }

        //direction is (pointB - pointA).normalized
        Vector3 start = calculateCentroid(eyesL.position, eyesR.position);
        Ray r = new Ray(start, (laserTarget.position - start).normalized);
        hit = Physics.Raycast(r, out hitInfo, Options.LaserTargetDistance);
        if(hit)
            laserTarget.localPosition = new Vector3(laserTarget.localPosition.x, laserTarget.localPosition.y, hitInfo.distance);
        else
            laserTarget.localPosition = new Vector3(laserTarget.localPosition.x, laserTarget.localPosition.y, Options.LaserTargetDistance);

        if(AlwaysFireLaserBeams)
            SetLasersEnabled(true);

        if (gangnamObject != null)
        {
            gangnamObject.transform.position = this.gameObject.transform.position;
            gangnamObject.transform.rotation = this.gameObject.transform.rotation;
        }
    }
Example #7
0
    void Fire()
    {
        if (!hit)
            return;

        Player otherPlayer = hitInfo.transform.GetComponent<Player>();
        if(otherPlayer == null)
            return;

        ParticleSystem hitParticles = laserTarget.GetComponent<ParticleSystem>();
        hitParticles.Play();

        PlayerHealthPackage ps = new PlayerHealthPackage();
        ps.PlayerIP = otherPlayer.PlayerIP;
        ps.Value = Options.HitDamage;
        ps.Hit = true;
        NetworkManager.Instance.Client.SendData(ps);
    }