Example #1
0
 /// <summary>
 /// Put the ghosts back in their home, ready to begin a new attack
 /// </summary>
 /// <param name="newLevel">True at level start, false otherwise</param>
 /// <param name="player">The pac man. Pac Man is often respawned with the ghosts, so they need to know about the new Pac Man.</param>
 public void Reset(bool newLevel, Player player)
 {
     State          = EGhostState.Home;    // Ghosts start at home
     previousState_ = EGhostState.Home;    // Sounds are played when currentState != previousState.
     // So to get them playing at level start, we do this simple hack.
     updateCount_       = 0;
     initialJumps_      = Constants.InitialJumps(GhostType, newLevel);
     position_          = Constants.startPosition(GhostType);
     scheduleStateEval_ = true;
     lastJunction_      = new Point();
     player_            = player;
     scatterModesLeft_  = 4;
     UpdateSpeed();
 }
Example #2
0
    IEnumerator SpawnObject()
    {
        yield return(new WaitForSeconds(m_ghostDelayTime));

        float showspeed = Vector3.SqrMagnitude(m_GhostMoveTarget.position - m_GhostSpawnLocator.position) / m_ghostShowTime;

        while (m_curExtent < m_extent)
        {
            MoveGhost(showspeed);
            ExpendGhost(showspeed);

            yield return(new WaitForSeconds(Time.deltaTime));
        }
        m_ghostState = DragonGhost.EGhostState.EGS_CATCHABLE;
        yield break;
    }
Example #3
0
        void StateEval()
        {
            EGhostState initialState = State;

            scheduleStateEval_ = false;

            switch (State)
            {
            case EGhostState.Home:
                // Ghost exit the home state for the scatter state when they get to the row
                // above the home
                if (position_.Tile.Y == 11 && position_.DeltaPixel.Y == 0)
                {
                    // Select inital direction based on scatter tiles
                    if (Constants.scatterTiles(GhostType)[0].X < 13)
                    {
                        direction_ = EDirection.Left;
                    }
                    else
                    {
                        direction_ = EDirection.Right;
                    }
                    if (scatterModesLeft_ > 0)
                    {
                        State = EGhostState.Scatter;
                    }
                    else
                    {
                        State = EGhostState.Attack;
                    }
                    return;
                }
                // Ghosts move up when they are aligned with the entrance
                else if (position_.Tile.X == 13 && position_.DeltaPixel.X == 8)
                {
                    direction_ = EDirection.Up;
                }
                // When on one side, move towards middle when on the bottom and time's up
                // If time's not up, keep bouncing up and down
                else if ((position_.DeltaPixel.Y == 8) &&
                         ((position_.Tile.X == 11 && position_.DeltaPixel.X == 8) ||
                          (position_.Tile.X == 15 && position_.DeltaPixel.X == 8)))
                {
                    if (position_.Tile.Y == 14)
                    {
                        initialJumps_--;
                        if (initialJumps_ == 0)
                        {
                            if (position_.Tile.X == 11)
                            {
                                direction_ = EDirection.Right;
                            }
                            else
                            {
                                direction_ = EDirection.Left;
                            }
                        }
                        else
                        {
                            direction_ = EDirection.Up;
                        }
                    }
                    else if (position_.Tile.Y == 13)
                    {
                        direction_ = EDirection.Down;
                    }
                }
                break;

            case EGhostState.Scatter:
                // Attempt to reverse direction upon entering this state
                if (previousState_ == EGhostState.Attack)
                {
                    scatterModesLeft_--;
                    if (NextTile(OppositeDirection(direction_)).IsOpen)
                    {
                        direction_ = OppositeDirection(direction_);
                    }
                }
                AIScatter();
                int timeInScatterMode = scatterModesLeft_ <= 2 ? 5 : 7;
                if ((DateTime.Now - timeInCurrentState) > TimeSpan.FromSeconds(timeInScatterMode))
                {
                    State = EGhostState.Attack;
                }
                break;

            case EGhostState.Dead:
                // Attempt to reverse direction upon entering this state
                if (previousState_ != EGhostState.Dead && previousState_ != EGhostState.Blue)
                {
                    if (NextTile(OppositeDirection(direction_)).IsOpen)
                    {
                        direction_ = OppositeDirection(direction_);
                    }
                }
                else
                {
                    AIDead();
                }
                if (position_.DeltaPixel.X == 8 && position_.DeltaPixel.Y == 8)
                {
                    if (position_.Tile.Y == 14)
                    {
                        State = EGhostState.Home;
                    }
                }
                break;

            case EGhostState.Attack:
                // Attempt to reverse direction upon entering this state
                if (previousState_ != EGhostState.Attack && previousState_ != EGhostState.Blue)
                {
                    if (NextTile(OppositeDirection(direction_)).IsOpen)
                    {
                        direction_ = OppositeDirection(direction_);
                    }
                }
                else
                {
                    AIAttack();
                }

                if ((DateTime.Now - timeInCurrentState) > TimeSpan.FromSeconds(20))
                {
                    State = EGhostState.Scatter;
                }
                break;

            case EGhostState.Blue:
                // Attempt to reverse direction upon entering this state
                if (previousState_ != EGhostState.Blue)
                {
                    if (NextTile(OppositeDirection(direction_)).IsOpen)
                    {
                        direction_ = OppositeDirection(direction_);
                    }
                }
                else
                {
                    // TODO : make special blue AI
                    AIAttack();
                }

                // When blue time is over, revert to attack mode.
                if ((DateTime.Now - timeInCurrentState) > TimeSpan.FromSeconds(Constants.BlueTime()))
                {
                    State = EGhostState.Attack;
                }
                break;
            }

            // TODO : move all these magic numbers to the Constants class.
            // We select a new sound only upon some state change, or when
            // the number of crumps goes below certain thresholds.
            if ((initialState != previousState_) ||
                (Grid.NumCrumps == 199 && previousNumCrumps_ == 200) ||
                (Grid.NumCrumps == 19 && previousNumCrumps_ == 20))
            {
                PlaySound();
            }
            previousState_ = initialState;
        }