예제 #1
0
파일: Level.cs 프로젝트: Mattias1/pacman
 private DirectionKeys transformDirKey(DirectionKeys key)
 {
     if (key == DirectionKeys.None)
     {
         return(DirectionKeys.None);
     }
     return((DirectionKeys)(((int)key + this.TransFormKey) % 4));
 }
예제 #2
0
파일: Level.cs 프로젝트: Mattias1/pacman
        public virtual void Initialize()
        {
            // Create the list objects
            this.Ghosts        = new List <Ghost>();
            this.PickupObjects = new List <PickupObject>();

            // Spawn all gameobjects
            this.maxPickUpCounter = 0;
            for (int y = 0; y < this.Height; y++)
            {
                for (int x = 0; x < this.Width; x++)
                {
                    Vector2 pos = this.GridToWorld(x, y);
                    if (this.UnsafeIsPacManSpawn(x, y))
                    {
                        this.PacMan    = new PacMan(pos, this);
                        this.PacMan.AI = this.setAI(0, this.PacMan);
                    }
                    else if (this.UnsafeIsGhostSpawn(x, y))
                    {
                        int i = this.Ghosts.Count;
                        if (Ais[i + 2] != null)
                        {
                            this.Ghosts.Add(new Ghost(pos, this, i));
                            this.Ghosts[i].AI = this.setAI(i + 2, this.Ghosts[i]);
                        }
                        else
                        {
                            this.Ghosts.Add(null);
                        }
                    }
                    else if (this.UnsafeIsOrb(x, y))
                    {
                        this.PickupObjects.Add(new PickupObject(ORB, pos, this));
                        this.maxPickUpCounter++;
                    }
                    else if (this.UnsafeIsSuperOrb(x, y))
                    {
                        this.PickupObjects.Add(new PickupObject(SUPERORB, pos, this));
                        this.maxPickUpCounter++;
                    }
                    else if (this.UnsafeIsPickupSpawn(x, y))
                    {
                        this.maxPickUpCounter++;
                    }
                }
            }

            // Some default settings
            this.Start();
            this.LastDirectionKey = DirectionKeys.None;
            this.setPreferredCameraFocus();
            this.Graphics.SetDefaultCamera();
            this.Player.UpdateCamera();
        }
예제 #3
0
파일: Level.cs 프로젝트: Mattias1/pacman
 public void ResetDirectionKeyFromDir(Vector2 dir)
 {
     foreach (DirectionKeys d in (DirectionKeys[])Enum.GetValues(typeof(DirectionKeys)))
     {
         this.LastDirectionKey = d;
         if (this.GetDirFromDirectionKey() == dir)
         {
             break;
         }
     }
 }
예제 #4
0
파일: Level.cs 프로젝트: Mattias1/pacman
        public virtual void ResetPositions()
        {
            // Set the correct AI's
            if (this.MultiPlayer)
            {
                foreach (UserInfo user in this.multiplayerInfo.Users)
                {
                    this.GetGameObject(user.Id).AI = this.setAI(user.Id, this.GetGameObject(user.Id));
                }
            }

            // Set the game state
            this.Start();
            this.LastDirectionKey = DirectionKeys.None;

            // Reposition PacMan and the ghosts
            int ghostCount = 0;

            for (int y = 0; y < this.Height; y++)
            {
                for (int x = 0; x < this.Width; x++)
                {
                    if (this.UnsafeIsPacManSpawn(x, y))
                    {
                        this.PacMan.Position = this.GridToWorld(x, y);
                        this.PacMan.Velocity = Vector2.Zero;
                    }
                    if (this.UnsafeIsGhostSpawn(x, y))
                    {
                        if (this.Ghosts[ghostCount] != null)
                        {
                            this.Ghosts[ghostCount].Position = this.GridToWorld(x, y);
                            this.Ghosts[ghostCount].Velocity = Vector2.Zero;
                        }
                        ghostCount++;
                    }
                }
            }

            // Update the camera
            this.Graphics.SetDefaultCamera();
            this.Player.UpdateCamera();
        }
예제 #5
0
파일: Level.cs 프로젝트: Mattias1/pacman
        public Vector2 GetDirFromDirectionKey(DirectionKeys key)
        {
            switch (key)
            {
            case DirectionKeys.Up:
                return(-Vector2.UnitY);

            case DirectionKeys.Down:
                return(Vector2.UnitY);

            case DirectionKeys.Right:
                return(Vector2.UnitX);

            case DirectionKeys.Left:
                return(-Vector2.UnitX);

            default:
                return(Vector2.Zero);
            }
        }
예제 #6
0
파일: Level.cs 프로젝트: Mattias1/pacman
        public override void Update(UpdateEventArgs e)
        {
            // Update the timer
            if (this.TimeLeftInS > 0)
            {
                this.TimeLeftInS -= e.ElapsedTimeInSf;
                if (this.TimeLeftInS == 0)
                {
                    this.TimeLeftInS = -0.1f;
                }
            }

            // Update the particle system
            this.particleSystem.Update(e);

            // Manage the camera
            if (InputManager.Keys.Down(Key.W))
            {
                this.Graphics.Camera.ChangeDistance(-15f * e.ElapsedTimeInSf);
            }
            if (InputManager.Keys.Down(Key.S))
            {
                this.Graphics.Camera.ChangeDistance(15f * e.ElapsedTimeInSf);
            }
            if (InputManager.Keys.Down(Key.A))
            {
                this.Graphics.Camera.RotateAroundFocusRad(-2f * e.ElapsedTimeInSf);
                this.calculateTransformDirKey();
            }
            if (InputManager.Keys.Down(Key.D))
            {
                this.Graphics.Camera.RotateAroundFocusRad(2f * e.ElapsedTimeInSf);
                this.calculateTransformDirKey();
            }
            if (InputManager.Keys.Down(Key.R))
            {
                this.Graphics.Camera = new Camera(this.Graphics, PacMan.CameraEye, Vector3.Zero, Vector3.UnitY, PacManProgram.WIDTH, PacManProgram.HEIGHT);
                this.TransFormKey    = 0;
                this.Player.UpdateCamera();
            }

            // Update the keyboard directions
            if (InputManager.Keys.Hit(Key.Up))
            {
                this.LastDirectionKey = transformDirKey(DirectionKeys.Up);
            }
            if (InputManager.Keys.Hit(Key.Down))
            {
                this.LastDirectionKey = transformDirKey(DirectionKeys.Down);
            }
            if (InputManager.Keys.Hit(Key.Right))
            {
                this.LastDirectionKey = transformDirKey(DirectionKeys.Right);
            }
            if (InputManager.Keys.Hit(Key.Left))
            {
                this.LastDirectionKey = transformDirKey(DirectionKeys.Left);
            }

            // Cheat
            if (InputManager.Keys.Down(Key.C) && InputManager.Keys.Down(Key.ShiftLeft))
            {
                if (this.PickupObjects.Count > 6)
                {
                    this.PickupObjects.RemoveRange(0, this.PickupObjects.Count - 6);
                }
            }

            if (this.State == States.Running)
            {
                if (InputManager.Keys.Hit(Key.P))
                {
                    this.Pause();
                    InputManager.Update();
                }

                // Update the game objects
                if (this.PacMan != null)
                {
                    this.PacMan.Update(e);
                }
                if (this.MsPacMan != null)
                {
                    this.MsPacMan.Update(e);
                }
                foreach (Ghost ghost in this.Ghosts)
                {
                    if (ghost != null)
                    {
                        ghost.Update(e);
                    }
                }
            }

            if (this.State == States.Paused)
            {
                if (InputManager.Keys.Hit(Key.P))
                {
                    this.Start();
                }
            }

            if (this.State == States.Starting)
            {
                // Set the correct rotation
                if (this.LastDirectionKey != DirectionKeys.None)
                {
                    Vector2 dir = this.GetDirFromDirectionKey();
                    if (this.IsMoveable(this.Player.GetGridPos() + dir))
                    {
                        this.Player.Angle = GameMath.Angle(dir);
                    }
                    else
                    {
                        this.ClearDirectionKey();
                    }
                }

                // Update the camera
                this.Player.UpdateCamera();

                // Start the game
                if (this.TimeLeftInS < 0)
                {
                    this.State       = States.Running;
                    this.TimeLeftInS = 0;
                }
            }

            if (this.State == States.Won || this.State == States.Lost)
            {
            }
        }
예제 #7
0
파일: Level.cs 프로젝트: Mattias1/pacman
 public void ClearDirectionKey()
 {
     this.LastDirectionKey = DirectionKeys.None;
 }
예제 #8
0
        public override void Update()
        {
            DirectionKeys newDirection = DirectionKeys.None;

            if ((PressedKeys & DirectionKeys.Right) == DirectionKeys.Right & GridCreator.Grid[Animation.Location.X / Coordinate.Multiplier + 1, Animation.Location.Y / Coordinate.Multiplier])
            {
                newDirection = DirectionKeys.Right;
            }

            else if ((PressedKeys & DirectionKeys.Left) == DirectionKeys.Left & GridCreator.Grid[Animation.Location.X / Coordinate.Multiplier - 1, Animation.Location.Y / Coordinate.Multiplier])
            {
                newDirection = DirectionKeys.Left;
            }

            else if ((PressedKeys & DirectionKeys.Up) == DirectionKeys.Up & GridCreator.Grid[Animation.Location.X / Coordinate.Multiplier, Animation.Location.Y / Coordinate.Multiplier - 1])
            {
                newDirection = DirectionKeys.Up;
            }

            else if ((PressedKeys & DirectionKeys.Down) == DirectionKeys.Down & GridCreator.Grid[Animation.Location.X / Coordinate.Multiplier, Animation.Location.Y / Coordinate.Multiplier + 1])
            {
                newDirection = DirectionKeys.Down;
            }


            if (CurrentDirection != newDirection && newDirection != DirectionKeys.None & (Animation.Location.X % Coordinate.Multiplier == 0 & Animation.Location.Y % Coordinate.Multiplier == 0))
            {
                Animation newAnimation = null;


                switch (newDirection)
                {
                case DirectionKeys.Right:

                    newAnimation = AnimationFactory.CreateAnimation(AnimationType.PacmanRight);

                    Step = new Coordinate(Speed, 0);

                    break;

                case DirectionKeys.Left:
                    newAnimation = AnimationFactory.CreateAnimation(AnimationType.PacmanLeft);
                    Step         = new Coordinate(-Speed, 0);
                    break;

                case DirectionKeys.Up:
                    newAnimation = AnimationFactory.CreateAnimation(AnimationType.PacmanUp);
                    Step         = new Coordinate(0, -Speed);
                    break;

                case DirectionKeys.Down:
                    newAnimation = AnimationFactory.CreateAnimation(AnimationType.PacmanDown);
                    Step         = new Coordinate(0, Speed);
                    break;
                }

                newAnimation.Location = Animation.Location;
                Animation             = newAnimation;
                CurrentDirection      = newDirection;
            }



            switch (CurrentDirection)
            {
            case DirectionKeys.Right:


                if (GridCreator.Grid[Animation.Location.X / Coordinate.Multiplier + 1, Animation.Location.Y / Coordinate.Multiplier])
                {
                    Animation.Location += Step;
                }
                break;

            case DirectionKeys.Left:


                if (GridCreator.Grid[(int)Math.Ceiling((double)Animation.Location.X / Coordinate.Multiplier - 1), Animation.Location.Y / Coordinate.Multiplier])
                {
                    Animation.Location += Step;
                }

                break;

            case DirectionKeys.Up:

                if (GridCreator.Grid[Animation.Location.X / Coordinate.Multiplier, (int)Math.Ceiling((double)Animation.Location.Y / Coordinate.Multiplier - 1)])
                {
                    Animation.Location += Step;
                }
                break;

            case DirectionKeys.Down:

                if (GridCreator.Grid[Animation.Location.X / Coordinate.Multiplier, Animation.Location.Y / Coordinate.Multiplier + 1])
                {
                    Animation.Location += Step;
                }
                break;
            }
        }
예제 #9
0
파일: Program.cs 프로젝트: sstaras13/Pacman
        public override void Update()
        {
            DirectionKeys newDirection = DirectionKeys.None;

            if ((PressedKeys & DirectionKeys.Left) == DirectionKeys.Left)
            {
                newDirection = DirectionKeys.Left;
            }
            else if ((PressedKeys & DirectionKeys.Right) == DirectionKeys.Right)
            {
                newDirection = DirectionKeys.Right;
            }
            else if ((PressedKeys & DirectionKeys.Up) == DirectionKeys.Up)
            {
                newDirection = DirectionKeys.Up;
            }
            else if ((PressedKeys & DirectionKeys.Down) == DirectionKeys.Down)
            {
                newDirection = DirectionKeys.Down;
            }

            if (CurrentDirection != newDirection && newDirection != DirectionKeys.None)
            {
                Animation newAnimation;
                switch (newDirection)
                {
                case DirectionKeys.Left:
                    newAnimation = AnimationFactory.CreateAnimation(AnimationType.PacmanLeft);
                    break;

                case DirectionKeys.Right:
                    newAnimation = AnimationFactory.CreateAnimation(AnimationType.PacmanRight);
                    break;

                case DirectionKeys.Up:
                    newAnimation = AnimationFactory.CreateAnimation(AnimationType.PacmanUp);
                    break;

                default:
                    newAnimation = AnimationFactory.CreateAnimation(AnimationType.PacmanDown);
                    break;
                }

                newAnimation.Location = Animation.Location;
                Animation             = newAnimation;
                CurrentDirection      = newDirection;
            }

            switch (CurrentDirection)
            {
            case DirectionKeys.Left:
                Animation.Location -= new Coordinate(Speed, 0);
                break;

            case DirectionKeys.Right:
                Animation.Location += new Coordinate(Speed, 0);
                break;

            case DirectionKeys.Up:
                Animation.Location -= new Coordinate(0, Speed);
                break;

            default:
                Animation.Location += new Coordinate(0, Speed);
                break;
            }
        }