Ejemplo n.º 1
0
    void CheckFireGun()
    {   //for now, it defaults to bouncy. Later should add capability for multiple shot types.
        if (Input.GetKey(FireButton) && CanFire())
        {
            Quaternion qt;
            Vector3    pos;

            if (BulletSpawnLoc != null)
            {
                qt  = BulletSpawnLoc.transform.rotation;
                pos = BulletSpawnLoc.transform.position;
            }
            else
            {
                qt  = new Quaternion();
                pos = Vector3.zero;
            }

            CreateProjectileMsg msg = new CreateProjectileMsg(true, Time.frameCount, OwningTank.GetComponent <TankBody>().GetTankID(),
                                                              ShotType.Bouncy,
                                                              pos, qt);
            OwningGame.BroadcastMessage("CreateProjectile", msg, GameUtilities.DONT_CARE_RECIEVER);
            FrameFired = Time.frameCount;
        }
    }
Ejemplo n.º 2
0
    void AttackMaxAggroPlayer()
    {   //Attack the max aggro player, if their aggro is greater than 3 (MAGIC NUMBER)
        GameObject MaxAggroPlayer = FindMaxAggroPlayer();

        if (MaxAggroPlayer == null)
        {
            return;
        }

        transform.LookAt(MaxAggroPlayer.transform);
        if (CanFire())
        {
            Quaternion qt;
            Vector3    pos;

            if (BulletSpawnLoc != null)
            {
                qt  = BulletSpawnLoc.transform.rotation;
                pos = BulletSpawnLoc.transform.position;
            }
            else
            {
                qt  = new Quaternion();
                pos = Vector3.zero;
            }

            CreateProjectileMsg msg = new CreateProjectileMsg(false, Time.frameCount, GameUtilities.INVALID_TANK_ID,
                                                              ShotType.Bouncy,
                                                              pos, qt);
            OwningGame.BroadcastMessage("CreateProjectile", msg, GameUtilities.DONT_CARE_RECIEVER);
            FrameFired = Time.frameCount;
        }
    }
Ejemplo n.º 3
0
    void CreateProjectile(CreateProjectileMsg msg)
    {
        Quaternion qt = new Quaternion(msg.xQuat, msg.yQuat, msg.zQuat, msg.wQuat);
        Vector3    pos;

        pos.x = msg.xPos;
        pos.y = msg.yPos;
        pos.z = msg.zPos;

        var wb = (GameObject)Instantiate(WonkyBullet, pos, qt);

        wb.GetComponent <WB> ().PlayerFriendly = msg.PlayerFriendly;

        Color color = new Color();

        if (!msg.PlayerFriendly)
        {
            wb.GetComponent <WB> ().Damage = 10f;           //MAGIC NUMBER
            color.r = 255;
            color.g = 0;
            color.b = 0;
        }
        else
        {
            wb.GetComponent <WB> ().Damage = 10f;           //MAGIC NUMBER
            color.r = 255;
            color.g = 150;
            color.b = 0;
        }

        wb.GetComponent <MeshRenderer> ().material.color = color;
        wb.GetComponent <WB> ().NoCollisions             = 0;
        wb.GetComponent <WB> ().CreatingPLayer           = msg.TankID;

        // Add velocity to the bullet
        wb.GetComponent <Rigidbody>().velocity = wb.transform.forward * VelocityCoeff;

        // Destroy the bullet after 2 seconds
        if (!msg.PlayerFriendly)
        {
            Destroy(wb, BulletLifeSpanScalar * 1);
        }
        else
        {
            Destroy(wb, BulletLifeSpanScalar * 0.75f);
        }
    }
Ejemplo n.º 4
0
 void CreateProjectile(CreateProjectileMsg msg)
 {
     if (!msg.External)
     {
         string DeconMsg =
             CreateProjectileID
             + "," + msg.PlayerFriendly
             + "," + msg.FrameNo
             + "," + msg.TankID
             + "," + ((int)msg.TypeFired)
             + "," + msg.xPos
             + "," + msg.yPos
             + "," + msg.zPos
             + "," + msg.xQuat
             + "," + msg.yQuat
             + "," + msg.zQuat
             + "," + msg.wQuat;
         WebsockAdaptorSend(DeconMsg);
     }
 }
Ejemplo n.º 5
0
    static CreateProjectileMsg ReconstructCreateProjectileMsg(string message)
    {
        string[]            parts = message.Split(new char[] { ',' });
        CreateProjectileMsg msg   = new CreateProjectileMsg();

        msg.External       = true;
        msg.PlayerFriendly = bool.Parse(parts[0]);
        msg.FrameNo        = int.Parse(parts[1]);
        msg.TankID         = byte.Parse(parts[2]);
        int TF = int.Parse(parts[3]);

        msg.TypeFired = (ShotType)TF;

        msg.xPos = float.Parse(parts[4]);
        msg.yPos = float.Parse(parts[5]);
        msg.zPos = float.Parse(parts[6]);

        msg.xQuat = float.Parse(parts[7]);
        msg.yQuat = float.Parse(parts[8]);
        msg.zQuat = float.Parse(parts[9]);
        msg.wQuat = float.Parse(parts[10]);

        return(msg);
    }