private void CheckCollision() { float dis = Vector3.Distance(GetPostition(), pacMan.GetPosition()); if (dis < 1.0f) { if (IsCanBeConsumed()) { Consumed(); } if (IsCanConsumePacman()) { gameBoard.StartDeath(); } } }
// Update is called once per frame void Update() { if (!HandleInput()) { Application.Quit(); return; } if (Map.DotCount == 0) { return; } else if (lives <= 0) { return; } MoveAatar(); for (int g = 0; g < Ghosts.Count; g++) { Ghosts[g].onUpdate(Map, Avatar); } if (Map.HasIntersectedDot(Avatar.GetPosition())) { UpdateScore(10); if (Map.DotCount == 0) { } } myGhostGhostCounter -= Time.deltaTime; if (Map.HasIntersectedBigDot(Avatar.GetPosition())) { UpdateScore(20); myGhostGhostCounter = 20.0f; for (int g = 0; g < Ghosts.Count; g++) { Ghosts[g].isClaimable = true; } } if (myGhostGhostCounter <= 0) { for (int g = 0; g < Ghosts.Count; g++) { Ghosts[g].isClaimable = false; } } for (int g = 0; g < Ghosts.Count; g++) { if ((Ghosts[g].GetPosition() - Avatar.GetPosition()).magnitude < 16.0f) { if (myGhostGhostCounter <= 0.0f) { UpdateLives(lives - 1); if (lives > 0) { Avatar.Respawn(new Vector2(13 * 22, 16 * 22)); Ghosts[g].Respawn(new Vector2(13 * 22, 13 * 22)); break; } else { GameOver(); return; } } else { UpdateScore(50); Ghosts[g].isDead = true; Ghosts[g].Die(Map); } } } }