示例#1
0
    /// <summary>
    /// When Pac Man hits a Ghost.
    /// </summary>
    /// <param name="Ghost">The Ghost that Pac Man collided with.</param>

    void OnHitGhost(GameObject Ghost)
    {
        GhostMechanics ghost = Ghost.GetComponent <GhostMechanics>();

        if (ghost.ScaredState)          //  If the ghost is scared.
        {
            OnHitScaredGhost(ghost);    //  Kill that ghost.
        }
        else
        {
            PacManIsDead();             //  Otherwise, kill Pac Man.
        }
        PlayerStats.SaveGame();
    }
示例#2
0
    void Start()
    {
        Mechanics = GetComponent <GhostMechanics>();

        if (!Mechanics)
        {
            Debug.LogWarning("Ghost with ID: " + GhostID + " does not have a <GhostMecahnics> component!");
        }
        else
        {
            RespawnPoint = Mechanics.RespawnPoint; //  Assigns this GhostController's respawn point to the same one in this Ghost's GhostMechanics.
        }
        StartSequence();                           //  Begins the starting sequence to begin/restart the game.
    }
示例#3
0
    /// <summary>
    /// When Pac Man hits a big pellet.
    /// </summary>
    /// <param name="BigPellet">The big pellet that Pac Man collided with.</param>

    void EatBigPellet(GameObject BigPellet)
    {
        Destroy(BigPellet);         //  Remove the Big Pellet from the game.
        PlayerStats.score += 50;
        PlaySound("EATFRUIT");      //  Play the sound of Pac Man eating a Fruit/Big Pellet.
        StopSound("AMBIENT");       //  Stops the ambient from playing.

        for (int i = 0; i < 4; i++) //  For every ghost in the game.
        {
            GhostMechanics gc = GhostHolder.GetChild(i).gameObject.GetComponent <GhostMechanics>();
            if (gc.IsAlive)         //  If that ghost is alive.
            {
                gc.SetScared(true); //  Set that ghost to a scared state.
            }
        }
    }
示例#4
0
    /// <summary>
    /// Determins the sound that needs to be played according to the other Ghost's states.
    /// </summary>

    void DetermineSound()
    {
        GameObject[] Ghosts = GameObject.FindGameObjectsWithTag("Ghost");  //  Find all the Ghosts in the level.
        bool         OneScared = false, OneDead = false;                   //  If at least one is scared and if at least one is dead.

        for (int i = 0; i < Ghosts.Length; i++)                            //  For every Ghost in the level.
        {
            GhostMechanics GM = Ghosts[i].GetComponent <GhostMechanics>(); //  Get the Ghost's GhostMechanics.cs component.

            if (GM.ScaredState)                                            //  If this Ghost is scared.
            {
                OneScared = true;                                          //  At least one Ghost is scared.
            }
            if (!GM.IsAlive)                                               //  If this Ghost is not alive.
            {
                OneDead = true;                                            //  At least one Ghost is dead.
            }
        }

        if (OneScared && !OneDead)  //  When at least one Ghost is scared, but no Ghosts are dead.
        {
            PlaySound("GHOSTSCAREDSTATE");
            StopSound("DEAD");
            StopSound("AMBIENT");
            return;
        }

        if (OneScared && OneDead)   //  When at least one Ghost is scared and one Ghost is dead.
        {
            StopSound("GHOSTSCAREDSTATE");
            StopSound("AMBIENT");
            PlaySound("DEAD");
            return;
        }

        if (!OneScared && !OneDead) //  When there are no Ghosts who are scared or dead.
        {
            StopSound("GHOSTSCAREDSTATE");
            StopSound("DEAD");
            PlaySound("AMBIENT");
        }
    }
示例#5
0
    /// <summary>
    /// Resets the game to the necessary default values.
    /// </summary>

    void ResetGame()
    {
        IsAlive = true;                                     //  Sets Pac Man to be alive.
        DeadStateAnim.SetBool("PacManIsDead", false);       //  Stop Pac Man's death animation.
        moveSpeed          = DefaultMoveSpeed;              //  Pac Man's movement speed is back to it's default value.
        IsOutOfPortal      = true;                          //  Set Pac Man to be outside of any Portal.
        transform.position = SpawnPoint.transform.position; //  Pac Man will be moved to his spawn point.
        R();                                                //  Pac Man will turn right by default.
        PlaySound("AMBIENT");                               //  Play the ambient sound.

        for (int i = 0; i < 4; i++)
        {
            GameObject      Ghost = GhostHolder.GetChild(i).gameObject;
            GhostController GC    = Ghost.GetComponent <GhostController>();
            GC.enabled = true;
            GC.ResetPositions();
            GhostMechanics GM = Ghost.GetComponent <GhostMechanics>();
            GM.enabled = true;
            GM.ResetPositions();
        }
    }
示例#6
0
    /// <summary>
    /// When Pac Man hits a Ghost who is scared.
    /// </summary>
    /// <param name="Ghost">The scared Ghost that Pac Man collided with.</param>

    void OnHitScaredGhost(GhostMechanics Ghost)
    {
        //TODO: Play the death animation for The Ghosts. DONE.
        Ghost.OnHitPacMan();    //  This can only be called if the ghost that was hit is scared.
    }
示例#7
0
 void Awake()
 {
     ghostController = GetComponent <GhostController>();
     ghostMechanics  = GetComponent <GhostMechanics>();
 }