コード例 #1
0
ファイル: Pacman.cs プロジェクト: NicolasDiab/Pacman
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            positionScore.X = 620;
            positionScore.Y = 200;

            positionVies.X = 620;
            positionVies.Y = 300;

            positionVictoire.X = this.GraphicsDevice.Viewport.Width / 2 - 390;
            positionVictoire.Y = this.GraphicsDevice.Viewport.Height / 2;

            joueurPacman = new JoueurPacman(this, "pacman", 3, 120, 400);

            fantomeCyan   = new IAFantom(this, "fantome_cyan", 2, 281, 280);
            fantomeOrange = new IAFantom(this, "fantome_orange", 2, 282, 280);
            fantomeRose   = new IAFantom(this, "fantome_rose", 2, 280, 280);
            fantomeRouge  = new IAFantom(this, "fantome_rouge", 2, 279, 280);

            score = 0;
            vies  = 3;

            nextBlinkTime = 0;
            gameOver      = false;
            _tryAgain     = false;

            base.Initialize();
        }
コード例 #2
0
        public static Boolean testMiam(JoueurPacman joueurPacman)
        {
            Boolean bmiam = false;
            // On récupère la position X/Y arrondie du pacman dans un tableau
            // On convertit la position x/y de pixel vers une case [i,j] de la matrice
            ObjetAnime objetAnime = joueurPacman._pacman;

            int[] position = Moteur2D.getPositionMatrice(objetAnime.Position.X, objetAnime.Position.Y);
            int   j        = position[0];
            int   i        = position[1];

            // Puis on test si le miam est possible
            byte[,] map = Pacman.getMap();
            if (map[i, j] == 1)
            {
                bmiam     = true;
                map[i, j] = 10;
                Pacman.setMap(map);
                ajouterScore(5);
            }
            else if (map[i, j] == 3)
            {
                bmiam     = true;
                map[i, j] = 2;
                Pacman.setMap(map);
                ajouterScore(100);
                // activer immortalité
                // fuite des fantome
                // chgt textures
            }
            else if (map[i, j] == 4)
            {
                bmiam     = true;
                map[i, j] = 10;

                Pacman.setPouvoirBool(true);
                joueurPacman.Pouvoir = true;
                Pacman.setPouvoirTime(0);

                Pacman.setMap(map);
                ajouterScore(50);
            }

            return(bmiam);
        }
コード例 #3
0
ファイル: Moteur2D.cs プロジェクト: NicolasDiab/Pacman
        // Return true si un déplacement ferait déplacer un pacman ou un fantome
        // vers un mur du labyrinthe.
        public static Boolean testCollision(Object obj1, String direction)
        {
            // On initialise une collision à false par défaut
            bool collision = false;
            // On récupère la position X/Y arrondie du pacman/fantome dans un tableau
            // On convertit la position x/y de pixel vers une case [i,j] de la matrice
            ObjetAnime objetAnime = null;

            if (obj1 is JoueurPacman)
            {
                JoueurPacman joueurPacman = (JoueurPacman)obj1;
                objetAnime = joueurPacman._pacman;
            }
            else if (obj1 is IAFantom)
            {
                IAFantom iaFantom = (IAFantom)obj1;
                objetAnime = iaFantom._fantom;
            }
            int[] position = getPositionMatrice(objetAnime.Position.X, objetAnime.Position.Y);
            int   j        = position[0];
            int   i        = position[1];

            // Puis on test si le déplacement est possible selon le déplacement
            // On récupère la carte
            byte[,] map = Pacman.getMap();
            int VX = Pacman.getVX();
            int VY = Pacman.getVY();

            // Si la case suivante est pas un mur
            // il y a collision
            // R L U D pour Right Left Up Down
            if (direction == "R")
            {
                if (j >= VY - 1) // Si dépasse de la matrice, amène de l'autre côté de l'écran
                {
                    j = -1;
                }
                if (map[i, j + 1] == 0)
                {
                    collision = true;
                }
            }
            else if (direction == "L")
            {
                if (j <= 1) // Si dépasse de la matrice, amène de l'autre côté de l'écran
                {
                    j = VY;
                }
                if (map[i, j - 1] == 0)
                {
                    collision = true;
                }
            }
            else if (direction == "U")
            {
                if (i <= 1) // Si dépasse de la matrice, amène de l'autre côté de l'écran
                {
                    i = VX;
                }
                if (map[i - 1, j] == 0)
                {
                    collision = true;
                }
            }
            else if (direction == "D")
            {
                if (i >= VX - 1) // Si dépasse de la matrice, amène de l'autre côté de l'écran
                {
                    i = -1;
                }
                if (map[i + 1, j] == 0)
                {
                    collision = true;
                }
            }

            return(collision);
        }