Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        rotationalOffset = Random.Range(0f, 2 * Mathf.PI);
        control          = GetComponent <NPControl>();
        player           = GameObject.FindGameObjectWithTag("Player");
        attackMode       = false;
        animator         = GetComponent <Animator>();
        rb          = GetComponent <Rigidbody2D>();
        boxCollider = GetComponent <BoxCollider2D>();
        lifeManager = GetComponent <LifeManager>();
        if (projectilePool == null)
        {
            projectilePool = new Queue <Projectiles.Projectile>();
        }

        for (int i = 0; i < projectilesPerAttack * maxAttacks; i++)
        {
            GameObject             projectileInstance = Instantiate(projectile);
            Projectiles.Projectile projectileCopy     =
                new Projectiles.Projectile(projectileInstance.GetComponent <Rigidbody2D>(),
                                           projectileInstance);
            projectilePool.Enqueue(projectileCopy);
            projectileCopy.instance.SetActive(false);
        }
    }
Example #2
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.transform.tag == "Walls" ||
         other.gameObject.layer == LayerMask.NameToLayer("Enemies"))
     {
         if (other.gameObject.layer == LayerMask.NameToLayer("Enemies"))
         {
             if (other.gameObject.GetComponent <LifeManager>().subLife(dano))
             {
                 bool rand = Random.Range(0f, 1f) <= chanceDeDropar;
                 if (rand)
                 {
                     float whichPowerup = Random.Range(0f, 2f);
                     if (whichPowerup <= 1f)
                     {
                         Instantiate(dropSpeed,
                                     other.gameObject.transform.position, Quaternion.identity);
                     }
                     else
                     {
                         Instantiate(dropCooldown,
                                     other.gameObject.transform.position, Quaternion.identity);
                     }
                 }
                 score.AddScore(100);
                 other.gameObject.GetComponent <Enemy>().Die();
             }
         }
         gameObject.SetActive(false);
         Projectiles.Projectile projectile = new Projectiles.Projectile(rb, gameObject);
         Fire.projectilePool.Enqueue(projectile);
     }
 }
Example #3
0
    // Start is called before the first frame update
    void Start()
    {
        control     = GetComponent <NPControl>();
        player      = GameObject.FindGameObjectWithTag("Player");
        attackMode  = false;
        animator    = GetComponent <Animator>();
        rb          = GetComponent <Rigidbody2D>();
        boxCollider = GetComponent <BoxCollider2D>();
        lifeManager = GetComponent <LifeManager>();

        if (shieldPool == null)
        {
            shieldPool = new Queue <Projectiles.Projectile>();
        }

        for (int i = 0; i < maxShields; i++)
        {
            GameObject             shieldObject = Instantiate(shield);
            Projectiles.Projectile shieldCopy   =
                new Projectiles.Projectile(shieldObject.GetComponent <Rigidbody2D>(),
                                           shieldObject);
            shieldPool.Enqueue(shieldCopy);
            shieldCopy.instance.SetActive(false);
        }
    }
Example #4
0
    // Start is called before the first frame update
    void Start()
    {
        control     = GetComponent <NPControl>();
        player      = GameObject.FindGameObjectWithTag("Player");
        attackMode  = false;
        animator    = GetComponent <Animator>();
        rb          = GetComponent <Rigidbody2D>();
        boxCollider = GetComponent <BoxCollider2D>();
        lifeManager = GetComponent <LifeManager>();
        chargeLight = GetComponentInChildren <Light2D>();

        if (laserPool == null)
        {
            laserPool = new Queue <Projectiles.Projectile>();
        }

        for (int i = 0; i < maxLaserLength; i++)
        {
            GameObject             laserPart = Instantiate(laser);
            Projectiles.Projectile laserCopy =
                new Projectiles.Projectile(laserPart.GetComponent <Rigidbody2D>(),
                                           laserPart);
            laserPool.Enqueue(laserCopy);
            laserCopy.instance.SetActive(false);
        }

        chargeLight.gameObject.SetActive(false);
    }
Example #5
0
    IEnumerator AttackSpiral()
    {
        float angle = 0f;

        for (int i = 0; i < projectilesPerAttack; i++)
        {
            Bounds bounds = boxCollider.bounds;
            shootPosition = new Vector3(transform.position.x,
                                        transform.position.y - bounds.extents.y / 2, 0f);

            angle += (2 * Mathf.PI) / projectilesPerAttack;

            Projectiles.Projectile projectileCopy = projectilePool.Dequeue();
            projectileCopy.instance.SetActive(true);

            projectileCopy.instance.transform.position = shootPosition;

            projectileCopy.rb.velocity = new Vector3(projectileSpeed * Mathf.Cos(angle + rotationalOffset),
                                                     projectileSpeed * Mathf.Sin(angle + rotationalOffset), 0f);
            for (int j = 0; j < framesBetweenShots; j++)
            {
                yield return(null);
            }
        }
    }
Example #6
0
    void RecallLasers()
    {
        int length = laserQueue.Count;

        for (int i = 0; i < length; i++)
        {
            Projectiles.Projectile laserCopy = laserQueue.Dequeue();
            laserCopy.instance.SetActive(false);
            laserPool.Enqueue(laserCopy);
        }
        chargeLight.gameObject.SetActive(false);
    }
Example #7
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.transform.tag == "PlayerProjectile")
     {
         Projectiles.Projectile shield = new Projectiles.Projectile(rb, gameObject);
         Monk.shieldPool.Enqueue(shield);
         gameObject.SetActive(false);
         Projectiles.Projectile playerShoot =
             new Projectiles.Projectile(other.GetComponent <Rigidbody2D>(), other.gameObject);
         Fire.projectilePool.Enqueue(playerShoot);
         playerShoot.instance.SetActive(false);
     }
     else if (other.transform.tag == "Player")
     {
         doDamage = true;
     }
 }
Example #8
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.tag == "Walls" || other.transform.tag == "Player")
        {
            gameObject.SetActive(false);
            Projectiles.Projectile projectile = new Projectiles.Projectile(rb, gameObject);
            Priest.projectilePool.Enqueue(projectile);

            if (other.transform.tag == "Player")
            {
                if (player.lifeManager.subLife(dano))
                {
                    // Fim de jogo
                    GameController.GameOver();
                }
            }
        }
    }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        if (lastProjectileTimer > 0)
        {
            lastProjectileTimer -= Time.fixedDeltaTime;
        }

        if (Input.GetButton("Fire1") && projectilePool.Count > 0 && lastProjectileTimer <= 0f)
        {
            Projectiles.Projectile projectile = projectilePool.Dequeue();
            projectile.instance.SetActive(true);
            projectile.instance.transform.position = transform.position;
            projectile.rb.velocity =
                new Vector3(projectileSpeed * transform.localScale.x, 0f, 0f);
            lastProjectileTimer = projectileTimer;
            animator.SetBool("fire", true);
            StartCoroutine(RechargeLight());
        }
    }
Example #10
0
    // Start is called before the first frame update
    void Start()
    {
        animator              = GetComponent <Animator>();
        rechargeLight         = GetComponentInChildren <Light2D>();
        intensity             = rechargeLight.intensity;
        rechargeLight.enabled = false;

        for (int i = 0; i < numProjectiles; i++)
        {
            GameObject             projectileInstance = Instantiate(projectile);
            Projectiles.Projectile projectileCopy     =
                new Projectiles.Projectile(projectileInstance.GetComponent <Rigidbody2D>(),
                                           projectileInstance);
            projectilePool.Enqueue(projectileCopy);
            projectileCopy.instance.SetActive(false);
        }

        animator.SetBool("fire", false);
    }
Example #11
0
    // Start is called before the first frame update
    void Start()
    {
        fixedTimeBetweenSpawns      = timeBetweenSpawns;
        ScoreManager.startedPlaying = true;
        timeSinceLastSpawn          = timeBetweenSpawns;
        priestPool = new Queue <Projectiles.Projectile>();
        bishopPool = new Queue <Projectiles.Projectile>();
        monkPool   = new Queue <Projectiles.Projectile>();

        for (int i = 0; i < numPriests; i++)
        {
            GameObject             priestInstance = Instantiate(priest);
            Projectiles.Projectile priestCopy     =
                new Projectiles.Projectile(priestInstance.GetComponent <Rigidbody2D>(),
                                           priestInstance);
            priestPool.Enqueue(priestCopy);
            priestCopy.instance.SetActive(false);
        }

        for (int i = 0; i < numBishops; i++)
        {
            GameObject             bishopInstance = Instantiate(bishop);
            Projectiles.Projectile bishopCopy     =
                new Projectiles.Projectile(bishopInstance.GetComponent <Rigidbody2D>(),
                                           bishopInstance);
            bishopPool.Enqueue(bishopCopy);
            bishopCopy.instance.SetActive(false);
        }

        for (int i = 0; i < numMonks; i++)
        {
            GameObject             monkInstance = Instantiate(monk);
            Projectiles.Projectile monkCopy     =
                new Projectiles.Projectile(monkInstance.GetComponent <Rigidbody2D>(),
                                           monkInstance);
            monkPool.Enqueue(monkCopy);
            monkCopy.instance.SetActive(false);
        }

        StartCoroutine(SpawnEnemies(2));
    }
Example #12
0
    IEnumerator ShieldAttack()
    {
        if (shieldPool.Count > 0)
        {
            Projectiles.Projectile shieldCopy = shieldPool.Dequeue();
            shieldCopy.instance.SetActive(true);
            shieldCopy.instance.transform.position = globalShieldPosition;

            Vector3 oldPlayerPosition = player.transform.position;

            while (!(shieldCopy.instance.transform.position.y + 1f > oldPlayerPosition.y &&
                     shieldCopy.instance.transform.position.y - 1f < oldPlayerPosition.y))
            {
                float   step           = verticalSpeed * Time.fixedDeltaTime;
                Vector3 targetPosition = new Vector3(shieldCopy.instance.transform.position.x,
                                                     oldPlayerPosition.y, 0f);
                if (shieldCopy.instance.transform.position.y < -5f)
                {
                    targetPosition.y = Mathf.Clamp(targetPosition.y, -33f, -26.75f);
                }
                else
                {
                    targetPosition.y = Mathf.Clamp(targetPosition.y, -4f, 2.25f);
                }

                shieldCopy.instance.transform.position = Vector3.MoveTowards(shieldCopy.instance
                                                                             .transform.position, targetPosition, step);

                yield return(null);
            }
        }

        yield return(null);

        OnAttackComplete();
    }
Example #13
0
    IEnumerator LaserAttack()
    {
        rb.gravityScale = 0f;
        while (!(transform.position.y + .5f > player.transform.position.y &&
                 transform.position.y - 1f < player.transform.position.y))
        {
            float   step           = verticalSpeed * Time.fixedDeltaTime;
            Vector3 targetPosition = new Vector3(transform.position.x,
                                                 player.transform.position.y, 0f);
            if (transform.position.y < -5f)
            {
                targetPosition.y = Mathf.Clamp(targetPosition.y, -33f, -26.75f);
            }
            else
            {
                targetPosition.y = Mathf.Clamp(targetPosition.y, -4f, 2.25f);
            }

            transform.position = Vector3.MoveTowards(transform.position,
                                                     targetPosition, step);
            if ((targetPosition.x > player.transform.position.x && control.facingRight) ||
                (targetPosition.x < player.transform.position.x && !control.facingRight))
            {
                control.Flip();
            }

            yield return(null);
        }

        RaycastHit2D hit = Physics2D.Raycast(globalShootPosition,
                                             control.facingRight ? Vector2.right : -Vector2.right, Mathf.Infinity, laserCollisionMask);

        if (hit)
        {
            chargeLight.gameObject.SetActive(true);
            float intensity = chargeLight.intensity;

            for (int i = 0; i < framesBeforeLaser; i++)
            {
                float percentage = (float)i * (1f / framesBeforeLaser);
                chargeLight.intensity = Mathf.Lerp(0f, intensity, percentage);
                yield return(null);
            }

            laserQueue = new Queue <Projectiles.Projectile>();

            for (float dx = 0f; dx < hit.distance; dx += (float)1f / 8f)
            {
                Projectiles.Projectile laserCopy = laserPool.Dequeue();
                laserCopy.instance.SetActive(true);

                laserQueue.Enqueue(laserCopy);

                int directionX = control.facingRight ? 1 : -1;

                laserCopy.instance.transform.position = transform.position +
                                                        new Vector3(dx * directionX, 0f, 0f);
            }

            for (int i = 0; i < laserDurationFrames; i++)
            {
                yield return(null);
            }

            RecallLasers();
        }
        OnAttackComplete();
    }
Example #14
0
        public void Hit(Projectile source)
        {
            if (isHit || isInvunerable)
            {
                return;
            }
            if (source is Shuriken)
            {
                this.health--;
                if (this.health < 0)
                {
                    this.Die();
                    return;
                }
            }
            ResetTongue();
            isHit = true;
            jumping = false;
            falling = false;
            fallCount = 0.0;
            jumpCount = 0.0;

            if (source.location.X > this.location.X)
            {
                //hit left
                this.currentHitState = HitState.hitLeft;
            }
            else
            {
                //hit right
                this.currentHitState = HitState.hitRight;
            }
        }
Example #15
0
 protected void DealDamage(RaycastHit ray, IHittable h, Projectiles.Projectile thisProjectile)
 {
     h.Hit(ray, thisProjectile, FinalDamage);
     OnDealDamage(h);
 }