Exemple #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));
                }
            }
        }
    }
        public static void CreateBullet(ITransform transform, int team, Vector2 direction)
        {
            Bullet            bullet  = new Bullet();
            List <ICollision> targets = new List <ICollision>(); //is nog leeg

            foreach (var human in ((Level)bullet.currentLevel).humans)
            {
                if (human.Team != team)
                {
                    targets.Add(human._collision);
                }
            }
            targets.Add(((Level)bullet.currentLevel).obstacles[0]._collision); //Voeg grond toe, hardcoded voor nu
            bullet.Texture = Textures.BulletTexture;
            BulletPhysicsHandler physicsHandler = new BulletPhysicsHandler();

            physicsHandler.inputAcceleration = 600; //Default 800
            Vector2 accuracyReduction = new Vector2(RandomNumberClass.GenerateRandomFloat(-0.12f, 0.12f), RandomNumberClass.GenerateRandomFloat(-0.07f, 0.03f));

            direction  = Vector2.Normalize(direction);
            direction += accuracyReduction;
            physicsHandler.Direction = Vector2.Normalize(direction);
            bullet._PhysicsHandler   = physicsHandler;
            BulletCollision collision = new BulletCollision(transform.Position, targets);

            collision.RectangleWidth  = 5;
            collision.RectangleHeight = 3;
            bullet._collision         = collision;
            bullet._collision.Parent  = bullet;
            bullet.Scale    = 2.5f;
            bullet.Rotation = MathUtilities.VectorToAngle(direction);
            bullet.Position = new Vector2(transform.Position.X + 9, transform.Position.Y + 13);
            (bullet.currentLevel).bullets.Add(bullet);
        }
    //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;
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        int life;


        if (collision.gameObject.tag == "Bullets2" || collision.gameObject.tag == "Bullets1")
        {
            BulletCollision bulletCollision = collision.gameObject.GetComponent <BulletCollision>();
            if (bulletCollision.hitCounter == 0)
            {
                if (gameObject.tag == "Player1" && collision.gameObject.tag == "Bullets1")
                {
                    return;
                }
                if (gameObject.tag == "Player2" && collision.gameObject.tag == "Bullets2")
                {
                    return;
                }
            }

            if (gameObject.tag == "Player1")
            {
                GameData.player1Health--;
            }
            else
            {
                GameData.player2Health--;
            }

            if (gameObject.tag == "Player1")
            {
                life = GameData.player1Health;
            }
            else
            {
                life = GameData.player2Health;
            }

            hitSounds[Random.Range(0, hitSounds.Length)].Play();

            if (life == 0)
            {
                gameObject.SetActive(false);
                if (gameObject.tag == "Player1")
                {
                    GameManager.instance.onPlayer1Death();
                }
                if (gameObject.tag == "Player2")
                {
                    GameManager.instance.onPlayer2Death();
                }
            }
        }
    }
Exemple #5
0
    void Update()
    {
        if (player.getCurrentPower() == PlayerController.powerUpState.RED)
        {
            bulletDamage *= player.powerMultiplier;
        }
        else
        {
            bulletDamage = defaultDamage;
        }

        previousPosition = BulletCollision.bulletCollisionCast(gameObject, transform, previousPosition, bulletRB, bulletDamage, "player");
    }
    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;
            }
        }
    }
Exemple #7
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);
    }
        public void StartTransmittingData(IPlayerManager playerManager, IShipManager shipManager
                                          , IBulletManager bulletManager, BulletCollision bulletCollision, ShipCollision shipCollision)
        {
            playerManager.SendPlayerPosition          += shipManager.ReceivePlayerPosition;
            shipManager.SendShipsPositions            += bulletManager.ReceiveShipsPositions;
            shipManager.SendNewWeapons                += bulletManager.SubscribeForNewWeapons;
            bulletCollision.bulletCollision           += bulletManager.OnBulletCollision;
            bulletCollision.bulletCollidesWithAShip   += shipManager.OnBulletCollision;
            bulletCollision.bulletCollidesWithAShip   += playerManager.OnBulletCollision;
            shipCollision.shipCollidesWithAnotherShip += shipManager.OnShipCollision;

            shipManager.SendMessageWhenShipDestroyed += playerManager.UpdateScore;

            shipManager.ShipCollidesWithPlayer += playerManager.UpdateHealth;
        }
Exemple #9
0
        public Game()
        {
            this.satellite     = new Satellite();
            this.playerManager = new PlayerManager();
            this.bulletManager = new BulletManager();
            this.shipManager   = new ShipManager();

            this.bulletCollision = new BulletCollision();
            this.shipCollision   = new ShipCollision();

            this.satellite.StartTransmittingData(playerManager, shipManager,
                                                 bulletManager, bulletCollision, shipCollision);

            this.shipManager.GenerateShips();
            this.playerManager.CreatePlayer(shipManager.BuildShip(ShipType.PlayerShip));
        }
Exemple #10
0
    //the reason for the coroutine is so it can use the WaitForSeconds with the reloadTime of the player.
    private IEnumerator Reload()
    {
        yield return(new WaitForSeconds(reloadTime));

        loadedBullet = Instantiate(bullet, transform.position, transform.rotation);
        //sets the parent so it moves up and down with the player before it's fired.
        loadedBullet.transform.SetParent(this.transform);
        //sets the player to the players layer so that the player and their own bullet don't collide with each other since the collision matrix has been modified.
        loadedBullet.layer = this.gameObject.layer;
        //gives the presaved references from the start method
        BulletCollision BCTemp = loadedBullet.GetComponent <BulletCollision>();

        BCTemp.OwnerID = this.playerID;
        BCTemp.SM      = SM;
        //sets loaded so that the update method can fire the weapon again
        loaded = true;
    }
    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;
    }
    public override void Fire()
    {
        if (isReadyToFire)
        {
            if (!weaponItem.isRangedWeapon)
            {
                RaycastHit hit;

                if (weaponAnchor != null)
                {
                    Debug.DrawRay(weaponAnchor.transform.position, weaponAnchor.transform.TransformDirection(Vector3.forward) * weaponItem.weaponRange, Color.yellow);
                    if (Physics.Raycast(weaponAnchor.transform.position, weaponAnchor.transform.TransformDirection(Vector3.forward), out hit, weaponItem.weaponRange))
                    {
                        //Debug.Log("Hit succesful, hit: " + hit.transform.gameObject.name);
                        EnemyHealth hitHealth = hit.transform.gameObject.GetComponent <EnemyHealth>();
                        if (hitHealth != null)
                        {
                            hitHealth.DealDamage(weaponItem.weaponDamage);
                            Debug.Log("Dealing damage to enemy");
                        }
                    }
                }
            }
            else
            {
                GameObject projectile = Instantiate(weaponItem.projectileObject, weaponAnchor.transform.position, Quaternion.identity);
                projectile.GetComponent <Rigidbody>().AddForce(transform.forward * weaponItem.projectileSpawnSpeed);
                BulletCollision bc = projectile.GetComponent <BulletCollision>();

                if (bc != null)
                {
                    bc.damage   = weaponItem.weaponDamage;
                    bc.isPlayer = true;
                }
                else
                {
                    GrenadeTimer gt = projectile.GetComponent <GrenadeTimer>();
                    gt.damage = weaponItem.weaponDamage;
                }
            }
        }

        base.Fire();
    }
Exemple #13
0
 void Update()
 {
     previousPosition = BulletCollision.bulletCollisionCast(gameObject, transform, previousPosition, bulletRB, enemyDamage, "enemy");
 }