Beispiel #1
0
    private void Awake()
    {
        totalPallets = FindObjectsOfType <Tile>().Count(i => i.isPellet || i.isSuperPellet);
        highScore    = PlayerPrefs.GetInt("HighScore", 0);
        audioSource  = GetComponent <AudioSource>();
        ghosts       = FindObjectsOfType <Ghost>();
        pacMan       = FindObjectOfType <PacMan>();

        Tile[] objecs = FindObjectsOfType <Tile>();

        foreach (Tile t in objecs)
        {
            if (t.GetComponent <Tile>() != null || t.GetComponent <Node>() != null)
            {
                Vector2 pos = t.transform.position;
                boarGame[(int)pos.x, (int)pos.y] = t.gameObject;
            }

            //if (!o.CompareTag("Ghost") && !o.CompareTag("Player") && !o.CompareTag("GhostHouse"))
            //{
            //    Vector2 pos = o.transform.position;
            //    boarGame[(int)pos.x, (int)pos.y] = o;
            //}
        }
    }
Beispiel #2
0
        /*
         *  TODO:
         *  - Cases to cover:
         *      - If no enemy is nearby:
         *          - Catch the closest pellets
         *          - If Sped up and Switched but enemy is no longer nearby, focus on pellets
         *      - If enemy is nearby:
         *          - Switch type to counter enemy -- Set Switch flag to true -- REMEMBER cool down is 10 turns!
         *          - If already switched and ability cooled-down
         *              - Check if PacDude can beat enemy
         *                  - If it can Speed up and chase enemy -- We'll need a flag for Switch such that it's false after speed up
         *          - If already switched but still cooling-down, catch the closest pellets
         *          - If PacDude is  still in the same coordinate then move away... It means we've clashed with another pacDude!
         *  - Within this function we'd have to implement the pathfinding function
         */
        /* This is the function where all the decision making is to be made */
        public string GetCommand(PacMan enemy, int enemyDistance, Pellet pellet, int pelletDistance, Map map, int width, int height)
        {
            /* If we're cooled down then let's put our abilities to good use! */
            if ((m_abilityCooldown == 0) && (m_speedTurnsLeft == 0))
            {
                return(Speed());
            }

            if (enemy != null && enemyDistance <= 3 && m_abilityCooldown == 0)
            {
                string counterType = CounterPacType(enemy.Type);
                if (!counterType.Equals(m_type))
                {
                    return(this.Switch(counterType));
                }
            }

            if (pellet == null)
            {
                Position next = map.BFS(m_position);
                return(next == null?this.MoveTo(m_position) : this.MoveTo(next));
            }
            else
            {
                return(this.MoveTo(pellet.Position));
            }
        }
Beispiel #3
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            MagicImage      LImage = new PacMan();
            MagicBackground LBack  = new TextBackground(LImage.ImageHeight, 10);

            FGenerator = new TextGenerator(LImage, LBack);

            FTimer          = new ObjectTimer(this);
            FTimer.Interval = 33;
//			FTimer.Interval = 100;
            FTimer.Tick += new EventHandler(UpdateData);

            MagicImage      LSampleImage = new PictureGrabber(this.pictureBox1.Image, 5);
            MagicBackground LBackground  = new TextBackground(LSampleImage.ImageHeight, 10);
            TextGenerator   LGenerator   = new TextGenerator(LSampleImage, LBackground);

//			this.Box.Text = FGenerator.GetIntro() + "\r\n"
            this.Box.Text += LGenerator.GetStereogram();

//			UpdateData(FTimer,null);
            this.Box.Select(0, 0);
//			FTimer.Start();

            this.Width  = (int)(FGenerator.Width * (this.Box.Font.Size * 0.75 + 1) + 15);
            this.Height = (int)(FGenerator.Height * (this.Box.Font.Size * 1.25 + 1) + 40);
        }
Beispiel #4
0
    // Update is called once per frame
    public void OnUpdate(MapManager MapManager, PacMan avatar)
    {
        switch ((States)fsm.GetState())
        {
        case States.Idle:
            Idle();
            break;

        case States.ExitSpawn:
            ExitSpawn();
            break;

        case States.Patrol:
            Patrol();
            break;

        case States.Chase:
            Chase();
            break;

        case States.Vulnerable:
            Vulnerable();
            break;

        case States.Dead:
            Dead();
            break;
        }
    }
Beispiel #5
0
    public PlayerData(PacMan pacMan)
    {
        pacMan            = this.pacMan;
        positionPacMan    = new float[2];
        positionPacMan[0] = pacMan.transform.position.x;
        positionPacMan[1] = pacMan.transform.position.y;



        /*
         * pacMan = this.pacMan;
         * ghostRed = this.ghostRed;
         * positionPacMan = new float[3];
         * positionPacMan[0]=pacMan.transform.position.x;
         * positionPacMan[1]=pacMan.transform.position.y;
         * positionPacMan[2]=pacMan.transform.position.z;
         *
         * positionGhostRed = new float[3];
         *
         * if(ghostType == GhostType.Red)
         * {
         *   positionGhostRed[0] = ghostRed.transform.position.x;
         *   positionGhostRed[1] = ghostRed.transform.position.y;
         *   positionGhostRed[2] = ghostRed.transform.position.z;
         * }
         *
         */
    }
Beispiel #6
0
    void StartIntro()
    {
        // Hide all Game Objects and play intro
        PacMan pacman = GameObject.FindGameObjectWithTag("PacMan").GetComponent <PacMan>();

        pacman.transform.GetComponent <SpriteRenderer>().enabled = false;
        pacman.canMove = false;

        GameObject[] blinkys = GameObject.FindGameObjectsWithTag("Blinky");
        foreach (GameObject blinky in blinkys)
        {
            blinky.GetComponent <SpriteRenderer>().enabled = false;
        }
        GameObject[] inkys = GameObject.FindGameObjectsWithTag("Inky");
        foreach (GameObject inky in inkys)
        {
            inky.GetComponent <SpriteRenderer>().enabled = false;
            inky.GetComponent <Inky>().canMove           = false;
        }
        GameObject[] pinkys = GameObject.FindGameObjectsWithTag("Pinky");
        foreach (GameObject pinky in pinkys)
        {
            pinky.GetComponent <SpriteRenderer>().enabled = false;
            pinky.GetComponent <Pinky>().canMove          = false;
        }

        StartCoroutine(ShowObjectsAfter(2.25f));
    }
Beispiel #7
0
        /// <summary>
        /// Permet d'appliquer la bonne strategie de comportement selon le fantome
        /// </summary>
        /// <param name="p_fantôme">Le fantome a appliquer le comportement</param>
        /// <param name="p_pacman">Le pacman</param>
        /// <returns>Le deplacement que le fantome doit prendre</returns>
        public Déplacement AppliquerComportement(Fantôme p_fantôme, PacMan p_pacman)
        {
            switch (p_fantôme.ObtenirComportement())
            {
            case TypeComportement.Blinky:
            {
                return(m_blinky.AppliquerInstinct(p_fantôme.Coordonnée,
                                                  p_pacman.Coordonnée, p_pacman.DéplacementActuel, p_fantôme.EstApeuré()));
            }

            case TypeComportement.Pinky:
            {
                return(m_pinky.AppliquerInstinct(p_fantôme.Coordonnée,
                                                 p_pacman.Coordonnée, p_pacman.DéplacementActuel, p_fantôme.EstApeuré()));
            }

            case TypeComportement.Inky:
            {
                return(m_inky.AppliquerInstinct(p_fantôme.Coordonnée,
                                                p_pacman.Coordonnée, p_pacman.DéplacementActuel, p_fantôme.EstApeuré()));
            }

            case TypeComportement.Clyde:
            {
                return(m_clyde.AppliquerInstinct(p_fantôme.Coordonnée,
                                                 p_pacman.Coordonnée, p_pacman.DéplacementActuel, p_fantôme.EstApeuré()));
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #8
0
    IEnumerator ShowObjectsAfter(float delay)
    {
        yield return(new WaitForSeconds(delay));

        // Show all Game Objects
        PacMan pacman = GameObject.FindGameObjectWithTag("PacMan").GetComponent <PacMan>();

        pacman.transform.GetComponent <SpriteRenderer>().enabled = true;

        GameObject[] blinkys = GameObject.FindGameObjectsWithTag("Blinky");
        foreach (GameObject blinky in blinkys)
        {
            blinky.GetComponent <SpriteRenderer>().enabled = true;
        }
        GameObject[] inkys = GameObject.FindGameObjectsWithTag("Inky");
        foreach (GameObject inky in inkys)
        {
            inky.GetComponent <SpriteRenderer>().enabled = true;
        }
        GameObject[] pinkys = GameObject.FindGameObjectsWithTag("Pinky");
        foreach (GameObject pinky in pinkys)
        {
            pinky.GetComponent <SpriteRenderer>().enabled = true;
        }

        StartCoroutine(StartGameAfter(2));
    }
Beispiel #9
0
        static void Main(string[] args)
        {
            MagicImage      LImage      = new PacMan();
            MagicBackground LBackground = new TextBackground(11, LImage.ImageHeight);
            TextGenerator   LGenerator  = new TextGenerator(LImage, LBackground);

            for (int i = 0; i < 300; i++)
            {
                Console.WriteLine(LGenerator.GetStereogram());
                Console.WriteLine();
                System.Threading.Thread.Sleep(new TimeSpan(1000000));
            }

            /*
             * ANSI Escape Character tests
             *                      for (int i = 0; i <= 32; i++)
             *                      {
             *                              Console.Write(" :");
             *                              Console.Write(i);
             *                              Console.Write(": ");
             *                              Console.Write((char)i);
             *                              Console.Write("[2J");
             *
             *                      }
             */
            /*			0 non bold
             *                      1 bold
             *                      30-37;
             *                      40-47;
             *                              m
             */
            //			Console.Write("\27[6;6H");
            //			Console.Write("\27[6;6H");
            Console.ReadLine();
        }
Beispiel #10
0
    protected Node ChooseNextNode()
    {
        Node target = null;

        PacMan pm = pacMan.GetComponent <PacMan> ();

        if (pm.targetNode != null && pm.targetNode != currentNode)
        {
            target = pm.targetNode;
        }
        else if (pm.currentNode != null)
        {
            target = pm.currentNode;
        }
        else if (currentNode != pm.previousNode)
        {
            target = pm.previousNode;
        }

        path = navigation.GetShortestPath(previousNode, target);

        target = null;
        if (path != null && path.Count > 1)
        {
            target = path[1];
        }

        return(target);
    }
Beispiel #11
0
 public SpriteSource PacMan(PacMan pacMan)
 {
     if (pacMan.Animation.Active)
     {
         return(PacMan(pacMan.Direction, pacMan.Animation.Current, pacMan.Dying));
     }
     return(Blank);
 }
Beispiel #12
0
 private void Awake()
 {
     animator       = GetComponent <Animator>();
     spriteRenderer = GetComponent <SpriteRenderer>();
     gameBoard      = FindObjectOfType <GameBoard>();
     pacMan         = FindObjectOfType <PacMan>();
     ResetPositionAndDirection();
 }
 /// <summary>
 /// Check if monster over PacMan
 /// </summary>
 /// <param name="pacMan">PacMan object</param>
 /// <returns>true if monster is over PacMan, else returns false</returns>
 public bool IsMonsterOverPacMan(PacMan pacMan)
 {
     if (monsterPos.x == pacMan.pacManPos.x && monsterPos.y == pacMan.pacManPos.y)
     {
         return(true);
     }
     return(false);
 }
Beispiel #14
0
        /// <summary>
        /// Spawn PacMan to its position.
        /// </summary>
        private void SpawnPacMan()
        {
            Transform spawnPoint = GameObject.Find("PacManSpawnPoint").transform;

            PacMan            = Instantiate(_pacManToSpawnPrefab, spawnPoint.position, _pacManToSpawnPrefab.transform.rotation);
            PacMan.Identifier = ++MaxObjectIdentifier;
            PacMan.Name       = "PacMan";
        }
 // Start is called before the first frame update
 void Start()
 {
     timeScale = Time.timeScale;
     lives     = maxLives;
     Avatar    = GameObject.Instantiate(PacManPrefab).GetComponent <PacMan>();
     Avatar.Respawn(MapManager.Get().playerStartPos);
     Avatar.OnDeathAnimationFinished += PlayerDeath;
 }
Beispiel #16
0
    public void SetMainCamera(PacMan parent)
    {
        mainCamera.transform.parent = parent.transform;
        Vector3 position = mainCamera.transform.localPosition;

        position.x = 0f;
        position.y = 0f;
        mainCamera.transform.localPosition = position;
    }
Beispiel #17
0
    void OnTriggerEnter2D(Collider2D other)
    {
        PacMan pacman = other.GetComponent <PacMan>();

        if (pacman != null)
        {
            pacman.ConsumePellet(false);
            Destroy(gameObject);
        }
    }
Beispiel #18
0
    public static void SavePlayer(PacMan pacMan)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/player.txt";
        FileStream      stream    = new FileStream(path, FileMode.Create);

        PlayerData data = new PlayerData(pacMan);

        formatter.Serialize(stream, data);
        stream.Close();
    }
Beispiel #19
0
 // Start is called before the first frame update
 void Start()
 {
     Avatar = GameObject.Instantiate(PacManPrefab).GetComponent <PacMan>();
     Avatar.SetPosition(new Vector2Int(13, 16));
     lives  = 3;
     Ghosts = new List <Ghost>();
     for (int g = 0; g < 4; g++)
     {
         Ghosts.Add(GameObject.Instantiate(GhostPrefab).GetComponent <Ghost>());
         Ghosts[g].SetPosition(new Vector2Int(13, 13));
     }
 }
Beispiel #20
0
    void ConfigurePacMan()
    {
        GameObject pacmanGameObject = GameObject.FindGameObjectWithTag("PacMan");

        if (pacmanGameObject != null)
        {
            PacMan pacman = pacmanGameObject.GetComponent <PacMan>();
            pacman.moveSpeed      = Settings.pacmanMoveSpeed;
            pacman.timeInvincible = Settings.ghostTimeFrightened;
            pacman.audio.volume   = Settings.soundFXVolume;
        }
    }
Beispiel #21
0
 public Game(string Id)
 {
     ID         = Id;
     map        = new Maze();
     pacMan     = new PacMan(map, new Position(13, 17));
     blinky     = new Blinky(pacMan, map, new Position(10, 11));
     pinky      = new Pinky(pacMan, map, new Position(11, 14));
     gui        = new GUI(map);
     clyde      = new Clyde(pacMan, map, new Position(11, 15));
     inky       = new Inky(pacMan, map, new Position(12, 15));
     collision  = new Collision(pinky, blinky, inky, clyde, pacMan, gui);
     gameEngine = new GameEngine(blinky, clyde, inky, pinky);
 }
Beispiel #22
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        PacMan pac = collision.gameObject.GetComponent <PacMan>();

        if (pac != null)
        {
            pac.Die();
        }
        else
        {
            SetDirection();
        }
    }
Beispiel #23
0
    public override void FixedUpdate()
    {
        Vector2        currentDir    = destination - (Vector2)transform.position.Round();
        List <Vector3> validTileList = new List <Vector3>();
        Vector3        targetTile    = new Vector3();
        // Take tile 2 in front of pac man
        // Draw line from blinky to this tile
        // Double line distance
        // Rounded = targettile
        Vector3 offsetTile = (Vector2)PacMan.transform.position.Round() + (2 * PacMan.GetComponent <PacManMoveScript>().moveDirection);

        if (scatterMode)
        {
            targetTile = scatterTile;
        }
        else
        {
            targetTile = (DrawOffsetLine(offsetTile));
        }

        List <Vector3> tileList = new List <Vector3>(CreateTileList());

        foreach (Vector3 tile in tileList)
        {
            Vector2 potentialDir = tile - transform.position.Round();
            if (Valid(tile) && Vector2.Dot(potentialDir.normalized, currentDir.normalized) != -1)
            {
                validTileList.Add(tile);
            }
        }

        List <Vector3> LAValidTileList = new List <Vector3>(CreateLAValidTileList(validTileList));

        //TODO: make it so blinky only moves after reaching destination (set destination if dest == transform.position like in pacmanscript)
        if ((Vector2)transform.position.Round() != destination)
        {
            MoveTowardDestination(transform.position, destination, movespeed, validTileList);
        }
        else
        {
            SetDestination(validTileList, LAValidTileList, targetTile);
        }

        Vector2 dir = destination - (Vector2)transform.position;

        GetComponent <Animator>().SetFloat("DirX", dir.x);
        GetComponent <Animator>().SetFloat("DirY", dir.y);

        linerenderer.SetPosition(0, gameObject.transform.position.Round());
        linerenderer.SetPosition(1, targetTile);
    }
Beispiel #24
0
        //public Ghost[] ghostsList;

        public GameField()
        {
            pacMan = new PacMan();
            GGhost = new GGhost("G");
            BGhost = new BGhost();
            PGhost = new PGhost();
            RGhost = new RGhost();
            //ghostsList = new Ghost[]
            //{
            //     new Ghost("G"),
            //     new Ghost("R"),
            //     new Ghost("B"),
            //     new Ghost("P")
            //};
        }
 public void PlayerDeath(PacMan p)
 {
     UpdateLives(lives - 1);
     if (lives > 0)
     {
         Avatar.Respawn(MapManager.Get().playerStartPos);
         Avatar.Reset();
         EnemyManager.Get().ResetGhosts();
     }
     else
     {
         PauseGame(true);
         GameOver();
         return;
     }
 }
Beispiel #26
0
    /*
     *  TODO: Maybe add this into a interface or something? Instead of repeating it?
     */
    static int FindClosestObject(Position pos, List <PacMan> objects, ref PacMan target)
    {
        int shortestDistance = 100;

        foreach (var obj in objects)
        {
            int distance = pos.GetDistance(obj.Position);
            shortestDistance = Math.Min(shortestDistance, distance);
            if (distance == shortestDistance)
            {
                target = obj;
            }
        }

        return(shortestDistance);
    }
Beispiel #27
0
    private void ResetPositions()
    {
        GameObject go = GameObject.Find("Ghosts");

        GameObject[] ghosts = new GameObject[go.transform.childCount];
        for (int i = 0; i < ghosts.Length; i++)
        {
            Destroy(go.transform.GetChild(i).gameObject);
        }
        if (pac == null)
        {
            pac = GameObject.Find("Homer").GetComponent <PacMan>();
        }
        pac.ResetPosition();

        grid.CreateGhosts();
    }
Beispiel #28
0
    void OnTriggerEnter2D(Collider2D other)
    {
        PacMan pacman = other.GetComponent <PacMan>();

        if (pacman != null)
        {
            if (isFrightened)
            {
                // TODO:
                pacman.score += 300;
                Destroy(gameObject);
            }
            else
            {
                pacman.StartDeath();
            }
        }
    }
Beispiel #29
0
        public GameGrid()
        {
            Width  = 20;
            Height = 20;
            cells  = new Cell[Width, Height];
            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Width; y++)
                {
                    cells[x, y] = new Cell(x, y, this);
                }
            }

            this.Monsters    = new Monster[5];
            this.Monsters[0] = new Monster(this);
            pacmanLocation   = GetCell(10, 10);
            PacMan           = new PacMan();
        }
    private float currentTimeOnBase;      // tiempo que llevamos en base

    // Use this for initialization
    public virtual void Start()
    {
        // captura de referencias
        grid   = GameObject.FindGameObjectWithTag("Grid").GetComponent <MyGrid>();
        pacMan = GameObject.FindGameObjectWithTag("PacMan").GetComponent <PacMan>();

        ghostBaseObject = GameObject.FindGameObjectWithTag("GhostBase");

        //ghostRenderer = transform.GetComponentInChildren<Renderer>();

        // base de los fantasmas
        ghostBase = grid.GetNodeContainingPosition(ghostBaseObject.transform.position); // guardamos donde se encuentra la base
        ghostBaseObject.transform.position = ghostBase.position;                        // ajustamos su posicion

        //  guardamos los materiales de los fantasmas
        // transform.GetComponentInChildren<Renderer>().material = initialMaterial;



        // DANI SI PUEDES HAZ QUE SEA LA ZONA ENTERA LA QUE SE CONSDIERE LA BASE Y QUE LOS FANTASMAS PUEDAN IR A DIFERENTES POSICIONES DE ESTA
        // Y QUE ADEMAS SE GUARDEN LAS COORDENADAS DE TODOS LOS NODOS SITUADOS AHI

        // waypoints
        currentWaypointIndex = 0;
        nodeToReach          = waypoints[currentWaypointIndex].GetNode();

        // guardamos el nodo en el que estamos
        currentNode = grid.GetNodeContainingPosition(transform.position);
        initialNode = currentNode;

        //Debug.LogError(currentNode == initialNode, gameObject);

        pathCalculated = false;
        // usamos su posicion para colocarnos bien
        grid.AdjustPosition(this.gameObject, currentNode);

        // creamos la lista para el camino
        pathToFollow = new List <Node>();            // si inicializamos eta variable en el start no sra accesible desde otras funciones que no sean de unity (CONJETURA)

        // guardamos el color inicial
        initialColor = ghostRenderer.material.color;
    }