Esempio n. 1
0
 public void Die()
 {
     this.PacManState = PacManState.Dying;
     this.spriteAnimationAdapter.CurrentAnimation = PacManDying;
     this.spriteAnimationAdapter.ResetAnimation(PacManDying);
     this.spriteAnimationAdapter.ResumeAmination(PacManDying);
 }
 public PacManAnimated(Game game)
     : base(game)
 {
     // TODO: Construct any child components here
     input       = (InputHandler)game.Services.GetService(typeof(IInputHandler));
     pacManState = PacManState.Stopped;
 }
Esempio n. 3
0
 internal void OnDeath()
 {
     status    = PacManState.Dead;
     direction = Direction.right;
     Rotate();
     SetTicksToChangeFrame(2);
     frameIndex         = 0;
     sptRenderer.sprite = animationDying[0];
 }
Esempio n. 4
0
 protected override void LoadContent()
 {
     this.SpriteTexture = this.Game.Content.Load <Texture2D>("pacManSingle");
     this.Origin        = new Vector2(this.SpriteTexture.Width / 2, this.SpriteTexture.Height / 2);
     this.Location      = new Microsoft.Xna.Framework.Vector2(100, 100);
     this.Speed         = 200;
     this.pacState      = PacManState.Chomping;
     base.LoadContent();
 }
Esempio n. 5
0
        public PacManAnimated(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
            input       = (InputHandler)game.Services.GetService(typeof(IInputHandler));
            gameConsole = (GameConsole)game.Services.GetService(typeof(IGameConsole));
            PacManState = PacManState.Spawning;
            observers   = new List <IObserver>();

            powerTimer.Elapsed += new System.Timers.ElapsedEventHandler(powerTimer_Elapsed);
        }
Esempio n. 6
0
        public override void Update(GameTime gameTime)
        {
            //Elapsed time since last update
            float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            this.controller.Update(gameTime);
            if (this.PacState == PacManState.Chomping)
            {
                this.Location += ((this.controller.Direction * (time / 1000)) * Speed);      //Simple Move
                this.Rotate    = this.controller.Rotate;
            }
            //Change State based on movement
            if (this.controller.hasInputForMoverment)
            {
                if (pacState != PacManState.Spawning && (pacState != PacManState.SuperPacMan)
                    &&
                    (pacState != PacManState.Dying))
                {
                    this.PacState = PacManState.Chomping;
                }
            }
            else
            {
                if (pacState != PacManState.Spawning &&
                    (pacState != PacManState.SuperPacMan) &&
                    (pacState != PacManState.Dying))
                {
                    this.PacState = PacManState.Still;
                }
            }

            //Keep PacMan On Screen
            if (this.Location.X > Game.GraphicsDevice.Viewport.Width - (this.spriteTexture.Width / 2))
            {
                this.Location.X = Game.GraphicsDevice.Viewport.Width - (this.spriteTexture.Width / 2);
            }
            if (this.Location.X < (this.spriteTexture.Width / 2))
            {
                this.Location.X = (this.spriteTexture.Width / 2);
            }

            if (this.Location.Y > Game.GraphicsDevice.Viewport.Height - (this.spriteTexture.Height / 2))
            {
                this.Location.Y = Game.GraphicsDevice.Viewport.Height - (this.spriteTexture.Height / 2);
            }

            if (this.Location.Y < (this.spriteTexture.Height / 2))
            {
                this.Location.Y = (this.spriteTexture.Height / 2);
            }

            base.Update(gameTime);
        }
Esempio n. 7
0
    internal void SetReady()
    {
        status = PacManState.Waiting;
        sptRenderer.enabled = true;
        direction           = Direction.left;
        dirVector           = Utils.VectorByDir(direction);
        tile       = new Vector2Int(16, 7);
        inBetwen   = 0.5f;
        tileTarget = tile + dirVector;
        frameIndex = 0;

        PositionUpdate();
        Rotate();
        sptRenderer.sprite = animationMoving[frameIndex];
    }
Esempio n. 8
0
        public void ObserverUpdate(object sender, object message)
        {
            if (message is PacManState)
            {
                PacManState p = (PacManState)message;
                Console.WriteLine(this + " notified " + p + " from " + sender);
            }
            if (message is string)
            {
                string strMessage = (string)message;
                switch (strMessage)
                {
                case "PowerUP":
                    Console.WriteLine(this + "PowerUp Message Received");
                    break;

                case "PowerUP Elapsed":
                    Console.WriteLine(this + "PowerUp Elapsed Message Received");
                    break;
                }
            }
        }
Esempio n. 9
0
        public void ObserverUpdate(Object sender, Object message)
        {
            if (message is PacManState)
            {
                PacManState p = (PacManState)message;
                gameConsole.GameConsoleWrite(this + " notified " + p + " from " + sender);
                if (p == PacManState.Dying)
                {
                    this.State = GhostState.Roving;
                }
            }
            if (message is string)
            {
                string strMessage = (string)message;
                switch (strMessage)
                {
                case "PowerUP":
                    this.Evade();
                    break;

                case "PowerUP Elapsed":
                    this.ghostState = GhostState.Roving;
                    break;

                case "Alive":
                    if (this.Intersects(pacMan))
                    {
                        while (this.Intersects(pacMan))
                        {
                            gameConsole.GameConsoleWrite(this + " relocated ");
                            this.Location = this.GetRandLocation();
                            this.SetTranformAndRect();
                        }
                    }
                    break;
                }
            }
        }
Esempio n. 10
0
 public PacMan()
 {
     //Set default state will call notify so make sure this.Ghosts is intitialized first
     this.State = PacManState.Still;
 }
Esempio n. 11
0
 internal void StopPacMan()
 {
     status = PacManState.Waiting;
 }
Esempio n. 12
0
 internal void OnGameStart()
 {
     status = PacManState.Alive;
     SetTicksToChangeFrame(1);
 }
Esempio n. 13
0
 void Awake()
 {
     //QualitySettings.vSyncCount = 0; Application.targetFrameRate = 12;//TODO remove!!!
     sptRenderer = GetComponent <SpriteRenderer>();
     status      = PacManState.Waiting;
 }
Esempio n. 14
0
 void SetState(PacManState newState)
 {
     prevState    = currentState;
     currentState = newState;
 }
Esempio n. 15
0
        //Function to fire event
        // return the Pacman state.....
        public PacManState FireEvent(int eventNumber)
        {
            PacManEvents triggerEvent = (PacManEvents)eventNumber;

            if (PacmanCurrentState.Equals(PacManState.START_PAC))
            {
                switch (triggerEvent)
                {
                case PacManEvents.ToEatCheeze:
                    PacmanCurrentState = PacManState.START_PAC;
                    return(PacmanCurrentState);

                    break;

                case PacManEvents.ToEatSuperTab:
                    PacmanCurrentState = PacManState.SUPERMAN;
                    return(PacmanCurrentState);

                    break;

                case PacManEvents.EatByGhost:
                    PacmanCurrentState = PacManState.DEAD;
                    return(PacmanCurrentState);

                    break;

                case PacManEvents.ToEatLastCheeze:
                    PacmanCurrentState = PacManState.LEVELUP;
                    return(PacmanCurrentState);

                    break;

                default:
                    inValid = true;
                    return(PacmanCurrentState);

                    break;
                }
            }
            else if (PacmanCurrentState.Equals(PacManState.SUPERMAN))
            {
                switch (triggerEvent)
                {
                case PacManEvents.ToEatCheeze:
                    PacmanCurrentState = PacManState.SUPERMAN;
                    return(PacmanCurrentState);

                case PacManEvents.ToEatSuperTab:
                    PacmanCurrentState = PacManState.SUPERMAN;
                    return(PacmanCurrentState);

                case PacManEvents.PacmanEatsSacredGhost:
                    PacmanCurrentState = PacManState.SUPERMAN;
                    return(PacmanCurrentState);

                case PacManEvents.BraveGhostEatsPacman:
                    PacmanCurrentState = PacManState.DEAD;
                    return(PacmanCurrentState);

                case PacManEvents.SuperPacmanTimeOut:
                    PacmanCurrentState = PacManState.START_PAC;
                    return(PacmanCurrentState);

                default:
                    inValid = true;
                    return(PacmanCurrentState);
                }
            }
            else if (PacmanCurrentState.Equals(PacManState.DEAD))
            {
                switch (triggerEvent)
                {
                case PacManEvents.NoLifeLeft:
                    PacmanCurrentState = PacManState.GAMEOVER;
                    return(PacmanCurrentState);

                case PacManEvents.LifeLeft:
                    PacmanCurrentState = PacManState.START_PAC;
                    return(PacmanCurrentState);

                default:
                    inValid = true;
                    return(PacmanCurrentState);
                }
            }
            else if (PacmanCurrentState.Equals(PacManState.LEVELUP))
            {
                switch (triggerEvent)
                {
                case PacManEvents.NextLevel:
                    PacmanCurrentState = PacManState.START_PAC;
                    return(PacmanCurrentState);

                case PacManEvents.LastLevelGameUp:
                    PacmanCurrentState = PacManState.GAMEOVER;
                    return(PacmanCurrentState);

                default:
                    inValid = true;
                    return(PacmanCurrentState);
                }
            }
            else
            {
                switch (triggerEvent)
                {
                case PacManEvents.LastLevelGameUp:
                    PacmanCurrentState = PacManState.GAMEOVER;
                    return(PacmanCurrentState);

                default:
                    inValid = true;
                    return(PacmanCurrentState);
                }
            }
        }
Esempio n. 16
0
 // Constructor to first time intialize the state...
 public PacManFsm()
 {
     PacmanCurrentState = PacManState.START_PAC;
 }
Esempio n. 17
0
 //get current state of pacman
 public FSM(PacManState initial_State)
 {
     this.PacmanCurrentState = initial_State;
 }
Esempio n. 18
0
        private void UpdatePacMan(GamePadState gamePad1State, float lastUpdateTime)
        {
            //Dying pacman can't move
            if (PacManState == PacManState.Dying)
            {
                if (spriteAnimationAdapter.GetLoopCount() > 0)
                {
                    //spriteAnimationAdapter.PauseAnimation(PacManDying);
                    //spriteAnimationAdapter.ResetAnimation(PacManDying);
                    spriteAnimationAdapter.CurrentAnimation = PacManMoving;
                    //TODO move pacman to a location without a ghost
                    this.locationRect = new Rectangle(100, 100, this.spriteAnimationAdapter.CurrentTexture.Width, this.spriteAnimationAdapter.CurrentTexture.Height);
                    this.PacManState  = PacManState.Stopped;
                    this.Notify("Alive");
                }
                return;
            }

            PacManState = PacManState.Stopped;

            //Input for update from analog stick
            #region LeftStick
            if (gamePad1State.ThumbSticks.Left.Length() > 0.0f)
            {
                PacManState = PacManState.Moving;               //Change State;

                Direction    = gamePad1State.ThumbSticks.Left;
                Direction.Y *= -1;      //Invert Y Axis

                float RotationAngle = (float)Math.Atan2(
                    gamePad1State.ThumbSticks.Left.X,
                    gamePad1State.ThumbSticks.Left.Y);

                Rotate = (float)MathHelper.ToDegrees(RotationAngle - (float)(Math.PI / 2));


                //Time corrected move. MOves PacMan By PacManDiv every Second
                Location += ((Direction * (lastUpdateTime / 1000)) * Speed);      //Simple Move PacMan by PacManDir

                //Keep PacMan On Screen
                if (Location.X > graphics.GraphicsDevice.Viewport.Width - (this.locationRect.Width / 2))
                {
                    Location.X = graphics.GraphicsDevice.Viewport.Width - (this.locationRect.Width / 2);
                }

                if (Location.X < (this.locationRect.Width / 2))
                {
                    Location.X = (this.locationRect.Width / 2);
                }
            }
            #endregion

            //Update for input from DPad
            #region DPad
            Vector2 PacManDDir = Vector2.Zero;
            if (gamePad1State.DPad.Left == ButtonState.Pressed)
            {
                //Orginal Position is Right so flip X
                PacManDDir += new Vector2(-1, 0);
            }
            if (gamePad1State.DPad.Right == ButtonState.Pressed)
            {
                //Original Position is Right
                PacManDDir += new Vector2(1, 0);
            }
            if (gamePad1State.DPad.Up == ButtonState.Pressed)
            {
                //Up
                PacManDDir += new Vector2(0, -1);
            }
            if (gamePad1State.DPad.Down == ButtonState.Pressed)
            {
                //Down
                PacManDDir += new Vector2(0, 1);
            }
            if (PacManDDir.Length() > 0)
            {
                PacManState = PacManState.Moving;               //Change State;

                //Angle in radians from vector
                float RotationAngleKey = (float)Math.Atan2(
                    PacManDDir.X,
                    PacManDDir.Y * -1);
                //Find angle in degrees
                Rotate = (float)MathHelper.ToDegrees(
                    RotationAngleKey - (float)(Math.PI / 2)); //rotated right already

                //move the pacman
                Location += ((PacManDDir * (lastUpdateTime / 1000)) * Speed);      //Simple Move PacMan by PacManDir
            }
            #endregion

            //Update for input from Keyboard
#if !XBOX360
            #region KeyBoard


            Vector2 PacManKeyDir = new Vector2(0, 0);

            if (input.KeyboardState.IsKeyDown(Keys.Left))
            {
                //Flip Horizontal

                PacManKeyDir += new Vector2(-1, 0);
            }
            if (input.KeyboardState.IsKeyDown(Keys.Right))
            {
                //No new sprite Effects

                PacManKeyDir += new Vector2(1, 0);
            }
            if (input.KeyboardState.IsKeyDown(Keys.Up))
            {
                PacManKeyDir += new Vector2(0, -1);
            }
            if (input.KeyboardState.IsKeyDown(Keys.Down))
            {
                PacManKeyDir += new Vector2(0, 1);
            }
            if (PacManKeyDir.Length() > 0)
            {
                PacManState = PacManState.Moving;               //Change State;

                float RotationAngleKey = (float)Math.Atan2(
                    PacManKeyDir.X,
                    PacManKeyDir.Y * -1);

                Rotate = (float)MathHelper.ToDegrees(
                    RotationAngleKey - (float)(Math.PI / 2));


                Location += ((PacManKeyDir * (lastUpdateTime / 1000)) * Speed);      //Simple Move PacMan by PacManDir
            }
            #endregion
#endif

            //Animation
            switch (PacManState)
            {
            case PacManState.Moving:
                spriteAnimationAdapter.ResumeAmination(PacManMoving);
                break;

            case PacManState.Stopped:
                spriteAnimationAdapter.PauseAnimation(PacManMoving);
                break;
            }
        }
Esempio n. 19
0
    //pac fire event function
    public void pacFireEvent(PacManEvents e)
    {
        if (this.PacmanCurrentState == PacManState.Start_Pacman)
        {
            switch (e)
            {
            case PacManEvents.EatCheese:
                this.PacmanCurrentState = PacManState.Start_Pacman;
                this.color = Color.green;
                break;

            case PacManEvents.Eat_SuperTablet:
                this.PacmanCurrentState = PacManState.Super_Pacman;
                this.color = Color.blue;
                break;

            case PacManEvents.Eaten_by_ghost:
                this.PacmanCurrentState = PacManState.DEAD;
                this.color = Color.red;
                break;

            case PacManEvents.ToEatLastCheeze:
                this.PacmanCurrentState = PacManState.LEVELUP;
                this.color = Color.yellow;
                break;

            default:
                this.PacmanCurrentState = PacManState.Start_Pacman;
                this.color = Color.green;
                break;
            }
        }
        else if (this.PacmanCurrentState == PacManState.Super_Pacman)
        {
            switch (e)
            {
            case PacManEvents.EatCheese:
                this.PacmanCurrentState = PacManState.Super_Pacman;
                this.color = Color.blue;
                break;

            case PacManEvents.Eat_SuperTablet:
                this.PacmanCurrentState = PacManState.Super_Pacman;
                this.color = Color.blue;
                break;

            case PacManEvents.ToEatLastCheeze:
                this.PacmanCurrentState = PacManState.LEVELUP;
                this.color = Color.yellow;
                break;

            case PacManEvents.Pacman_Eats_Sacred_Ghost:
                this.PacmanCurrentState = PacManState.Super_Pacman;
                this.color = Color.blue;
                break;

            case PacManEvents.Brave_Ghost_Eats_Pacman:
                this.PacmanCurrentState = PacManState.DEAD;
                this.color = Color.red;
                break;

            case PacManEvents.SuperPacman_Timeout:
                this.PacmanCurrentState = PacManState.Start_Pacman;
                this.color = Color.green;
                break;

            default:
                this.PacmanCurrentState = PacManState.Super_Pacman;
                this.color = Color.blue;
                break;
            }
        }
        else if (this.PacmanCurrentState == PacManState.DEAD)
        {
            switch (e)
            {
            case PacManEvents.NoLifeLeft:
                this.PacmanCurrentState = PacManState.GAMEOVER;
                this.color = Color.black;
                break;

            case PacManEvents.LifeLeft:
                this.PacmanCurrentState = PacManState.Start_Pacman;
                this.color = Color.green;
                break;

            default:
                this.PacmanCurrentState = PacManState.DEAD;
                this.color = Color.red;
                break;
            }
        }
        else if (this.PacmanCurrentState == PacManState.LEVELUP)
        {
            switch (e)
            {
            case PacManEvents.NextLevel:
                this.PacmanCurrentState = PacManState.Start_Pacman;
                this.color = Color.green;
                break;

            case PacManEvents.LastLevel:
                this.PacmanCurrentState = PacManState.GAMEOVER;
                this.color = Color.black;
                break;

            default:
                this.PacmanCurrentState = PacManState.LEVELUP;
                this.color = Color.yellow;
                break;
            }
        }
        else
        {
            switch (e)
            {
            case PacManEvents.LastLevel:
                this.PacmanCurrentState = PacManState.GAMEOVER;
                this.color = Color.black;
                break;

            default:
                inValid = true;
                break;
            }
        }
    }