Exemplo n.º 1
0
    public bool TakeDamage()
    {
        if (damageCooldown > 0f)
        {
            return(false);
        }
        mySprite.color = Color.red;
        damageCooldown = 0.1f;

        SoundeffectsManager.PlayEffect("slap");


#if UNITY_EDITOR
        // return true;
#endif
        hitPoints -= 1;

        if (hitPoints <= 0)
        {
            dead           = true;
            hateDistance   = 0;
            mySprite.color = Color.black;
            StartCoroutine(restartLevel());
            SoundeffectsManager.PlayEffect("death");
        }
        return(true);
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        bool shouldOpen = CheckOpen();

        if (shouldOpen)
        {
            if (!gateOpen)
            {
                if (render.isVisible)
                {
                    SoundeffectsManager.PlayEffect("gateup");
                }

                coll.enabled  = false;
                render.sprite = openGate;
                gateOpen      = true;
            }
        }
        else
        {
            coll.enabled  = true;
            render.sprite = closedGate;
            gateOpen      = false;
        }
    }
Exemplo n.º 3
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            PlayerCharacterWalking.playerToonScript.TakeDamage();
            return;
        }

        if (other.gameObject.tag == "Badguys")
        {
            SoundeffectsManager.PlayEffect("gargoyle_death");
            if (other.GetComponent <Gargoyle>() != null)
            {
                other.gameObject.GetComponent <Gargoyle>().Death();
            }
            if (other.GetComponent <GoblinSpearthrower>() != null)
            {
                other.gameObject.GetComponent <GoblinSpearthrower>().Death();
            }
            if (other.GetComponent <BarrelDoodad>() != null)
            {
                other.gameObject.GetComponent <BarrelDoodad>().Death();
            }
            if (other.GetComponent <PlayerHunter>() != null)
            {
                other.gameObject.GetComponent <BarrelDoodad>().Death();
            }
            return;
        }
    }
Exemplo n.º 4
0
    IEnumerator coinGrab()
    {
        GetComponent <CircleCollider2D>().enabled = false;
        yield return(new WaitForSeconds(0.1f));

        PlayerCharacterWalking.pickupCoin();
        GetComponent <SpriteRenderer>().enabled = false;
        SoundeffectsManager.PlayEffect("coin");
    }
Exemplo n.º 5
0
    IEnumerator spawnBarrel()
    {
        SoundeffectsManager.PlayEffect("coin");
        yield return(new WaitForSeconds(1f));

        SoundeffectsManager.PlayEffect("vending");
        Vector2     spawnpoint = new Vector2(transform.position.x, transform.position.y - 2);
        GameObject  dropped    = GameObject.Instantiate(spawns, spawnpoint, Quaternion.identity, null);
        Rigidbody2D dropflow   = dropped.GetComponent <Rigidbody2D>();// dropped.AddComponent<Rigidbody2D>();

        dropflow.AddForce(Vector2.down * 30f);
    }
Exemplo n.º 6
0
    void AttackPlayer()
    {
        SoundeffectsManager.PlayEffect("lich_attack");
        attackCooldown = 0.4f;
        if (!PlayerCharacterWalking.playerToonScript.TakeDamage())
        {
            return;
        }
        float damageForce = 800f;

        PlayerCharacterWalking.playerToon.GetComponent <Rigidbody2D>().AddForce(direction * damageForce);
    }
Exemplo n.º 7
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            PlayerCharacterWalking.coins        -= 5;
            PlayerCharacterWalking.hateDistance -= 5 * PlayerCharacterWalking.RadiusPerCoin;
            PlayerCharacterWalking.hitPoints    += 1;

            SoundeffectsManager.PlayEffect("lifeup");

            Death();
            return;
        }
    }
Exemplo n.º 8
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (activated)
     {
         return;
     }
     if (collision.gameObject.GetComponent <PlayerCharacterWalking>() != null)
     {
         SoundeffectsManager.PlayEffect("lifeup");
         activated = true;
         GetComponent <SpriteRenderer>().sprite = awoken;
         collision.gameObject.GetComponent <PlayerCharacterWalking>().originPosition = collision.gameObject.transform.position;
         StoredGold = PlayerCharacterWalking.coins;
     }
 }
Exemplo n.º 9
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (!immuneDiesOnCollissionWithSelf)
     {
         return;
     }
     if (!charging)
     {
         return;
     }
     if (collision.gameObject.GetComponent <Gargoyle>() != null)
     {
         SoundeffectsManager.PlayEffect("gargoyle_death");
         collision.gameObject.GetComponent <Gargoyle>().Death();
         Death();
     }
 }
Exemplo n.º 10
0
    void FixedUpdate()
    {
        if (!mySprite.isVisible)
        {
            return;
        }
        if (PlayerCharacterWalking.playerToon == null)
        {
            return;
        }
        if (ExitStairs.gamePaused)
        {
            return;
        }
        if (dead)
        {
            return;
        }
        if (attackCooldown > 0f)
        {
            // mySprite.sprite = hunting;
            attackCooldown -= Time.fixedDeltaTime;
            return;
        }

        float   speedboost     = 1f;
        Vector2 goodguyThisWay = PlayerCharacterWalking.playerToon.transform.position - transform.position;

        Vector2 walkThisWay = (Vector2)targetPoint.position - (Vector2)transform.position;

        if (goodguyThisWay.magnitude <= PlayerCharacterWalking.hateDistance)
        {
            walkThisWay = (Vector2)PlayerCharacterWalking.playerToon.transform.position - (Vector2)transform.position;
            if (goodguyThisWay.magnitude < 0.8f)
            {
                AttackPlayer();
                return;
            }
            speedboost = (PlayerCharacterWalking.coins * 0.2f) + 1f;
        }

        Vector2 pointDistance = (Vector2)routePoints[0].position - (Vector2)routePoints[1].position;

        if (pointDistance.magnitude < 1.4f)
        {
            foreach (Transform tr in routePoints)
            {
                if (tr.GetComponent <Gargoyle>() != null)
                {
                    tr.GetComponent <Gargoyle>().Death();
                }
                if (tr.GetComponent <BarrelDoodad>() != null)
                {
                    tr.GetComponent <BarrelDoodad>().Death();
                }
            }

            SoundeffectsManager.PlayEffect("gargoyle_death");
            Death();
            return;
        }


        var distance = walkThisWay.magnitude;

        direction = walkThisWay / distance;

        if (distance < 1f)
        {
            foreach (Transform ral in routePoints)
            {
                if (ral != targetPoint)
                {
                    targetPoint = ral; break;
                }
            }
        }

        float monsterWalkSpeed = 0.5f + (0.3f * PlayerCharacterWalking.hateDistance) * speedboost;

        rb2d.MovePosition(rb2d.position + direction * Time.fixedDeltaTime * monsterWalkSpeed);
        mySprite.flipX = (direction.x > 0);

        /*
         *
         * mySprite.sprite = sleeping;
         *
         * attackRange = 1f + Charge * 3f;
         *
         * Vector2 goodguyThisWay = PlayerCharacterWalking.playerToon.transform.position - transform.position;
         *
         * if (goodguyThisWay.magnitude > PlayerCharacterWalking.hateDistance)
         * {
         *  if (Charge > 0) Charge -= Time.deltaTime * 0.35f;
         *  mySprite.color = new Color(1f - Charge, 1f - Charge, 1f);
         *  return;
         * }
         * var distance = goodguyThisWay.magnitude;
         * direction = goodguyThisWay / distance;
         *
         * if (goodguyThisWay.magnitude < attackRange)
         * {
         *  AttackPlayer();
         *  return;
         * }
         *
         * Charge += Time.deltaTime * 0.2f;
         * mySprite.color = new Color(1f - Charge, 1f - Charge, 1f);
         * mySprite.flipX = (direction.x > 0);
         */
    }
Exemplo n.º 11
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!mySprite.isVisible)
        {
            return;
        }
        if (PlayerCharacterWalking.playerToon == null)
        {
            return;
        }
        if (ExitStairs.gamePaused)
        {
            return;
        }
        if (dead)
        {
            return;
        }
        if (attackCooldown > 0f)
        {
            attackCooldown -= Time.fixedDeltaTime;
            return;
        }

        if (charging)
        {
            Charge         -= Time.deltaTime;
            mySprite.sprite = hunting;

            if (Charge >= 0.6f)
            {
                mySprite.color = (mySprite.color == Color.red ? Color.white : Color.red);
                return;
            }

            float monsterWalkSpeed = 7.5f + (0.3f * PlayerCharacterWalking.hateDistance);

            //Vector2 velocity = new Vector2(moveHorizontal, moveVertical) * 5f;
            rb2d.MovePosition(rb2d.position + direction * Time.fixedDeltaTime * monsterWalkSpeed);
            mySprite.flipX = (direction.x > 0);


            Vector2 goodguyNearby = PlayerCharacterWalking.playerToon.transform.position - transform.position;
            if (goodguyNearby.magnitude < 0.8f)
            {
                AttackPlayer();
                Charge = 0;
                return;
            }

            if (Charge <= 0)
            {
                charging         = false;
                gameObject.layer = LayerMask.NameToLayer("Movable");
            }
            return;
        }
        mySprite.sprite = sleeping;

        Vector2 goodguyThisWay = PlayerCharacterWalking.playerToon.transform.position - transform.position;

        if (goodguyThisWay.magnitude > PlayerCharacterWalking.hateDistance)
        {
            if (Charge > 0)
            {
                Charge -= Time.deltaTime * 0.15f;
            }
            mySprite.color  = new Color(1f, 1f - Charge, 1f - Charge);
            mySprite.sprite = sleeping;
            return;
        }

        Charge += Time.deltaTime * 0.2f;

        mySprite.color = new Color(1f, 1f - Charge, 1f - Charge);

        if (Charge >= 1)
        {
            SoundeffectsManager.PlayEffect("gargoyle_dash");
            var distance = goodguyThisWay.magnitude;
            direction        = goodguyThisWay / distance;
            charging         = true;
            gameObject.layer = LayerMask.NameToLayer("Evil");
        }

        return;

        mySprite.sprite = hunting;
    }