public event PacmanDiedEventHandler PacmanDiedEvent; //event encapsulating pacman died event /// <summary> /// The Ghost constructor will take as input a GameState object /// in order to get information about the pacman object, the maze /// and the pen of the ghosts. The constructor will also initialize /// the position fo the ghost, its target relative to Pacman's position, /// a ghoststate enum and a color of the ghost with the input with /// the input values passed to the method. An exception will be thrown /// if the gamestate object passed is null or if the target's x or y /// values are negative /// </summary> /// <param name="g">A GameState object</param> /// <param name="x">the int x coordinates of the ghost position</param> /// <param name="y">the int y coordinates of the ghost position</param> /// <param name="target">the vector target of the ghost</param> /// <param name="start">the ghoststate enum of the ghost</param> /// <param name="c">the color of the ghost</param> public Ghost(GameState g, int x, int y, Vector2 target, GhostState start, Enums.Color c) { if (Object.ReferenceEquals(null, g)) { throw new ArgumentException("The input GameState object passed to the Ghost constructor must not be null"); } if (x < 0 || y < 0) { throw new ArgumentException("The Ghost's x and y position must be negative"); } this.pacman = g.Pacman; this.maze = g.Maze; this.pen = g.Pen; this.target = target; this.colour = c; this.position = new Vector2(x, y); if (start == GhostState.Scared) { this.currentState = new Scared(this, this.maze); } if (start == GhostState.Chasing) { this.currentState = new Chase(this, this.maze, this.target, this.pacman); } if (start == GhostState.Penned) { this.currentState = new Penned(); } this.points = 200; //default points set to 200 }
/// <summary> /// ChangeState method will take as input a GhostState enum /// and will change the state of the ghost object corresponding to /// that input GhostState enum /// </summary> /// <param name="g">A ghoststate enum</param> public void ChangeState(GhostState g) { switch (g) { case GhostState.Scared: this.currentState = new Scared(this, this.maze); break; case GhostState.Chasing: this.currentState = new Chase(this, this.maze, this.target, this.pacman); break; case GhostState.Released: if (this.CurrentState != GhostState.Scared) { this.currentState = new Chase(this, this.maze, this.target, this.pacman); } this.Position = ReleasePosition; this.CheckCollisions(this.pacman.Position); break; case GhostState.Penned: if (this.CurrentState != GhostState.Scared) { this.currentState = new Penned(); } break; default: this.currentState = new Chase(this, this.maze, this.target, this.pacman); break; } }
public void SetFrightened() { if (!(state is DeadState || state is GoingHomeState)) { SoundManager.instance.PlaySingle(frightned, 3); state.Exit(this); state = new FrightnedState(this); state.Start(this); } }
void FixedUpdate() { var nextState = state.Update(this); if (nextState != null) { state.Exit(this); state = nextState; state.Start(this); } direction = Vector2Int.FloorToInt((target - body.position).normalized); if (state is FrightnedState) { animator.SetTrigger("frightned"); } else if (state is GoingHomeState) { if (direction == Vector2Int.right) { animator.SetTrigger("deadright"); } else if (direction == Vector2Int.down) { animator.SetTrigger("deaddown"); } else if (direction == Vector2Int.up) { animator.SetTrigger("deadup"); } else { animator.SetTrigger("deadleft"); } } else { if (direction == Vector2Int.right) { animator.SetTrigger("right"); } else if (direction == Vector2Int.down) { animator.SetTrigger("down"); } else if (direction == Vector2Int.up) { animator.SetTrigger("up"); } else { animator.SetTrigger("left"); } } }
public void ChangeState(IGhostState stateParam) { if(currentState is Chase) { currentState = new Scared(this, this.maze); } else if(currentState is Scared) { Reset(); } }
//private void SetDefaultNonParameterMemberVariables() //{ // //myGhostHealthState = GhostHealthState.Alive; // //ChangeState(new SAlive()); //} public void ChangeState(IGhostState aState) { if (CurrentBehaviour == aState) { return; } if (CurrentBehaviour != null) { CurrentBehaviour.Exit(this); } CurrentBehaviour = aState; aState.Enter(this); }
// Use this for initialization protected virtual void Start() { var playerGameObject = GameObject.FindGameObjectWithTag("Player"); WarpIn = GameObject.Find("WarpIn"); WarpOut = GameObject.Find("WarpOut"); gridTiles = GameManager.instance.InitGrid(TileMap); body = GetComponent <Rigidbody2D>(); animator = GetComponent <Animator>(); playerBody = playerGameObject.GetComponent <Rigidbody2D>(); player = playerGameObject.GetComponent <Player>(); spriteRenderer = GetComponent <SpriteRenderer>(); warpInPositionVector2 = new Vector2(WarpIn.transform.position.x, WarpIn.transform.position.y); warpOutPositionVector2 = new Vector2(WarpOut.transform.position.x, WarpOut.transform.position.y); SpawningLocation = body.position; state = new DeadState(this); }
/// <summary> /// Changes the state of a ghost /// </summary> /// <param name="state">The state in which the ghost is changed to</param> public void ChangeState(GhostState state) { this.CurrentState = state; switch (state) { case GhostState.Scared: currentState = new Scared(this, this.maze); break; case GhostState.Chase: switch (Name) { case GhostName.Blinky: this.currentState = new Chase(this, maze, pacman); break; case GhostName.Speedy: this.currentState = new Ambush(this, maze, pacman); break; case GhostName.Inky: this.currentState = new Predict(this, GhostAssistant, maze, pacman); break; case GhostName.Clyde: this.currentState = new Proximity(this, maze, pacman); break; } break; case GhostState.Released: position = ReleasePosition; ChangeState(GhostState.Chase); break; case GhostState.Zombie: currentState = new Zombie(this, this.maze, pen.Entrance); break; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { if (state is FrightnedState) { GameManager.instance.AddScore(200); GameManager.instance.PauseGame(0.5f); SoundManager.instance.PlaySingle(eatGhost, 2); state.Exit(this); state = new GoingHomeState(this); state.Start(this); } else if (!(state is GoingHomeState)) { SoundManager.instance.PlaySingle(playerDead, 2); GameManager.instance.PauseGame(10f); GameManager.instance.GameOver(); SoundManager.instance.StopMusic(); player.Die(); } } }
/// <summary> /// The method ChangeState take an Enum type GhostState and change /// the state of our current ghost depending the state given. /// Also, if we switch to scare mode a timer is activated and the ghosts are feared /// for 9 seconds. /// </summary> /// <param name="state">state is an Enum that represent the new state that we gonna give to our ghost</param> public void ChangeState(GhostState state) { switch (state) { case GhostState.Chase: this.state = GhostState.Chase; currentState = new Chase(this, maze, pacman, pacman.Position); break; case GhostState.Scared: this.state = GhostState.Scared; currentState = new Scared(this, maze); scared.Interval = 7000; scared.Enabled = true; scared.Elapsed += UpdateState; break; case GhostState.Released: this.state = GhostState.Chase; currentState = new Chase(this, maze, pacman, pacman.Position); this.Position = ReleasedPos; break; } }
/// <summary> /// Changes the state of the ghost to scared/released/chase, depending on the parameter. /// </summary> /// <param name="stateParam">The state we want to set the ghost into</param> public void ChangeState(GhostState stateParam) { if (stateParam == GhostState.Scared) { currentState = new Scared(this, maze); colour = Color.White; scaredTime.Enabled = false; scaredTime.Enabled = true; } else if (stateParam == GhostState.Chase) { currentState = new Chase(this, maze, pacman, target); colour = originalClr; } else if (stateParam == GhostState.Released) { currentState = new Chase(this, maze, pacman, target); this.Position = Ghost.releasedPosition; colour = originalClr; stateParam = GhostState.Chase; } CurrentState = stateParam; }
public LeafNode(IGhostState aState) { myState = aState; }
public void Reset() { currentState = new Chase(this, this.maze, this.pacman, this.target); }
//public Ghost() { } public Ghost(GameState G, int X, int y, Vector2 target,IGhostState start, String color) { scared.Start(); }
public Ghost(GameState g, int x, int y, Vector2 target, IGhostState start, int color) { }