コード例 #1
0
        // Le jeu est dans l'état PLAY
        private void AnimatePlay()
        {
            GameRecord record;

            while (_cfg.play.Count > 0)
            {
                record = _cfg.play[0];
                if (record.tim > oturn)
                {
                    break;
                }
                _cfg.play.RemoveAt(0);
                _cfg.playerCfg.record.Add(record);
                if (record.tim == oturn)
                {
                    if (record.isKey)
                    {
                        switch (record.key)
                        {
                        case PacmanKey.Back:
                        {
                            TXYList xyList = _Pacman.xyList;
                            if (!xyList.empty)
                            {
                                xyList.deAdd();
                            }
                        }
                        break;

                        case PacmanKey.Left:
                            _Pacman.Left();
                            break;

                        case PacmanKey.Right:
                            _Pacman.Right();
                            break;

                        case PacmanKey.Down:
                            _Pacman.Down();
                            break;

                        case PacmanKey.Up:
                            _Pacman.Up();
                            break;
                        }
                    }
                    else
                    {
                        intProcessKey(record.tsk);
                    }
                }
            }

            if (Labyrinth.getCurrent().RemainingPills <= 0)
            {
                // toutes les pastilles ont été mangées, changement de niveau
                // accélère un peu le jeu
                Level++;
                SleepTime -= 1;
                numLaby    = (numLaby + 1) % 4;
                SetLabyrinth(numLaby);
                SetMode(GameMode.READY);
            }
            else
            {
                int        i;
                int        xp, yp;
                GhostState state;

                EraseSprites();
                ErasePoints();

                // testes de collisions
                xp = _Pacman.X;
                yp = _Pacman.Y;
                // collisions avec les fantomes
                foreach (Ghost ghost in _Ghosts)
                {
                    state = ghost.State;
                    // teste si le Pacman est en collision avec le Fantome i
                    if (_Pacman.HasCollision(ghost))
                    {
                        if (state.isHunt() || state.isRandom())
                        {
                            // Perdu une vie
                            SetMode(GameMode.DEATH);
                            return;
                        }
                        else if (state.isFlee())
                        {
                            // le fantome est mangé
                            ghost.setState(GhostState.EYE);
                            AddScore(_GhostScore);
                            FantScore *= 2;
                            AddPoints(_GhostScore);
                            if (Audio != null)
                            {
                                Audio.PlayEatGhost();
                            }
                        }
                    }
                }
                // collisions avec le bonus
                if (CurrentBonus != null)
                {
                    // le bonus existe
                    if (_Pacman.HasCollision(CurrentBonus))
                    {
                        int points = Math.Min(1600, Level * 100);
                        AddScore(points);
                        AddPoints(points);
                        CurrentBonus = null;
                        if (Audio != null)
                        {
                            Audio.PlayBonus();
                        }
                    }
                    if (CurrentBonus != null && CurrentBonus.animate() <= 0)
                    {
                        // le bonus est en fin de vie
                        CurrentBonus = null;
                    }
                }
                else
                {
                    // pas de bonus
                    if (Game.GetRandom(1000) < 5)
                    {
                        CurrentBonus = new Bonus(Level - 1);
                    }
                }

                // animate pacman
                if (speedCheck(Config.SpeedPacman))
                {
                    i = _Pacman.animate();
                    if (i == 1)
                    {
                        // une pastille est mangée
                        AddScore(10);
                        Audio.PlayPill();
                    }
                    else if (i == 2)
                    {
                        FantScore = 100;
                        // Les fantomes qui chasse deviennent fuyards
                        AddScore(50);
                        Audio.PlayBigPill();
                        setGhostsState(GhostState.FLEE);
                    }
                }
                // animate fantomes
                //      bool siren = false;

                foreach (Ghost ghost in _Ghosts)
                {
                    switch (ghost.State.ToEnum())
                    {
                    case GhostStateEnum.FLEE:
                        ghost.speedDevider = Config.GhostSpeedFlee;
                        break;

                    case GhostStateEnum.EYE:
                        ghost.speedDevider = Config.GhostSpeedEye;
                        break;

                    default:
                        if (Math.Sqrt((_Pacman.xLaby - ghost.xLaby) ^ 2 + (_Pacman.yLaby - ghost.yLaby) ^ 2) < Config.SafeRadius)
                        {
                            if (ghost.State.isHunt())
                            {
                                if (GetRandom(Config.GhostSpeedSwitchTime) == 2)
                                {
                                    if (GetRandom(1) == 1)
                                    {
                                        ghost.speedDevider = Config.GhostSpeedHunt;
                                    }
                                    else
                                    {
                                        ghost.speedDevider = Config.GhostSpeedHuntPulse;
                                    }
                                }
                            }
                            else
                            {
                                ghost.speedDevider = Config.GhostSpeed;
                            }
                        }
                        else
                        {
                            ghost.speedDevider = Config.GhostSpeedOutSafe;
                        }
                        break;
                    }

                    if (!speedCheck(ghost.speedDevider))
                    {
                        ghost.timers();
                        continue;
                    }
                    ghost.setPacmanCoor(xp, yp);
                    ghost.animate();
                    //        if (!siren && ghosts[i].getState().isHunt()) {
                    //          siren = true;
                    //          Audio.playSiren();
                    //        }
                }

                // animate points
                foreach (FlyingScore pt in _FlyingScores)
                {
                    pt.animate();
                }

                DrawSprites();
                DrawPoints();
                DrawScore();
                DrawLives();
                //if (DEBUG)
                //{
                //    foreach(Ghost ghost in _Ghosts)
                //    {
                //        //draw.drawDebugString(4, 12 + i * 12, 12, ghosts[i].toString());
                //    }
                //}
            }
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: pgourlain/pacman
        // Le jeu est dans l'état PLAY
        private void AnimatePlay()
        {
            if (Labyrinth.getCurrent().RemainingPills <= 0)
            {
                // toutes les pastilles ont été mangées, changement de niveau
                // accélère un peu le jeu
                Level++;
                SleepTime -= 1;
                numLaby    = (numLaby + 1) % 4;
                SetLabyrinth(numLaby);
                SetMode(GameMode.READY);
            }
            else
            {
                int        i;
                int        xp, yp;
                GhostState state;

                EraseSprites();
                ErasePoints();

                // testes de collisions
                xp = _Pacman.X;
                yp = _Pacman.Y;
                // collisions avec les fantomes
                foreach (Ghost ghost in _Ghosts)
                {
                    state = ghost.State;
                    // teste si le Pacman est en collision avec le Fantome i
                    if (_Pacman.HasCollision(ghost))
                    {
                        if (state.isHunt() || state.isRandom())
                        {
                            // Perdu une vie
                            SetMode(GameMode.DEATH);
                            if (Audio != null)
                            {
                                Audio.PlayDeath();
                            }
                            //Audio.playDeath();
                            return;
                        }
                        else if (state.isFlee())
                        {
                            // le fantome est mangé
                            ghost.setState(GhostState.EYE);
                            AddScore(_GhostScore);
                            FantScore *= 2;
                            AddPoints(_GhostScore);
                            if (Audio != null)
                            {
                                Audio.PlayEatGhost();
                            }
                            //Audio.playEatGhost();
                        }
                    }
                }
                // collisions avec le bonus
                if (CurrentBonus != null)
                {
                    // le bonus existe
                    if (_Pacman.HasCollision(CurrentBonus))
                    {
                        int points = Math.Min(1600, Level * 100);
                        AddScore(points);
                        AddPoints(points);
                        CurrentBonus = null;
                        if (Audio != null)
                        {
                            Audio.PlayBonus();
                        }
                        //Audio.playBonus();
                    }
                    if (CurrentBonus != null && CurrentBonus.animate() <= 0)
                    {
                        // le bonus est en fin de vie
                        CurrentBonus = null;
                    }
                }
                else
                {
                    // pas de bonus
                    if (Game.GetRandom(1000) < 5)
                    {
                        CurrentBonus = new Bonus(Level - 1);
                    }
                }

                // animate pacman
                i = _Pacman.animate();
                if (i == 1)
                {
                    // une pastille est mangée
                    AddScore(10);
                    if (Audio != null)
                    {
                        Audio.PlayPill();
                    }
                    //Audio.playPil();
                }
                else if (i == 2)
                {
                    FantScore = 100;
                    // Les fantomes qui chasse deviennent fuyards
                    AddScore(50);
                    foreach (Ghost ghost in _Ghosts)
                    {
                        ghost.setState(GhostState.FLEE);
                    }
                }
                // animate fantomes
                //      bool siren = false;
                foreach (Ghost ghost in _Ghosts)
                {
                    ghost.setPacmanCoor(xp, yp);
                    ghost.animate();
                    //        if (!siren && ghosts[i].getState().isHunt()) {
                    //          siren = true;
                    //          Audio.playSiren();
                    //        }
                }
                // animate points
                foreach (FlyingScore pt in _FlyingScores)
                {
                    pt.animate();
                }

                DrawSprites();
                DrawPoints();
                DrawScore();
                DrawLives();
                //if (DEBUG)
                //{
                //    foreach(Ghost ghost in _Ghosts)
                //    {
                //        //draw.drawDebugString(4, 12 + i * 12, 12, ghosts[i].toString());
                //    }
                //}
            }
        }