Ejemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "gameBoundary")
        {
            return;
        }

        if (other.tag == "bullet")
        {
            return;
        }

        if (other.tag == "ship")
        {
            Destroy(gameObject);              //destroys power up object
            GameObject   ship       = GameObject.Find("ship");
            ShipBehavior shipScript = ship.GetComponent <ShipBehavior>();
            shipScript.doBarrelRoll = true;             //do barrellRoll
            GameObject score       = GameObject.Find("Score");
            Score      scoreScript = score.GetComponent <Score>();
            scoreScript.AddScore(25);             //add 25 to score

            //play sound
            audio.clip = soundfile;
            audio.Play();
        }
    }
Ejemplo n.º 2
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "gameBoundary")
        {
            return;
        }

        if (other.tag == "bullet")
        {
            return;
        }

        if (other.tag == "ship")
        {
            //Instantiate (explosion, transform.position, transform.rotation); //explosion will occur at asteroid
            //Destroy (other.gameObject); //destroys ship
            Destroy(gameObject);              //destroys power up object

            GameObject   ship  = GameObject.Find("ship");
            ShipBehavior ship2 = ship.GetComponent <ShipBehavior>();
            ship2.SlowTime     = true;
            ship2.doBarrelRoll = true;
            ship2.SlowTimeTime = Time.time + 30f;

            //play sound
            audio.clip = soundfile;
            audio.Play();
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        GameObject   ship  = GameObject.Find("ship");
        ShipBehavior ship2 = ship.GetComponent <ShipBehavior>();

        if (ship2.SlowTime)
        {
            bulletSpeed = 25;
        }
        else
        {
            bulletSpeed = 50;
        }
        if (Time.time > nextShot)
        {
            nextShot = Time.time + fireRate;

            Rigidbody instantiatedProjectile = Instantiate(projectile,
                                                           transform.position,
                                                           transform.rotation)
                                               as Rigidbody;

            //make object move
            instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, bulletSpeed));

            //stops collisions between bullets and camera
            //Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
        }
    }
Ejemplo n.º 4
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "gameBoundary")
        {
            return;
        }

        if (other.tag == "bullet")
        {
            return;
        }

        if (other.tag == "ship")
        {
            GameObject   ship         = GameObject.Find("ship");
            ShipBehavior shipbehavior = ship.GetComponent <ShipBehavior>();
            shipbehavior.doBarrelRoll = true;
            if (shipbehavior.lives < 9)
            {
                shipbehavior.lives++;
            }

            //play sound
            //audio.PlayOneShot(soundfile);
            //audio.Play();
            audio.Play();
            Destroy(gameObject);              //destroys power up object
        }
    }
Ejemplo n.º 5
0
 private void OnTriggerEnter(Collider other)                        // when the cannonball collides with something
 {
     if (other.tag == "Player")                                     // if object colliding with is a player
     {
         ShipBehavior player = other.GetComponent <ShipBehavior>(); // gets the player script
         if (player == null)
         {
             return;
         }
         player.shipHealth -= damage; // subtracts damage from the health of the player
         Debug.Log("PlayerHealth: " + player.shipHealth);
     }
     else if (other.tag == "AI") // if object colliding with is an ai
     {
         CannonFireAI    cannonFireAI    = other.GetComponent <CannonFireAI>();
         RespawnBehavior respawnBehavior = other.GetComponent <RespawnBehavior>();
         ShipAi          shipAi          = other.GetComponent <ShipAi>(); // grabs the ai script
         if (shipAi == null)
         {
             return;
         }
         shipAi.health -= damage; // subtracts damge from the health of the ai
         if (shipAi.health <= 0.0f)
         {
             respawnBehavior.Respawn();
             shipAi.health = 100.0f;
             // Delete Below Later (Once Nathan is done with the AI code, implment that there
             userStatistics.addFood(Random.Range(1, 100));
             userStatistics.addGold(Random.Range(1, 25));
         }
         Debug.Log("AIHealth: " + shipAi.health);
     }
 }
Ejemplo n.º 6
0
 public void DisableShipAndShopCanvas(ShipBehavior shipBehavior)
 {
     currentPortCanvas.enabled    = false;
     headsUpDisplayCanvas.enabled = true;
     pcControlCanvas.enabled      = true;
     shipBehavior.enabled         = true;
     shipCanvas.enabled           = false;
     shipBehavior.stopSail();
 }
    void OnCollisionEnter(Collision info)
    {
        ShipBehavior ship = info.collider.GetComponent <ShipBehavior>();

        if (ship)
        {
            ship.GetDamage(damage);
        }

        Destroy(gameObject);
    }
Ejemplo n.º 8
0
 public void enableShipAndShopCanvas(ShipBehavior shipBehavior)
 {
     if (currentPortCanvas == null)
     {
         return;
     }
     currentPortCanvas.enabled    = true;
     shipCanvas.enabled           = true;
     headsUpDisplayCanvas.enabled = false;
     pcControlCanvas.enabled      = false;
     shipBehavior.enabled         = false;
     shopExitButton.gameObject.SetActive(true);
 }
Ejemplo n.º 9
0
    public bool FindShipToRemove(ShipBehavior otherShip)
    {
        ShipBehavior shipToRemove = _shipBehaviors.Find(ship => ship == otherShip);

        if (shipToRemove)
        {
            --_shipsRemaining;

            return(true);
        }

        return(false);
    }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        // transform.Translate(Vector3.front * -7 * Time.deltaTime);
        int timemult = (int)(Time.time / 120);

        if (timemult > 5)
        {
            timemult = 5;
        }
        float   asteroidspeed = -10f - timemult / 2;
        Vector3 pos           = transform.position;

        pos.x += 0.05f * ast_direction * Time.deltaTime;
        pos.y += 0.02f * ast_direction * Time.deltaTime;

        GameObject ship = GameObject.Find("ship");

        if (ship.GetComponent <ShipBehavior>() != null)
        {
            ShipBehavior ship2 = ship.GetComponent <ShipBehavior>();
            if (ship2.SlowTime)
            {
                pos.z += asteroidspeed / 2 * Time.deltaTime;
            }
            else
            {
                pos.z += asteroidspeed * Time.deltaTime;
            }
        }

        transform.position = pos;

        if (pos.z <= -15)
        {
            Destroy(gameObject);
        }

        //Rotate
        Vector3 rot = new Vector3();

        rot.x += ast_rotation * rotationSpeed * Time.deltaTime;
        rot.y += ast_rotation * rotationSpeed * Time.deltaTime;
        rot.z += ast_rotation * rotationSpeed * Time.deltaTime;
        transform.Rotate(rot);
    }
Ejemplo n.º 11
0
    private void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player")
        {
            Debug.Log("Current Port Canvas: " + portCanvas);

            cannonBalls.SetActive(false);
            shipBehavior = other.GetComponent <ShipBehavior>();
            shopEnterButton.onClick.AddListener(delegate { enableShipAndShopCanvas(shipBehavior); });
            shopExitButton.onClick.AddListener(delegate { DisableShipAndShopCanvas(shipBehavior); });
            shopEnterButton.gameObject.SetActive(true);

            if (Application.platform == (RuntimePlatform.WindowsEditor | RuntimePlatform.WindowsPlayer))
            {
                shopPcEnterKeyCode.enabled = true;
                if (Input.GetKeyDown(KeyCode.I))
                {
                    enableShipAndShopCanvas(shipBehavior);
                }
            }
        }
    }
Ejemplo n.º 12
0
    //time of invulnerability after getting hit

    void OnTriggerEnter(Collider other)
    {
        GameObject   ship         = GameObject.Find("ship");
        ShipBehavior shipbehavior = ship.GetComponent <ShipBehavior>();

        if (other.tag == "gameBoundary")
        {
            return;
        }

        if (other.tag == "bullet")
        {
            GameObject            spawner       = GameObject.Find("Spawner");
            enemySpaceshipSpawner spawnerScript = spawner.GetComponent <enemySpaceshipSpawner>();

            Instantiate(explosion, transform.position, transform.rotation);              //explosion will occur at collision
            if (gameObject.tag == "Enemy" || gameObject.tag == "ebullet")
            {
                Destroy(gameObject);                  //destroys enemy or enemy bullet(not sure if ebullet destroyed)
                spawnerScript.enemyAmount--;
            }
            Destroy(other.gameObject);              //destroys bullet
            //asteroid does not get destroyed
        }

        if (other.tag == "ship" && shipbehavior.immunetime < Time.time)
        {
            shipbehavior.lives--;
            shipbehavior.immunetime = Time.time + 3f;
            Destroy(gameObject);                                            //destroys asteroid
            Instantiate(explosion, transform.position, transform.rotation); //explosion will occur at asteroid
            if (shipbehavior.lives <= 0)
            {
                Destroy(other.gameObject);                  //destroys ship
                Application.LoadLevel(2);
            }
        }
    }
Ejemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        GameObject   ship  = GameObject.Find("ship");
        ShipBehavior ship2 = ship.GetComponent <ShipBehavior>();

        if (Time.time > starttime + 80f)
        {
            Destroy(gameObject);
            GameObject            spawner       = GameObject.Find("Spawner");
            enemySpaceshipSpawner spawnerScript = spawner.GetComponent <enemySpaceshipSpawner>();
            spawnerScript.enemyAmount--;
            Debug.Log("1");
        }
        else if (Time.time > starttime + 60f)
        {
            Vector3 currentPos    = this.transform.position;
            Vector3 target        = waypoints [waypoints.Length].transform.position;
            Vector3 moveDirection = (target - currentPos);
            Vector3 velocity      = rigidbody.velocity;
            if (ship2 != null)
            {
                if (ship2.SlowTime)
                {
                    moveSpeed = 5f;
                }
                else
                {
                    moveSpeed = 7.5f;
                }
            }
        }
        else if (node < waypoints.Length - 1)
        {
            Vector3 currentPos    = this.transform.position;
            Vector3 target        = waypoints [node].transform.position;
            Vector3 moveDirection = (target - currentPos);
            Vector3 velocity      = rigidbody.velocity;
            if (ship2 != null)
            {
                if (ship2.SlowTime)
                {
                    moveSpeed = 5f;
                }
                else
                {
                    moveSpeed = 7.5f;
                }
            }
            if (moveDirection.magnitude < 1)
            {
                node++;                 //move to next waypoint
                //Debug.Log("INCREASING NODE: " + node);
            }
            else
            {
                velocity = moveDirection.normalized * moveSpeed;
                //Debug.Log("VELOCITY: " + velocity);
            }
            rigidbody.velocity = velocity;
        }
        else
        {
            node = 0;             //reset to cycle formation
        }
    }
Ejemplo n.º 14
0
 private void Start()
 {
     _shipMesh = transform.GetChild(0).gameObject;
     _ship     = GetComponent <ShipBehavior>();
     _manager  = FindObjectOfType <PlayerManager>();
 }
Ejemplo n.º 15
0
 void Start()
 {
     ship = GetComponent <ShipBehavior>();
 }
Ejemplo n.º 16
0
 // Use this for initialization
 void Start()
 {
     pSys = GetComponent <ParticleSystem>();
     ship = transform.parent.GetComponent <ShipBehavior>();
 }