Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            InvokeRepeating("Fire", 0.000001f, firingRate);
        }

        if (Input.GetKeyUp(KeyCode.Space))
        {
            CancelInvoke("Fire");
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.position += Vector3.right * speed * Time.deltaTime;
        }
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.position += Vector3.left * speed * Time.deltaTime;
        }

        // Restrict the play to the game space
        float newX = Mathf.Clamp(transform.position.x, xmin, xmax);

        transform.position = new Vector3(newX, transform.position.y, transform.position.z);

        ExtraShips exShip = gameObject.GetComponent <ExtraShips> ();

        // Player's Lives
        //UpdatePlayersLives (exShip);

        PlayerLivesBar.displayPlayersLives();
    }
Exemplo n.º 2
0
 void UpdatePlayersLives(ExtraShips eShip)
 {
     // Player's Lives
     if (eShip.getMaxLive() <= lives)
     {
         PlayerLivesBar.displayPlayersLives("Lives: Max - ");
     }
     else
     {
         PlayerLivesBar.displayPlayersLives();
     }
 }
Exemplo n.º 3
0
    void OnTriggerEnter2D(Collider2D col)
    {
        ExtraShips eShip = col.gameObject.GetComponent <ExtraShips> ();

        if (col.gameObject.name.Contains("Ship"))
        {
            if (eShip)
            {
                if (eShip.getMaxLive() > lives)
                {
                    lives += eShip.GetExtraShip();
                    eShip.extraShipUsed();
                }
            }
        }
        else if (col.gameObject.name.Contains("Health"))
        {
            ExtraHealths extraHealth = col.gameObject.GetComponent <ExtraHealths>();

            if (extraHealth)
            {
                health += extraHealth.GetExtraHealth();
                extraHealth.extraHealthUsed();
            }
        }
        else if (col.gameObject.name.Contains("Speed"))
        {
            ExtraSpeeds extraSpeed = col.gameObject.GetComponent <ExtraSpeeds>();

            if (extraSpeed)
            {
                projectileSpeed += extraSpeed.GetExtraSpeed();
                extraSpeed.extraSpeedUsed();
            }
        }
        else if (col.gameObject.name.Contains("ExtraWeapon"))
        {
            ExtraWeapons extraWeapon = col.gameObject.GetComponent <ExtraWeapons>();

            if (extraWeapon)
            {
                if (extraWeapon.getMaxWeapons() >= numFire)
                {
                    numFire += extraWeapon.GetExtraWeapon();
                    extraWeapon.extraWeaponUsed();
                }
            }
        }
        else if (col.gameObject.name.Contains("Laser"))
        {
            Projectile missile = col.gameObject.GetComponent <Projectile> ();
            if (missile)
            {
                // Remove the damage from the player health
                health -= missile.GetDamage();

                // Then destory the missile
                missile.Hit();

                // If Health goes below 0
                if (health <= 0)
                {
                    Debug.Log("Current Lives Count: " + lives);
                    ReSetHealth();
                    lives -= 1;

                    if (lives == 0)
                    {
                        Debug.Log("Live Count: " + lives);
                        ReSetLives();
                        Die();
                    }
                }
            }
        }

        Update();

        // Player's Health
        PlayerHealth.displayPlayersHealth();
        // Player's Lives
        UpdatePlayersLives(eShip);

        Update();
    }