// 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++; }
void Move(int dx, int dy) { if (gsm.state != GameStateManager.State.GAME_MODE_PLAY) { animator.SetBool("IsRunning", false); rb.velocity = Vector2.zero; return; } if (dx != 0 || dy != 0) { rb.velocity = new Vector2(dx, dy) * speed; } animator.SetBool("IsRunning", (rb.velocity.x != 0 || rb.velocity.y != 0)); if (Random.value < Time.deltaTime) { if (aCat.flee > 0) { sound.BigSqueak(); } else { sound.Squeak(); } } //Teleport int x = Mathf.RoundToInt(transform.position.x); int y = Mathf.RoundToInt(transform.position.y); if (y == 32) { if (x == 14 && rb.velocity.x > 0) { x = 32; transform.position = new Vector3(x, y, transform.position.z); } else if (x == 32 && rb.velocity.x < 0) { x = 14; transform.position = new Vector3(x, y, transform.position.z); } } //correct position if (dx != 0) { transform.position = new Vector3(transform.position.x, y, transform.position.z); } if (dy != 0) { transform.position = new Vector3(x, transform.position.y, transform.position.z); } //correct rotation if (dx > 0) { transform.rotation = Quaternion.Euler(0, 0, -90); } if (dx < 0) { transform.rotation = Quaternion.Euler(0, 0, 90); } if (dy > 0) { transform.rotation = Quaternion.Euler(0, 0, 0); } if (dy < 0) { transform.rotation = Quaternion.Euler(0, 0, 180); } }