Exemple #1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "alien")
        {
            Destroy(bulletPos.gameObject);
            Destroy(other.gameObject);
            Shaker.Shake(0.1f);
        }

        if (other.tag == "shield")
        {
            Destroy(bulletPos.gameObject);
            Shaker.Shake(0.1f);
        }
    }
Exemple #2
0
    void Explode()
    {
        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius);

        foreach (Collider2D col in colliders)
        {
            Rigidbody2D rb = col.GetComponent <Rigidbody2D>();

            if (rb != null)
            {
                Vector2 dir = rb.position - GetComponent <Rigidbody2D>().position;

                rb.AddForce(dir, ForceMode2D.Impulse);
            }

            //damage player
            if (col.gameObject.GetComponent <PlayerHealth>())
            {
                col.gameObject.GetComponent <PlayerHealth>().takeDamage(2);
            }
        }

        //effects
        StartCoroutine(cameraShake.Shake(0.25f, 0.2f));
        explodeSound.Play();
        Instantiate(particles, transform.position, Quaternion.identity);

        //delay destruction
        GetComponent <CircleCollider2D>().enabled = false;
        GetComponent <SpriteRenderer>().enabled   = false;
        Destroy(gameObject, 0.25f);
    }
    void Update()
    {
        coolDown++;

        if (Input.GetKeyDown("space") && coolDown >= 50f)
        {
            Instantiate(bullet, position.position, position.rotation);

            coolDown = 0f;

            Shaker.Shake(0.08f);
        }

        if (position.position.x >= 20f)
        {
            position.position = new Vector2(20, -9);
        }

        if (position.position.x <= -20f)
        {
            position.position = new Vector2(-20, -9);
        }

        move = Input.GetAxis("Horizontal");

        transform.Translate((move * speed), 0, 0);
    }
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Boundary" ||
         other.tag == "DoubleShot" ||
         other.tag == "TripleShot" ||
         other.tag == "Shot" ||
         other.tag == "FourShot")
     {
         return;
     }
     if (other.tag == "Coin")
     {
         audioSource = GetComponent <AudioSource>();
         audioSource.Play();
     }
     if (other.tag == "EnemyShot")
     {
         if ((health - enemyShotDamage) < 0)
         {
             GameOver();
         }
         health -= enemyShotDamage;
         playerHealth.decreaseHealth(enemyShotDamage);
     }
     if (other.tag == "Enemy")
     {
         if ((health - enemyDamage) < 0)
         {
             GameOver();
         }
         health -= enemyDamage;
         playerHealth.decreaseHealth(enemyDamage);
         camShake.Shake();
     }
     if (other.tag == "Asteroid")
     {
         if ((health - asteroidDamage) < 0)
         {
             GameOver();
         }
         health -= asteroidDamage;
         playerHealth.decreaseHealth(asteroidDamage);
         camShake.Shake();
     }
 }
Exemple #6
0
 public void ExplosionSFX(int num)
 {
     if (playSFX == true)
     {
         sound ex = explosionFX[num];
         ex.source.Play();
         StartCoroutine(cameraShakeCR.Shake(0.15f, 0.4f));
         Debug.Log("Play Explosion SFX");
     }
 }
    void OnCollisionEnter2D(Collision2D coll)       //Checks for collisions
    {
        if (coll.gameObject.tag == "bullet")
        {
            hitsTaken += 1;             //If hit by player shot increase hit count

            if (hitsTaken == 20)        //When 20 hits taken, move into stage two
            {
                camShake.Shake(DeathShake, 6.0f);
                MageStage.GetComponent <AudioSource> ().Play();
            }

            if (hitsTaken >= 40)               //When 40 hits taken the boss will die
            {
                camShake.Shake(DeathShake, 3.0f);
                MageDeath.GetComponent <AudioSource> ().Play();
                animator.SetBool("dyingBoss", true);           //Set death animation
                GameScript.KillBossTwo(this);                  //Kill the boss
            }
        }
    }
Exemple #8
0
    void OnCollisionEnter2D(Collision2D coll)       //Checks for collisions
    {
        if (coll.gameObject.tag == "ground")        //If the tag ground is found, set jumping False
        {
            animator.SetBool("jumping", false);
            canJump = true;             //Allow jumping as it is not grounded
        }

        if (coll.gameObject.tag == "Enemy")           //If tag is Enemy, set off trigger GotHit
        {
            animator.SetTrigger("gotHit");
            PlayerDamaged.GetComponent <AudioSource> ().Play();
            camShake.Shake(DamageShake, 0.2f);
        }

        if (coll.gameObject.tag == "boss1")           //If tag is Enemy, set off trigger GotHit
        {
            animator.SetTrigger("gotHit");
            PlayerDamaged.GetComponent <AudioSource> ().Play();
            camShake.Shake(DamageShake, 0.2f);
        }
    }
    void OnCollisionEnter2D(Collision2D coll)       //Checks for collisions
    {
        if (coll.gameObject.tag == "bullet")
        {
            hitsTaken += 1;             //Add to times hit by player

            if (hitsTaken >= 20)        //Check if dead
            {
                camShake.Shake(DeathShake, 3.0f);
                animator.SetBool("dyingBoss", true);
                IdleSound.GetComponent <AudioSource> ().Play(); //Play dead sound
                GameScript.KillBoss(this);                      //Call the kill function
            }
        }
    }
Exemple #10
0
    public void takeDamage(int damage)
    {
        if (invulnerable || dead)
        {
            return;
        }

        StartCoroutine(DamageFlash());

        currentHp -= damage;
        hpBar.setHealth(currentHp);
        hpBar.damageAnimation();

        hurtSound.Play();

        if (currentHp <= 0)
        {
            die();
        }

        //add a knockback effect?

        StartCoroutine(cameraShake.Shake(0.15f, 0.2f));
    }
Exemple #11
0
    void Explode()
    {
        if (exploded)
        {
            return;
        }

        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius);

        foreach (Collider2D col in colliders)
        {
            Rigidbody2D rb = col.GetComponent <Rigidbody2D>();

            //explosive force
            if (rb)
            {
                Vector2 dir = rb.position - GetComponent <Rigidbody2D>().position;
                dir.Normalize();
                rb.velocity = Vector2.zero;
                rb.AddForce(dir * strength, ForceMode2D.Impulse);
            }

            //damage player
            if (col.gameObject.GetComponent <PlayerHealth>())
            {
                col.gameObject.GetComponent <PlayerHealth>().takeDamage(2);
            }

            //damage enemy
            if (col.gameObject.GetComponent <enemyHealth>())
            {
                col.gameObject.GetComponent <enemyHealth>().takeDamage(2);
            }
        }


        //effects
        StartCoroutine(cameraShake.Shake(0.4f, 0.2f));
        explodeSound.Play();
        Instantiate(particles, transform.position, Quaternion.identity);

        //delay destruction
        GetComponent <BoxCollider2D>().enabled  = false;
        GetComponent <SpriteRenderer>().enabled = false;
        transform.Find("light").gameObject.SetActive(false);
        Destroy(gameObject, 1f);
    }
Exemple #12
0
    public void TakeDamage(int amount)
    {
        damaged = true;

        currentHealth -= amount;

        healthSlider.value = currentHealth;

        playerAudio.Play();

        StartCoroutine(cameraShake.Shake(.15f, .6f));

        if (currentHealth <= 0 && !isDead)
        {
            Death();
        }
    }
Exemple #13
0
 public void laserStuff()
 {
     if (Input.GetButton("Fire1"))
     {
         laser.SetActive(true);
         RaycastHit2D hit = Physics2D.Raycast(laserOrigin.position, toolDir, 100, layerMask);
         if (hit.collider != null)
         {
             foreach (LineRenderer l in laserBeams)
             {
                 l.SetPosition(1, l.transform.InverseTransformPoint(hit.point));
                 end.position = hit.point;
                 end.up       = hit.normal;
                 end.gameObject.SetActive(true);
             }
             asteroid astro = hit.collider.GetComponent <asteroid>();
             if (astro != null)
             {
                 Vector2 pos  = astro.transform.position;
                 bool    boom = astro.damage(damagePerSecond * Time.deltaTime);
                 if (boom)
                 {
                     GameObject.Instantiate(explosion, pos, Quaternion.Euler(0, 0, Random.Range(0, 360)));
                     float shaky = Mathf.Clamp(-hit.distance * 0.1f + 1, 0.1f, 1f) * 0.7f;
                     shake.Shake(0.2f, shaky);
                 }
             }
         }
         else
         {
             foreach (LineRenderer l in laserBeams)
             {
                 l.SetPosition(1, Vector2.right * 100f);
                 end.gameObject.SetActive(false);
             }
         }
     }
     else
     {
         laser.SetActive(false);
     }
 }
Exemple #14
0
    void Shoot()
    {
        StartCoroutine(Shooting());
        currentAmmo--;

        StartCoroutine(cameraShake.Shake(0.1f, 0.05f));

        RaycastHit hitinfo;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hitinfo, range))
        {
            changeColor change = hitinfo.transform.GetComponent <changeColor>();
            if (change != null)
            {
                change.Changing(damage);
            }

            if (hitinfo.rigidbody != null)
            {
                hitinfo.rigidbody.AddForce(-hitinfo.normal * impactForce);
            }
        }
    }
        private void Update()
        {
            TimeBeforeWriting -= Time.deltaTime;

            if (TimeBeforeWriting <= 0.0f)
            {
                if (loadText && !coroutineProtect)
                {
                    StartCoroutine(LoadLetters(uiTextCopy));
                    coroutineProtect = true;
                }

                else if (loadText && coroutineProtect)
                {
                    uiText.text = showText;
                }

                else if (!loadText && !coroutineProtect)
                {
                    if (uiText.text != uiTextCopy)
                    {
                        TextInformations();
                    }
                }
            }



            if (!gameOver.isPlaying && fini == true)
            {
                StartCoroutine(cameraShake.Shake(2f, 10f));
                gameOver.clip = explosion;
                gameOver.Play();
                cameraShake.GetComponent <UnityEngine.Video.VideoPlayer>().Play();
                fini = false;
            }
        }
    public void boom()
    {
        //damage
        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius);

        foreach (Collider2D col in colliders)
        {
            Rigidbody2D rb = col.GetComponent <Rigidbody2D>();

            //explosive force
            if (rb)
            {
                Vector2 dir = rb.position - GetComponent <Rigidbody2D>().position;
                dir.Normalize();
                rb.velocity = Vector2.zero;
                rb.AddForce(dir * strength, ForceMode2D.Impulse);
            }

            //damage enemy
            if (col.gameObject.GetComponent <enemyHealth>())
            {
                col.gameObject.GetComponent <enemyHealth>().takeDamage(2);
            }
        }

        explodeSound.Play();
        Instantiate(particles, transform.position, Quaternion.identity);

        StartCoroutine(cameraShake.Shake(0.25f, 0.15f));

        //hide before delay destroying
        GetComponent <SpriteRenderer>().enabled   = false;
        GetComponent <TrailRenderer>().enabled    = false;
        GetComponent <CircleCollider2D>().enabled = false;
        Destroy(gameObject, 0.5f);
    }
Exemple #17
0

        
    IEnumerator shipBlast()
    {
        List <AttackLocation> damagableAttackPositions = new List <AttackLocation>();

        for (int i = 0; i < possibleAttackPositions.Length; i++)
        {
            int healthCur = 0;
            for (int j = 0; j < possibleAttackPositions[i].repairables.Count; j++)
            {
                healthCur += possibleAttackPositions[i].repairables[j].health;
            }
            if (healthCur > 0)
            {
                damagableAttackPositions.Add(possibleAttackPositions[i]);
            }
        }

        attackLocation = damagableAttackPositions[Random.Range(0, damagableAttackPositions.Count)].worldPositon;

        // if (attackLocation != null)
        // {
        //
        //
        //    // while (attackLocation == lastHitLocaton)
        //    // {
        //    //     locationIndex = Random.Range(0, possibleAttackPositions.Length);
        //    //     attackLocation = possibleAttackPositions[locationIndex].worldPositon;
        //    // }
        // }
        // else
        // {
        //     attackLocation = possibleAttackPositions[Random.Range(0, possibleAttackPositions.Length)].worldPositon;
        // }

        lastHitLocaton = attackLocation;
        gotHit         = true;                  //michael add
        yield return(new WaitForSeconds(.5f));  //delay in travel time of laser

        GameObject newBlast = Instantiate(blastEffectPrefab, attackLocation, Quaternion.identity);

        StartCoroutine(shake.Shake(0.15f, 0.2f));
        //shipShakingAnim.Play();
        index = Random.Range(0, possibleAttackPositions[locationIndex].nodes.Count);
        Grid.instance.GenerateLaserFire(possibleAttackPositions[locationIndex].nodes[index]);

        Collider[] damagedObjects = Physics.OverlapSphere(attackLocation, explosionRadius, interactableLayerMask);

        foreach (Collider damagedObject in damagedObjects)
        {
            IDamageable <int> caughtObject = damagedObject.GetComponent <IDamageable <int> >();
            //shipCurrenHealth -= explosionDamage;
            if (caughtObject != null)
            {
                caughtObject.TakeDamage(explosionDamage);
            }
        }

        AudioEventManager.instance.PlaySound("bang", .8f, Random.Range(.2f, 1f), 0);
        AdjustUI();

        if (shipCurrenHealth <= shipMaxHealth * 0.25)
        {
            LoseGame();
        }

        yield return(new WaitForSeconds(1.5f));

        Destroy(newBlast);

        yield return(null);
    }
Exemple #19
0
    void Update()
    {
        if (controllable == true)
        {
            if (abilities == true && isGrounded() == false)
            {
                Floating();
            }

            if (Input.GetKeyDown(KeyCode.E))
            {
                isDashButtonDownE = true;
            }
            if (Input.GetKeyDown(KeyCode.W))
            {
                isDashButtonDownW = true;
            }

            /*
             * if (isDashButtonDownE && Player.instancePlayer.currDash > 0 && !isGrounded())
             * {
             *  cameraShake.Shake(0.4f, 0.1f);
             *  if (this.transform.localScale.x > 0)
             *  {
             *      rb.velocity = new Vector2(1f * speed * 60f, rb.velocity.y);
             *      //rb.transform.Translate(speed * Time.deltaTime,0,0);
             *      Player.instancePlayer.currDash -= 1;
             *      Infoscript.instance.UpdateDashAmulette();
             *  }
             *  else
             *  {
             *      //rb.transform.Translate(speed * Time.deltaTime * -1, 0, 0);
             *      rb.velocity = new Vector2(-1f * speed * 60f, rb.velocity.y);
             *      Player.instancePlayer.currDash -= 1;
             *      Infoscript.instance.UpdateDashAmulette();
             *
             *  }
             *  isDashButtonDownE = false;
             * }
             */
            if (isDashButtonDownW && Player.instancePlayer.currDash > 0)
            {
                cameraShake.Shake(0.4f, 0.1f);
                rb.gravityScale = 0.1f;
                rb.velocity     = new Vector2(movementx * speed, 1f * 15f);
                Player.instancePlayer.currDash -= 1;
                Infoscript.instance.UpdateDashAmulette();

                timeGrounded      = 0;
                isDashButtonDownW = false;
            }
            else
            {
                Move();
                isDashButtonDownE = false;
                isDashButtonDownW = false;
                if (isGrounded())
                {
                    regenDash = StartCoroutine(RegenDash());
                }
            }
        }

        /*if (Input.GetMouseButtonDown(1))
         * {
         *  Infoscript.instance.DamageHealthpoints(1);
         * }
         */
    }
Exemple #20
0
 private void shakeCamera()
 {
     StartCoroutine(camerashake.Shake(.15f, .4f));
 }
Exemple #21
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Enemy")
        {
            Infoscript.instance.DamageHealthpoints(1);
            cameraShake.Shake(0.4f, 0.1f);
            Soundcontrollerscript.soundInstance.playAudioSource(1);
        }

        if (collision.tag == "BoostFlower")
        {
            PlayerMovement pM = GameObject.FindObjectOfType <PlayerMovement>();
            pM.getBoost();
        }

        if (collision.tag == "TriggerEvent")
        {
            Destroy(collision.gameObject);
            GameObject levelchanger = GameObject.Find("LevelChanger");
            levelchanger.GetComponent <MainMenu>().FadeToLevel();
        }

        if (collision.tag == "DeactivateObject")
        {
            this.gameObject.SetActive(false);
        }

        if (collision.tag == "DialogueTrigger")
        {
            DialogueTrigger dTrigger = collision.GetComponent <DialogueTrigger>();
            dialogueBoxM.SetActive(true);
            dTrigger.TriggerDialogue();
            dTrigger.ActivateButton();
            dTrigger.DeactivateDialogue();
        }

        if (collision.tag == "Checkpoint")
        {
            lastCheckpoint = collision.gameObject;
        }

        if (collision.tag == "Killzone")
        {
            cameraShake.Shake(0.4f, 0.1f);
            Respawn();
        }
        if (collision.tag == "EndGame")
        {
            GameObject levelchanger = GameObject.Find("LevelChanger");
            levelchanger.GetComponent <MainMenu>().FadeToLevel();
        }
        if (collision.tag == "HealthItem")
        {
            if (HealthPoints < 3)
            {
                addHP();
                Destroy(collision.gameObject);
            }
        }
        if (collision.tag == "Collectable")
        {
            currCollectables += 1;
            ProgressCollectables.updateCollactablesAmount();
            collectablesAmount.text = currCollectables + " / 25";
            Destroy(collision.gameObject);
        }

        if (collision.tag == "Amulette")
        {
            maxDash  += 1;
            currDash += 1;

            //updateProgressMaxDash();

            Infoscript.instance.UpdateDashAmulette();
            Destroy(collision.gameObject);
        }

        if (collision.tag == "BossSoul")
        {
            Boss.bossInstance.changeBossHP();
            Destroy(collision.gameObject);
        }

        if (collision.tag == "Projectile")
        {
            cameraShake.Shake(0.4f, 0.1f);
            Infoscript.instance.DamageHealthpoints(1);
            Soundcontrollerscript.soundInstance.playAudioSource(1);
            Destroy(collision.gameObject);
        }
    }