示例#1
0
 void OnEnable()
 {
     EventManagerController.StartListening("SwallowMapItem", () =>
     {
         score += 100;
         gameObject.GetComponent <Text>().text = "Score: " + score;
     });
 }
示例#2
0
 void OnEnable()
 {
     EventManagerController.StartListening("SwallowMapItem", () =>
     {
         bSwallowedItem = true;
     });
     EventManagerController.StartListening("SwallowZumbi", () =>
     {
         bSwallowedZombie = true;
     });
 }
    void OnEnable()
    {
        EventManagerController.StartListening("SwallowZumbi", () =>
        {
            if (hasGameEnded)
            {
                return;
            }

            zumbiCount--;

            if (zumbiCount == 0)
            {
                this.levelFinishedUI.SetActive(true);

                hasGameEnded = true;

                Debug.Log("gg faggots :)");

                StartCoroutine(WaitForKeyPress(KeyCode.Return, () => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1)));
            }
        });
        EventManagerController.StartListening("SwallowMapItem", () =>
        {
            playerhomo.GetComponent <Healthbar>().HealDamage(1.0f);
        });
        EventManagerController.StartListening("TakeDamage", () =>
        {
            playerhomo.GetComponent <Healthbar>().TakeDamage(5.0f);
            playerhomo.GetComponent <AudioSource>().Play();
        });
        EventManagerController.StartListening("GameOver", () =>
        {
            if (hasGameEnded)
            {
                return;
            }

            this.levelFailedUI.SetActive(true);

            hasGameEnded = true;

            Debug.Log("Game over losers :)");

            StartCoroutine(WaitForKeyPress(KeyCode.F, () => Restart()));
        });
        EventManagerController.StartListening("EndGame", () =>
        {
            Debug.Log("damn you succ good bb <3");

            StartCoroutine(WaitForKeyPress(KeyCode.Return, () => SceneManager.LoadScene(0)));
        });
    }
示例#4
0
    /****************************************** PRIVATE METHODS ******************************************/

    void Grab()
    {
        if (!isHoldingItem)
        {
            Vector2      grabBox      = new Vector2(grabRadius, GetHeight());
            Collider2D[] gnomesToGrab = Physics2D.OverlapBoxAll(grabCenter.position, grabBox, 0f, whatCanBeGrabbed);

            foreach (Collider2D coll in gnomesToGrab)
            {
                coll.gameObject.transform.parent = gameObject.transform;

                GnomeController gnome = coll.gameObject.GetComponent <GnomeController> ();
                ClockController clock = coll.gameObject.GetComponent <ClockController> ();

                if (gnome != null)
                {
                    Vector3 newGnomePosition = gnomeHolster.position;
                    newGnomePosition.y += gnome.GetWidth();
                    coll.gameObject.transform.position = newGnomePosition;
                    gnome.Flip(90);
                    gnome.Freeze();

                    // Fix the scale
                    Vector3 gnomeScale = new Vector3(1.1f, 1.1f, 0.3f);
                    coll.gameObject.transform.localScale = gnomeScale;

                    currentGnome = coll.gameObject;
                    animator.SetBool("isCarrying", true);
                    this.isHoldingItem = true;
                }
                else if (clock != null)
                {
                    Vector3 newClockPosition = gnomeHolster.position;
                    newClockPosition.y += clock.GetHeight() / 4;
                    coll.gameObject.transform.position = newClockPosition;
                    clock.FixRotation();
                    clock.Freeze();

                    // Fix the scale
                    Vector3 clockScale = new Vector3(0.26f, 0.26f, 0.26f);
                    coll.gameObject.transform.localScale = clockScale;

                    animator.SetBool("isCarrying", true);
                    this.isHoldingItem = true;
                    currentClock       = coll.gameObject;
                    string name = currentClock.GetComponent <ClockController> ().GetName();
                    EventManagerController.FireClockSelectedEvent(name);
                }
            }
        }
    }
示例#5
0
    public void TakeDamage(float damage)
    {
        if (isGameOver)
        {
            return;
        }

        hitpoint -= damage;

        if (hitpoint <= 0)
        {
            hitpoint = 0;
            Debug.Log("rip elli cu in petah tikwa lol");
            isGameOver = true;
            EventManagerController.TriggerEvent("GameOver");
        }

        UpdateHealthbar();
    }
示例#6
0
    private void OnCollisionEnter(Collision col)
    {
        if (col.collider.gameObject.tag == "Player")
        {
            // Reduce health from player

            // Play the hit sound effect on the player because were destroying this object

            // Destroy the shell.
            Destroy(gameObject);
            EventManagerController.TriggerEvent("TakeDamage");
        }
        else
        {
            if (col.collider.gameObject.tag == "BRICC")
            {
                col.collider.gameObject.GetComponent <Rigidbody>().isKinematic = false;
            }

            Destroy(gameObject);
        }
    }
示例#7
0
    void FixedUpdate()
    {
        float   centerY     = transform.position.y + boxCollider.offset.y;
        Vector2 centerPoint = new Vector2(transform.position.x, centerY);

        Vector2 bedBox = new Vector2(boxCollider.size.x * 3.7f, 20f);

        Collider2D[] gnomesOnTheBed = Physics2D.OverlapBoxAll(centerPoint, bedBox, 0f, ThingsOnTheBed);
        gnomesOntheBedCount = gnomesOnTheBed.Length;
        EventManagerController.FireSetScoreEvent(gnomesOntheBedCount);

        foreach (Collider2D coll in gnomesOnTheBed)
        {
            GnomeController gnome = coll.gameObject.GetComponent <GnomeController> ();
            gnome.BeInBed();
        }

        if (gnomesOntheBedCount == 7)
        {
            EventManagerController.FireBedFullEvent();
        }
    }
示例#8
0
    void Throw()
    {
        if (isHoldingItem)
        {
            if (huhSound != null)
            {
                huhSound.Play();
            }

            if (currentGnome != null)
            {
                GnomeController gnome = currentGnome.GetComponent <GnomeController> ();
                currentGnome.transform.parent = null;
                gnome.UnFreeze();
                gnome.isMidAir = true;
                Rigidbody2D gnomeRb   = currentGnome.GetComponent <Rigidbody2D> ();
                float       direction = facingRight ? 1f : -1f;
                gnomeRb.velocity = new Vector2(7.5f * direction, 15f);
                isHoldingItem    = false;
                currentGnome     = null;
                animator.SetBool("isCarrying", false);
            }
            else if (currentClock)
            {
                ClockController clock = currentClock.GetComponent <ClockController> ();
                currentClock.transform.parent = null;
                clock.UnFreeze();
                Rigidbody2D clockRb   = currentClock.GetComponent <Rigidbody2D> ();
                float       direction = facingRight ? 1f : -1f;
                clockRb.velocity = new Vector2(7.5f * direction, 15f);
                isHoldingItem    = false;
                currentClock     = null;
                animator.SetBool("isCarrying", false);
                EventManagerController.FireClockSelectedEvent("");
            }
        }
    }
    void OnTriggerEnter(Collider collider)
    {
        var collidedGameObject = collider.gameObject;

        Debug.Log($"Elli triggers with {collidedGameObject.name}");

        // This piece of code is irrelevant as we now detect collision with a layer-based approach.
        // We don't have to programatically check for the Tag.

        /*if (destructionWhitelist.Contains(collidedGameObject.tag)) {
         *  Debug.Log("Triggered type of MefakedHaorvim. ignoring!");
         *  return;
         * }*/

        var fixedElliScale = new Vector3(gameObject.transform.parent.transform.localScale.x * gameObject.transform.localScale.x,
                                         gameObject.transform.parent.transform.localScale.y * gameObject.transform.localScale.y,
                                         gameObject.transform.parent.transform.localScale.z * gameObject.transform.localScale.z);
        var collidedGameObjScale = collidedGameObject.transform.localScale;

        // Tried getting the mesh filter, from which i can get the mesh, from which i wanted to get
        // the canvas (is it the correct hierarchy?) for the scaleFactor. That way we won't need the 0.01 HACK.
        // var collidedGameObjMesh = collidedGameObject.GetComponent<MeshFilter>().mesh;
        // var calcedCollidedObjScale = collidedGameObjScale * collidedGameObject.GetComponent<Canvas>().scaleFactor;

        // WE ACTUALLY DON'T NEED SCALE FACTOR AT THE MOMENT, SO IT APPEARS!

        // HACK: We hardcodedingly use '0.01' as our scaleFactor. But it's not desirable or anything near that..
        // var calcedCollidedObjScale = collidedGameObjScale * 1 / 0.01f; // lol
        var calcedCollidedObjScale = collidedGameObjScale * 1;

        if (calcedCollidedObjScale.magnitude > fixedElliScale.magnitude)
        {
            Debug.Log($"Elli is smaller than {collidedGameObject.name}.");
            Debug.Log($"Elli size = {fixedElliScale.ToString()}. {collidedGameObject.name} size = {calcedCollidedObjScale.ToString()}");
            return;
        }

        var gameObjectToDestroy = collidedGameObject.tag == "Enemy" ? collidedGameObject.transform.parent.gameObject : collidedGameObject;

        if (collider.gameObject.tag == "Zumbi")
        {
            collider.gameObject.GetComponent <StateController>().enabled = false;
            Destroy(collider.gameObject.GetComponent <NavMeshAgent>());
            EventManagerController.TriggerEvent("SwallowZumbi");
        }

        collidedGameObject.GetComponent <Rigidbody>().isKinematic = false;
        collidedGameObject.GetComponent <Rigidbody>().useGravity  = true;

        var scaleFactor = 0.2f;

        if (collidedGameObject.tag == "BRICC")
        {
            Debug.Log("BRICCD");
            collidedGameObject.layer = 8;
            scaleFactor = 0.0045f;
        }

        Debug.Log($"Destroying {gameObjectToDestroy.name}...");
        Destroy(gameObjectToDestroy, 20.0f);
        gameObject.transform.parent.transform.localScale += new Vector3(calcedCollidedObjScale.x, 0, calcedCollidedObjScale.z) * scaleFactor;
        EventManagerController.TriggerEvent("SwallowMapItem");
        // gameObject.transform.parent.SendMessage("HealDamage", 1.0f);
    }