// Update is called once per frame void Update() { switch (ghostStates) { case GhostStates.Idle: if (BadGuy.LineToPlayer(transform.position, 35f) && Time.time - timer > 4) { BadGuy.FollowPlayer(navMeshAgent); ghostStates = GhostStates.Charging; } break; case GhostStates.Charging: if (navMeshAgent.remainingDistance < 1) { timer = Time.time; ghostStates = GhostStates.Idle; } BadGuy.HitPlayer(transform.position, navMeshAgent.velocity.normalized); break; } }
public void EventCheck(string ColliderName, string CollidedWith, GameObject ob) { if (ColliderName == "claire" && power == 1) { PacState = PacManStates.SuperPM; } if (CollidedWith == "claire" && power == 0) { CurrentEvent = GameEvents.Hunting; player.gameObject.transform.position = new Vector3(4, 2, 1); player.SetActive(false); // Ghosthunting(); } if (ColliderName == "claire") { if (CollidedWith == "Sphere (11)" || CollidedWith == "Sphere (12)" || CollidedWith == "Sphere (13)" || CollidedWith == "Sphere (14)" || CollidedWith == "Sphere (15)" || CollidedWith == "Sphere (16)" || CollidedWith == "Sphere (17)" || CollidedWith == "Sphere (18)" || CollidedWith == "Sphere (19)") { CurrentEvent = GameEvents.EatCrum; } } if (ColliderName == "claire") { // Debug.Log("collider = " + col + " other obj = " + target); if (CollidedWith == "Capsule" || CollidedWith == "Capsule (1)" || CollidedWith == "Capsule (2)") { ob.gameObject.SetActive(false); CurrentEvent = GameEvents.EatSuperTab; } } switch (PacState) { case PacManStates.Spawned: // stateOFpac.text = "Spawned"; player.SetActive(true); // Spawned(); Debug.Log("Spawned entered"); CurrentEvent = GameEvents.GameStart; break; case PacManStates.Roaming: break; case PacManStates.SuperPM: if (CollidedWith == "StoneMonster (9)" && power == 1) { SM9.SetActive(false); SMtime = 500; } if (CollidedWith == "StoneMonster (8)" && power == 1) { // Debug.Log("here in power mode " + otherObj); SMtime = 500; SM8.SetActive(false); } if (CollidedWith == "StoneMonster (7)" && power == 1) { // Debug.Log("here in power mode " + otherObj); SM7.SetActive(false); SMtime = 500; } if (CollidedWith == "StoneMonster (6)" && power == 1) { // Debug.Log("here in power mode " + otherObj); SMtime = 500; SM6.SetActive(false); } break; case PacManStates.WinState: break; case PacManStates.Dead: if (life > 0) { // player.transform.position = new Vector3(4, 2, 1); // collision.gameObject.transform.position = new Vector3(4, 2, 1); life--; Debug.Log("Life Lost , lifes left =" + (life)); // PacState = PacManStates.Spawned; CurrentEvent = GameEvents.NewLife; // PacState = PacManStates.Spawned; } else if (life == 0) { life--; Destroy(player); } break; default: break; } switch (GhState) { case GhostStates.ghostrespawn: Ghostrespawn(); break; case GhostStates.Ghostroaming: // Debug.Log("roam ghost "); SM6.transform.Translate(Vector3.forward * Time.deltaTime / 3); SM7.transform.Translate(Vector3.forward * Time.deltaTime / 3); SM8.transform.Translate(Vector3.forward * Time.deltaTime / 3); SM9.transform.Translate(Vector3.forward * Time.deltaTime / 3); break; case GhostStates.Ghostscared: SM6.transform.Translate(Vector3.forward * Time.deltaTime / 2); SM7.transform.Translate(Vector3.forward * Time.deltaTime / 2); SM8.transform.Translate(Vector3.forward * Time.deltaTime / 2); SM9.transform.Translate(Vector3.forward * Time.deltaTime / 2); break; case GhostStates.GhostDead: CurrentEvent = GameEvents.TimeOut; break; } switch (CurrentEvent) { case GameEvents.NewLife: PacState = PacManStates.Spawned; break; case GameEvents.GameStart: PacState = PacManStates.Roaming; break; case GameEvents.EncByPacMan: // GhState = GhostStates.GhostDead; break; case GameEvents.EncByGhost: if (life > 0) { // player.transform.position = new Vector3(4, 2, 1); // collision.gameObject.transform.position = new Vector3(4, 2, 1); life--; Debug.Log("Life Lost , lifes left =" + (life)); // PacState = PacManStates.Spawned; } else if (life == 0) { life--; // Dead(); // PacState = PacManStates.Dead; } PacState = PacManStates.Dead; break; case GameEvents.EatCrum: if (ColliderName == "claire") { if (CollidedWith == "Sphere (11)" || CollidedWith == "Sphere (12)" || CollidedWith == "Sphere (13)" || CollidedWith == "Sphere (14)" || CollidedWith == "Sphere (15)" || CollidedWith == "Sphere (16)" || CollidedWith == "Sphere (17)" || CollidedWith == "Sphere (18)" || CollidedWith == "Sphere (19)") { // Debug.Log(crums); ob.gameObject.SetActive(false); //Destroy(col.gameObject); // transform.Rotate(0, 180, 0); // Debug.Log("rotated" + otherObj); crums = crums + 1; if (crums == 18) { CurrentEvent = GameEvents.CrumsFinished; // Winstate(); } } } break; case GameEvents.EatSuperTab: //Debug.Log("here " + otherObj); player.transform.localScale = new Vector3(2, 2, 2); // ob.gameObject.SetActive(false); time = 1000; power = 1; GhState = GhostStates.Ghostscared; break; case GameEvents.AllLivesLost: break; case GameEvents.CrumsFinished: break; case GameEvents.Run: break; case GameEvents.TimeOut: if (GhState == GhostStates.Ghostscared) { GhState = GhostStates.Ghostroaming; } //if (time < 0 && life >= 0) //{ // player.transform.localScale = new Vector3(1, 1, 1); // power = 0; // // GhostRoaming(); //} //else //{ // power = 1; // // Ghostscared(); //} break; case GameEvents.Hunting: PacState = PacManStates.Dead; break; } }
//pac fire event function public void pacFireEvent(GhostEvents e) { if (this.GhostCurrentState == GhostStates.chase_pacman) { switch (e) { case GhostEvents.pacman_eaten: this.GhostCurrentState = GhostStates.random_move; this.color = Color.blue; break; case GhostEvents.eat_supertablet: this.GhostCurrentState = GhostStates.run_from_player; this.color = Color.yellow; break; default: this.GhostCurrentState = GhostStates.chase_pacman; this.color = Color.green; break; } } else if (this.GhostCurrentState == GhostStates.random_move) { switch (e) { case GhostEvents.respawn: this.GhostCurrentState = GhostStates.chase_pacman; this.color = Color.green; break; default: this.GhostCurrentState = GhostStates.random_move; this.color = Color.blue; break; } } else if (this.GhostCurrentState == GhostStates.run_from_player) { switch (e) { case GhostEvents.timeout: this.GhostCurrentState = GhostStates.chase_pacman; this.color = Color.green; break; case GhostEvents.ghost_eaten: this.GhostCurrentState = GhostStates.die; this.color = Color.black; break; default: this.GhostCurrentState = GhostStates.run_from_player; this.color = Color.yellow; break; } } else if (this.GhostCurrentState == GhostStates.die) { switch (e) { case GhostEvents.new_generated: this.GhostCurrentState = GhostStates.rise; this.color = Color.cyan; break; default: this.GhostCurrentState = GhostStates.die; this.color = Color.black; break; } } else { switch (e) { case GhostEvents.exit_room: this.GhostCurrentState = GhostStates.chase_pacman; this.color = Color.green; break; default: inValid = true; break; } } }
//get current state of pacman public ghostFSM(GhostStates initial_State) { this.GhostCurrentState = initial_State; }
public void GhostInstantiated() { pacmanAttacking = FindObjectOfType <GhostStates>(); }
void Start() { pacmanAttacking = FindObjectOfType <GhostStates>(); UI = FindObjectOfType <HUD>(); }
void Start() { ghostStates = GhostStates.Idle; timer = 0; }
public void EventCheck(string ColliderName, string CollidedWith, GameObject ob) { // states switch (CurrentEvent) { case GameEvents.NewLife: PacState = PacManStates.Spawned; break; case GameEvents.GameStart: PacState = PacManStates.Roaming; break; case GameEvents.EncByPacMan: GhState = GhostStates.GhostDead; break; case GameEvents.EatCrum: if (ColliderName == "pacman") { totalCrums = totalCrums + 1; if (totalCrums == 200) { CurrentEvent = GameEvents.CrumsFinished; // Winstate(); PacState = PacManStates.WinState; } } break; case GameEvents.EatSuperTab: GhState = GhostStates.Ghostscared; PacState = PacManStates.SuperPM; break; case GameEvents.AllLivesLost: PacState = PacManStates.Dead; break; case GameEvents.CrumsFinished: PacState = PacManStates.WinState; break; case GameEvents.Run: PacState = PacManStates.Roaming; break; case GameEvents.TimeOut: if (GhState == GhostStates.Ghostscared) { GhState = GhostStates.Ghostroaming; } break; case GameEvents.Hunting: PacState = PacManStates.Dead; break; } }