Exemplo n.º 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            if (player && flee > 0)
            {
                //Eat the cat!
                score.Add(player.GetCatValue());

                GameObject g = Instantiate(pointsPrefab);
                g.transform.position = transform.position;
                Points p = g.GetComponent <Points>();
                p.points = player.GetCatValue();
                p.color  = GetComponent <SpriteRenderer>().color;

                player.DoubleCatValue();
                sound.BigGulp();
                ResetEnemy();
                delay = 10;
            }
            else
            {
                gsm.state = GameStateManager.State.GAME_MODE_DEATH;
            }
        }
    }
Exemplo n.º 2
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     Debug.Log("Trigger: " + collision.gameObject.name);
     if (collision.gameObject.tag == "Player")
     {
         if (pointValue < 0)
         {
             gsm.state = GameStateManager.State.GAME_MODE_DEATH;
         }
         else
         {
             //Eat the pickup!
             sound.BigGulp();
             GameObject g = Instantiate(pointsPrefab);
             Points     p = g.GetComponent <Points>();
             p.color              = new Color(0, 0, 1, 0);
             p.points             = pointValue;
             g.transform.position = transform.position;
             score.Add(pointValue);
             Destroy(gameObject);
         }
     }
 }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        float x = 35f / 2f * Mathf.Sin(Mathf.PI / 40f * frame - Mathf.PI / 4f) + 55f / 2f;
        float y = -2f / 5f * frame + 64;

        if (frame < 160)
        {
            mouse.transform.position = new Vector3(x, y, 0);
            float xt = x - lastx;
            float yt = y - lasty;
            mouse.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(yt, xt) * 180f / Mathf.PI - 90);
            lastx = x;
            lasty = y;

            //make the cat face the mouse
            xt = x - cat.transform.position.x;
            yt = y - cat.transform.position.y;
            cat.transform.localRotation = Quaternion.Euler(0, 0, Mathf.Atan2(yt, xt) * 180f / Mathf.PI - 90);

            //...and move in the direction it faces
            cat.GetComponent <Rigidbody2D>().velocity = new Vector2(xt, yt).normalized * 40;
        }

        if (frame == 160)
        {
            Destroy(cheese);
            mouse.transform.localScale = new Vector3(2, 2, 1);

            //face the cat before eating it
            mouse.transform.rotation = Quaternion.Euler(0, 0, -45);
        }

        if (frame == 168)
        {
            Destroy(cat);
        }

        if (frame == 30)
        {
            sound.Squeak();
        }
        if (frame == 60)
        {
            sound.Meow();
        }
        if (frame == 90)
        {
            sound.Squeak();
        }
        if (frame == 120)
        {
            sound.Squeak();
        }
        if (frame == 150)
        {
            sound.Meow();
        }
        if (frame == 160)
        {
            sound.Gulp();
        }
        if (frame == 168)
        {
            sound.BigGulp();
        }
        if (frame == 180)
        {
            sound.BigSqueak();
        }
        if (frame == 240)
        {
            sound.BigSqueak();
        }
        if (frame == 300)
        {
            sound.BigSqueak();
        }

        if (frame == 0)
        {
            music.PlayTune("R16 O4 E- G- O5 E- F E- O4 B- G-"
                           + "E  E- G- O5 E- F E- O4 B- G-"
                           + "E  E- G- O5 E- F E- O4 B- G- R4 E-");
        }

        if (frame == 350)
        {
            FindObjectOfType <GameStateManager>().state =
                GameStateManager.State.GAME_MODE_START_LEVEL;
        }

        frame++;
    }