Exemplo n.º 1
0
    private void OnTriggerEnter(Collider col)
    {
        BulletCollision bc           = this.GetComponentInParent <BulletCollision>();
        ShipHandling    shipHandling = null;

        if (col.transform.parent != null)
        {
            if (col.transform.parent.GetComponent <ShipHandling>() != null)
            {
                shipHandling = col.transform.parent.GetComponent <ShipHandling>();
            }
        }
        //Debug.Log("OnTriggerEnter!! " + col.gameObject.tag + " " +  bc.bulletOwnerPlayerNumber + " " + shipHandling.playerNumber + " " + bc.isMine);

        if (shipHandling != null)
        {
            // Check for own deployed mines first
            if (col.transform.parent.tag == "CameraObject" && bc.isMine == true && bc.bulletOwnerPlayerNumber == shipHandling.playerNumber)
            {
                // Do nothing
            }
            else if (col.transform.tag == "Bullet")
            {
                // Do nothing
            }
            else
            {
                if (col.transform.parent.tag == "CameraObject")
                {
                    StartCoroutine(ExplodeMine(shipHandling, bc, activationDelay));
                }
            }
        }
    }
Exemplo n.º 2
0
    //Ship31 Secondary
    public void Ship31Secondary()
    {
        List <Transform> bulletSpecialSpawnPoints = new List <Transform>();
        int i = 0;

        foreach (Transform child in transform)
        {
            if (child.CompareTag("BulletSpawn") && child.name.Contains("BulletSpawnPointSecondary"))
            {
                bulletSpecialSpawnPoints.Add(child.transform);
                i++;
            }
        }

        ShipHandling shipHandling = this.GetComponentInParent <ShipHandling>();
        ShipDetails  shipDetails  = shipHandling.shipDetails;


        if (shipHandling.currentBattery >= shipDetails.Secondary.BatteryCharge)
        {
            List <Transform> usedSpawnPoints = new List <Transform>();

            usedSpawnPoints = bulletSpecialSpawnPoints;



            foreach (Transform currBulletSpawnPoint in usedSpawnPoints)
            {
                GameObject bullet = (GameObject)Instantiate(
                    shipDetails.Secondary.SecondaryPrefab,
                    currBulletSpawnPoint.position,
                    currBulletSpawnPoint.rotation);
                bullet.GetComponent <BulletCollision>().bulletOwnerPlayerNumber = shipHandling.playerNumber;
                Transform transform = bullet.GetComponentInChildren <Transform>();
                transform.localScale = new Vector3(shipDetails.Secondary.Scale, shipDetails.Secondary.Scale, shipDetails.Secondary.Scale);
                bullet.GetComponent <BulletCollision>().bulletHitPoints = shipDetails.Secondary.HitPoints;
                bullet.gameObject.tag = "Bullet";

                // Add velocity to the bullet
                bullet.GetComponent <Rigidbody>().velocity = bullet.transform.forward * shipDetails.Secondary.Speed;

                BulletCollision bulletCol = bullet.GetComponentInChildren <BulletCollision>();

                bulletCol.setDamage(shipDetails.Secondary.Damage);

                createdBullets.Add(bullet);

                // Destroy the bullet after X seconds
                Destroy(bullet, shipDetails.Secondary.TimeToLive);

                CheckForMaxInstances();
            }


            shipHandling.currentBattery    = shipHandling.currentBattery - shipDetails.Secondary.BatteryCharge;
            shipHandling.lastSecondaryUsed = Time.time;
        }
    }
Exemplo n.º 3
0
    public void Ship63Secondary()
    {
        ShipHandling shipHandling = this.GetComponentInParent <ShipHandling>();
        ShipDetails  shipDetails  = shipHandling.shipDetails;

        if (shipHandling.currentBattery >= shipDetails.Secondary.BatteryCharge)
        {
            DeployMine();
        }
    }
Exemplo n.º 4
0
    private void GenericPrimaryShoot()
    {
        ShipHandling shipHandling = this.GetComponentInParent <ShipHandling>();
        ShipDetails  shipDetails  = shipHandling.shipDetails;
        float        usedFireRate = shipDetails.Primary.FireRate;


        if (Time.time > usedFireRate + shipHandling.lastShot)
        {
            if (shipHandling.currentBattery >= shipDetails.Primary.BatteryCharge)
            {
                List <Transform> usedSpawnPoints = new List <Transform>();

                usedSpawnPoints = bulletSpawnPoints;

                foreach (Transform currBulletSpawnPoint in usedSpawnPoints)
                {
                    GameObject bullet = (GameObject)Instantiate(
                        shipDetails.Primary.bulletPrefab,
                        currBulletSpawnPoint.position,
                        currBulletSpawnPoint.rotation);
                    bullet.transform.parent = gameObject.transform;
                    bullet.GetComponent <BulletCollision>().bulletOwnerPlayerNumber = shipHandling.playerNumber;
                    bullet.GetComponent <BulletCollision>().bulletHitPoints         = shipDetails.Primary.HitPoints;
                    bullet.gameObject.tag = "Bullet";

                    Transform transform = bullet.GetComponentInChildren <Transform>();
                    transform.localScale = new Vector3(shipDetails.Primary.Scale, shipDetails.Primary.Scale, shipDetails.Primary.Scale);


                    // Add velocity to the bullet
                    bullet.GetComponent <Rigidbody>().velocity = bullet.transform.forward * shipDetails.Primary.Speed;

                    BulletCollision bulletCol = bullet.GetComponentInChildren <BulletCollision>(); //transform.Find("BulletCollision");
                                                                                                   //ScriptB other = (ScriptB)go.GetComponent(typeof(ScriptB));
                    bulletCol.setDamage(shipDetails.Primary.Damage);

                    createdBullets.Add(bullet);

                    // Destroy the bullet after X seconds
                    Destroy(bullet, shipDetails.Primary.TimeToLive);

                    CheckForMaxInstances();
                }

                shipHandling.currentBattery = shipHandling.currentBattery - shipDetails.Primary.BatteryCharge;
                shipHandling.lastShot       = Time.time;
            }
        }
    }
Exemplo n.º 5
0
    IEnumerator ExplodeMine(ShipHandling shipHandling, BulletCollision bc, float waitForSeconds = 0)
    {
        yield return(new WaitForSeconds(waitForSeconds));

        Collider[]          hitColliders = Physics.OverlapSphere(transform.position, radius);
        List <ShipHandling> shipsInArea  = new List <ShipHandling>();
        int i = 0;

        while (i < hitColliders.Length)
        {
            //Debug.Log(hitColliders[i].GetType() + " " + hitColliders[i].transform.parent.tag);

            if (hitColliders[i].transform.parent != null && hitColliders[i].transform.parent.tag == "CameraObject")
            {
                if (shipsInArea.IndexOf(hitColliders[i].transform.GetComponent <ShipHandling>()) < 0)
                {
                    shipsInArea.Add(hitColliders[i].transform.GetComponent <ShipHandling>());
                    //hitColliders[i].transform.GetComponent<Renderer>().GetComponent<Material>().color = Color.yellow;
                }
            }
            i++;
        }

        //Debug.Log("shipsInArea = "+shipsInArea.Count);

        //Do the damage to all players in the area
        i = 0;
        foreach (ShipHandling currShipHandling in shipsInArea)
        {
            bool shipDestroyed = shipHandling.DoDamage(bc.damage);
            if (shipDestroyed == true)
            {
                GameObject playerStats = GameObject.FindGameObjectWithTag("Player1Stats");

                // Don't add points if killed by itself!
                if (bc.bulletOwnerPlayerNumber != shipHandling.playerNumber)
                {
                    playerStats.GetComponent <UpdatePlayerStats>().playerScores[(int)bc.bulletOwnerPlayerNumber - 1]++;
                }
            }
        }

        // Do the big explosion
        GameObject explosion = Instantiate(bc.explosionPrefabBig, transform.position, Quaternion.identity);

        Destroy(explosion, 3.0f);
        Destroy(this.gameObject);
        Destroy(transform.parent.gameObject);
    }
Exemplo n.º 6
0
    private void CheckForMaxInstances()
    {
        ShipHandling shipHandling = this.GetComponentInParent <ShipHandling>();
        ShipDetails  shipDetails  = shipHandling.shipDetails;

        if (createdBullets.Count > shipDetails.Primary.MaxInstances)
        {
            for (int i = (createdBullets.Count - shipDetails.Primary.MaxInstances); i > 0; i--)
            {
                GameObject oldestBullet = createdBullets[0];
                Destroy(oldestBullet);
                createdBullets.RemoveAt(0);
            }
        }
    }
Exemplo n.º 7
0
    public void DeployMine()
    {
        List <Transform> bulletSpecialSpawnPoints = new List <Transform>();
        int i = 0;

        foreach (Transform child in transform)
        {
            if (child.CompareTag("BulletSpawn") && child.name.Contains("BulletSpawnPointSecondary"))
            {
                bulletSpecialSpawnPoints.Add(child.transform);
                i++;
            }
        }

        ShipHandling shipHandling = this.GetComponentInParent <ShipHandling>();
        ShipDetails  shipDetails  = shipHandling.shipDetails;


        foreach (Transform currBulletSpawnPoint in bulletSpecialSpawnPoints)
        {
            GameObject bullet = (GameObject)Instantiate(
                shipDetails.Secondary.SecondaryPrefab,
                currBulletSpawnPoint.position,
                currBulletSpawnPoint.rotation);
            bullet.GetComponent <BulletCollision>().bulletOwnerPlayerNumber = shipHandling.playerNumber;
            Transform transform = bullet.GetComponentInChildren <Transform>();
            transform.localScale = new Vector3(shipDetails.Secondary.Scale, shipDetails.Secondary.Scale, shipDetails.Secondary.Scale);
            bullet.GetComponent <BulletCollision>().bulletHitPoints = shipDetails.Secondary.HitPoints;
            bullet.gameObject.tag = "Bullet";
            bullet.GetComponent <BulletCollision>().isMine = true;
            bullet.transform.SetPositionAndRotation(currBulletSpawnPoint.position, Quaternion.identity);

            BulletCollision bulletCol = bullet.GetComponentInChildren <BulletCollision>();

            bulletCol.setDamage(shipDetails.Secondary.Damage);
            createdBullets.Add(bullet);

            Destroy(bullet, shipDetails.Secondary.TimeToLive);

            CheckForMaxInstances();
        }

        shipHandling.currentBattery    = shipHandling.currentBattery - shipDetails.Secondary.BatteryCharge;
        shipHandling.lastSecondaryUsed = Time.time;
    }
Exemplo n.º 8
0
    public void Ship17Primary()
    {
        ShipHandling shipHandling = this.GetComponentInParent <ShipHandling>();
        ShipDetails  shipDetails  = shipHandling.shipDetails;
        float        usedFireRate = shipDetails.Primary.FireRate;

        if (Time.time > usedFireRate + shipHandling.lastShot)
        {
            if (shipHandling.currentBattery >= shipDetails.Primary.BatteryCharge)
            {
                Ship17LaserActive = true;
                // The laser drawing is done in Update...
                Ship17LaserDurationLeft     = Ship17LaserDuration;
                shipHandling.currentBattery = shipHandling.currentBattery - shipDetails.Primary.BatteryCharge;
                shipHandling.lastShot       = Time.time;
            }
        }
    }
Exemplo n.º 9
0
    public void Ship47Secondary()
    {
        ShipHandling shipHandling = this.GetComponentInParent <ShipHandling>();
        ShipDetails  shipDetails  = shipHandling.shipDetails;



        if (shipHandling.currentBattery >= shipDetails.Secondary.BatteryCharge && Ship47SecondaryActive == false)
        {
            Ship47SecondaryActive        = true;
            shipHandling.currentBattery -= shipDetails.Secondary.BatteryCharge;

            AudioClip Woosh = shipDetails.Secondary.SecondarySound;
            //Debug.Log("Woosh is " + Woosh.ToString());
            //Debug.Log("source47 is " + source47.ToString());

            source47.PlayOneShot(Woosh);
        }
    }
Exemplo n.º 10
0
    private void AssignJoysticks()
    {
        shipHandling = GetComponent <ShipHandling>();
        playerNumber = (int)shipHandling.playerNumber;
        turnControl  = "Horizontal" + playerNumber;
        //thrustControl = "Vertical" + playerNumber;
        primaryControl = "Primary" + playerNumber;
        //secondaryControl = "Secondary" + (playerNumber);
        joystick = null;

        InputDevice[]      joysticks      = new InputDevice[InputManager.Devices.Count];
        List <InputDevice> finalJoysticks = new List <InputDevice>();

        InputManager.Devices.CopyTo(joysticks, 0);

        for (int i = 0; i < joysticks.Length; i++)
        {
            if (joysticks[i].Name.Equals("PlayStation 4 Controller") == false)
            {
                //Debug.Log("Device type is " + joysticks[i].Name + ", joystick number is " + i + ", playerNumber is " + playerNumber);
                finalJoysticks.Add(joysticks[i]);
            }
        }

        //Debug.Log("finalJoysticks.Count " + finalJoysticks.Count);
        if (finalJoysticks.Count > (playerNumber - 1))
        {
            //Debug.Log("Assigning joystick to player " + playerNumber);
            joystick = finalJoysticks[(playerNumber - 1)];
        }
        else
        {
            //Debug.Log("Joystick for player " + playerNumber + " is NULL");
            joystick = null;
        }
    }
Exemplo n.º 11
0
    void OnCollisionEnter(Collision col)
    {
        ShipHandling shipHandling = col.gameObject.GetComponent <ShipHandling>();

        //Debug.Log("OnCollisionEnter");

        // Check for own deployed mines first
        if (col.gameObject.tag == "CameraObject" && isMine == true && bulletOwnerPlayerNumber == shipHandling.playerNumber)
        {
            // Do nothing, just push it on collision.
        }
        else
        {
            if (col.gameObject.tag == "CameraObject")
            {
                bool       shipDestroyed = shipHandling.DoDamage(damage);
                GameObject explosion;

                if (isMine)
                {
                    explosion = Instantiate(explosionPrefabBig, transform.position, Quaternion.identity);
                }
                else
                {
                    explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                }

                //GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                Destroy(explosion, 3.0f);
                Destroy(this.gameObject);

                if (shipDestroyed == true)
                {
                    GameObject playerStats = GameObject.FindGameObjectWithTag("Player1Stats");
                    //Debug.Log("Killer was " + bulletOwnerPlayerNumber);

                    // Don't add points if killed by itself!
                    if (bulletOwnerPlayerNumber != shipHandling.playerNumber)
                    {
                        playerStats.GetComponent <UpdatePlayerStats>().playerScores[(int)bulletOwnerPlayerNumber - 1]++;
                    }
                }
            }
            else if (col.gameObject.tag == "Bullet")
            {
                //Debug.Log("Bullet Collision!!");
                GameObject explosion;


                // Exchange damage
                bulletHitPoints = bulletHitPoints - col.transform.GetComponent <BulletCollision>().damage;
                col.transform.GetComponent <BulletCollision>().bulletHitPoints = col.transform.GetComponent <BulletCollision>().bulletHitPoints - damage;

                //Debug.Log("Bullet hitpoints after collision: " + bulletHitPoints + " and " + col.transform.GetComponent<BulletCollision>().bulletHitPoints);

                // Check for casualties
                if (bulletHitPoints <= 0)
                {
                    if (isMine)
                    {
                        explosion = Instantiate(explosionPrefabBig, transform.position, Quaternion.identity);
                    }
                    else
                    {
                        explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                    }

                    Destroy(explosion, 3.0f);
                    Destroy(this.gameObject);
                }
                if (col.transform.GetComponent <BulletCollision>().bulletHitPoints <= 0)
                {
                    if (col.transform.GetComponent <BulletCollision>().isMine)
                    {
                        explosion = Instantiate(explosionPrefabBig, transform.position, Quaternion.identity);
                    }
                    else
                    {
                        explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                    }

                    Destroy(explosion, 3.0f);
                    Destroy(col.gameObject);
                }
            }
            else
            {
                // On any other object, just destroy the bullet
                GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                Destroy(explosion, 3.0f);
                Destroy(this.gameObject);
            }
        }
    }
Exemplo n.º 12
0
    //Ship17 Secondary
    public void Ship17Secondary()
    {
        // Give speed boost to ship
        ShipHandling shipHandling = this.GetComponentInParent <ShipHandling>();
        ShipDetails  shipDetails  = shipHandling.shipDetails;
        Rigidbody    rb           = GetComponent <Rigidbody>();

        if (shipHandling.currentBattery >= shipDetails.Secondary.BatteryCharge)
        {
            rb.AddForce((transform.right * 1000));

            shipHandling.currentBattery    = shipHandling.currentBattery - shipDetails.Secondary.BatteryCharge;
            shipHandling.lastSecondaryUsed = Time.time;
        }

        /*
         * List<Transform> bulletSpecialSpawnPoints = new List<Transform>();
         * int i = 0;
         * foreach (Transform child in transform)
         * {
         *  if (child.CompareTag("BulletSpawn") && child.name.Contains("BulletSpawnPointSecondary"))
         *  {
         *      bulletSpecialSpawnPoints.Add(child.transform);
         *      i++;
         *  }
         * }
         *
         * ShipHandling shipHandling = this.GetComponentInParent<ShipHandling>();
         * ShipDetails shipDetails = shipHandling.shipDetails;
         *
         *
         * if (shipHandling.currentBattery >= shipDetails.Secondary.BatteryCharge)
         * {
         *  List<Transform> usedSpawnPoints = new List<Transform>();
         *
         *  usedSpawnPoints = bulletSpecialSpawnPoints;
         *
         *
         *
         *  foreach (Transform currBulletSpawnPoint in usedSpawnPoints)
         *  {
         *      GameObject bullet = (GameObject)Instantiate(
         *      shipDetails.Secondary.SecondaryPrefab,
         *      currBulletSpawnPoint.position,
         *      currBulletSpawnPoint.rotation);
         *      bullet.GetComponent<BulletCollision>().bulletOwnerPlayerNumber = shipHandling.playerNumber;
         *      Transform transform = bullet.GetComponentInChildren<Transform>();
         *      transform.localScale = new Vector3(shipDetails.Secondary.Scale, shipDetails.Secondary.Scale, shipDetails.Secondary.Scale);
         *      bullet.GetComponent<BulletCollision>().bulletHitPoints = shipDetails.Secondary.HitPoints;
         *      bullet.gameObject.tag = "Bullet";
         *
         *      // Add velocity to the bullet
         *      bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * shipDetails.Secondary.Speed;
         *
         *      BulletCollision bulletCol = bullet.GetComponentInChildren<BulletCollision>();
         *
         *      bulletCol.setDamage(shipDetails.Secondary.Damage);
         *
         *      createdBullets.Add(bullet);
         *
         *      // Destroy the bullet after X seconds
         *      Destroy(bullet, shipDetails.Secondary.TimeToLive);
         *
         *      CheckForMaxInstances();
         *  }
         *
         *
         *  shipHandling.currentBattery = shipHandling.currentBattery - shipDetails.Secondary.BatteryCharge;
         *
         *
         *
         *  shipHandling.lastSecondaryUsed = Time.time;
         * }
         *
         */
    }
Exemplo n.º 13
0
    public void RedrawShip17Primary()
    {
        ShipHandling shipHandling      = this.GetComponentInParent <ShipHandling>();
        LineRenderer laserBeamRenderer = this.GetComponentInChildren <LineRenderer>();
        ShipDetails  shipDetails       = shipHandling.shipDetails;

        List <Transform> bulletPrimarySpawnPoints = new List <Transform>();
        int i = 0;

        foreach (Transform child in transform)
        {
            if (child.CompareTag("BulletSpawn") && child.name.Contains("BulletSpawnPointPrimary1"))
            {
                bulletPrimarySpawnPoints.Add(child.transform);
                i++;
            }
        }

        List <Transform> usedSpawnPoints = new List <Transform>();

        usedSpawnPoints = bulletPrimarySpawnPoints;

        foreach (Transform currBulletSpawnPoint in usedSpawnPoints)
        {
            RaycastHit hit;
            laserBeamRenderer.enabled = true;
            laserBeamRenderer.SetPosition(0, currBulletSpawnPoint.position);
            Vector3 direction = currBulletSpawnPoint.transform.forward;

            // Reduce laser length according to ship speed
            Rigidbody rb  = GetComponent <Rigidbody>();
            Vector3   vel = rb.velocity;

            float finalLaserLength = Ship17LaserLength - vel.magnitude;
            //Debug.Log("finalLaserLength = " + finalLaserLength);

            if (finalLaserLength < Ship17LaserMinLength)
            {
                finalLaserLength = Ship17LaserMinLength;
            }

            Vector3 endPoint = currBulletSpawnPoint.transform.position + currBulletSpawnPoint.transform.forward * finalLaserLength;

            Vector3 fwd = currBulletSpawnPoint.transform.TransformDirection(Vector3.forward);


            if (Physics.Raycast(currBulletSpawnPoint.transform.position, fwd, out hit, finalLaserLength))
            {
                //print("There is something in front of the object! " + hit.distance);
                endPoint = hit.point;

                ShipHandling hitShipHandling = hit.collider.gameObject.GetComponentInParent <ShipHandling>();


                // Do damage
                if (Ship17LaserDrawCount >= Ship17LaserDoDamageInterval)
                {
                    // Don't do damage every time laser is drawn
                    GameObject instance  = Resources.Load("Prefabs/ShrapnelExplosionMedium") as GameObject;
                    GameObject explosion = Instantiate(instance, hit.point, Quaternion.identity);
                    Destroy(explosion, 3.0f);
                    Ship17LaserDrawCount = 0;

                    if (hitShipHandling != null)
                    {
                        hitShipHandling.DoDamage(shipDetails.Primary.Damage);
                    }
                }
                else
                {
                    Ship17LaserDrawCount++;
                }
            }

            laserBeamRenderer.SetPosition(1, endPoint);
        }
    }