Exemplo n.º 1
0
        public PacForm()
        {
            //Use double buffering to reduce flicker.
            //Буферизація для уникнення мерехтіння
            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.DoubleBuffer,
                true);
            this.UpdateStyles();

            InitializeComponent();
            levels                   = new Levels(this);
            tmr_movement.Tick       += new EventHandler(MovementTick);
            highScores               = new HighScores();
            textLabel                = new Label();
            scoreLabel               = new Label();
            highScoreLabel           = new Label();
            levelLabel               = new Label();
            transitionTimer          = new System.Windows.Forms.Timer();
            transitionTimer.Interval = 300;
            transitionTimer.Tick    += new EventHandler(LevelTransitionBlinking);
            blinky                   = new Blinky(this);
            pinky = new Pinky(this);
            inky  = new Inky(this);
            clyde = new Clyde(this);
            InitializeTextLabels();
            KeyDown   += new KeyEventHandler(KeyWatch);
            keysLocked = true;
            InitializeSound();
        }
Exemplo n.º 2
0
        public MenagerGhosts(Map map, int time)
        {
            _timeFrightened = new Timer(10000);

            _ghosts = new Collection <Ghost>();
            _blinky = map.Blinky;
            _clyde  = map.Clyde;
            _inky   = map.Inky;
            _pinky  = map.Pinky;

            AddGhostsInCollection();
            SetTime(time);

            _changeStateGhosts = new ChangeStateGhosts(this);
        }
Exemplo n.º 3
0
        public GameScreen(GraphicsDevice graphics, ContentManager content) : base(graphics, content)
        {
            //This is because we are using the same pacman in the skinscreen
            //and some of the variables were changed
            #region PacManReInitizilation
            pac.Position     = new Vector2(120, 40);
            pac.Scale        = Vector2.One;
            pac.TimePerFrame = TimeSpan.FromMilliseconds(75);
            #endregion

            #region DeclareStartKeys
            StartKeys = new List <Keys>();
            StartKeys.Add(Keys.W);
            StartKeys.Add(Keys.Up);
            StartKeys.Add(Keys.S);
            StartKeys.Add(Keys.Down);
            StartKeys.Add(Keys.D);
            StartKeys.Add(Keys.Left);
            StartKeys.Add(Keys.Right);
            StartKeys.Add(Keys.A);
            #endregion

            pixel = new Texture2D(graphics, 1, 1);
            pixel.SetData(new[] { Color.White });


            var     map       = Content.Load <Texture2D>("Map");
            Color[] colorData = new Color[map.Height * map.Width];

            map.GetData(colorData);

            Func <Vertex, Vertex, double> Manhattan = (a, b) =>
            {
                return(Math.Abs(b.Value.X - a.Value.X) + Math.Abs(b.Value.Y - a.Value.Y));
            };

            Func <Vertex, Vertex, double> Euclidean = (a, b) =>
            {
                return(Math.Pow(b.Value.X - a.Value.X, 2) + Math.Pow(b.Value.Y - a.Value.Y, 2));
            };

            SpriteFont font = Content.Load <SpriteFont>("Font");

            Map       = new Graph(Manhattan);
            BlinkyMap = new Graph(Euclidean);

            var square        = Content.Load <Texture2D>("PacManImage");
            var blinkyTexture = Content.Load <Texture2D>("blinky");
            var pinkyTexture  = Content.Load <Texture2D>("pinky");
            var clydeTexture  = Content.Load <Texture2D>("clyde");
            var inkyTexture   = Content.Load <Texture2D>("inky");

            var foodTexture = Content.Load <Texture2D>("PacManFood");
            food = new List <BaseGameSprite>();

            var heartTexture = Content.Load <Texture2D>("RedHeart");

            var poweruptexture = Content.Load <Texture2D>("pacmanpowerup");

            var wallColor        = Color.Black;
            var invalidFoodColor = Color.Red;
            var powerUpColor     = Color.Yellow;
            var pacManStartColor = Color.Yellow;

            //add all verticies that aren't black
            for (int i = 0; i < colorData.Length; i++)
            {
                var x = i % map.Width * 40;
                var y = i / map.Width * 40;

                if (colorData[i] == wallColor)
                {
                    if (Hearts.Count < 3)
                    {
                        Hearts.Add(new Heart(heartTexture, new Vector2(x, 0), Color.White, Vector2.One));
                    }
                    Walls.Add(new BaseGameSprite(square, new Vector2(x, y), Color.Black, Vector2.One));
                    continue;
                }


                if (colorData[i] != invalidFoodColor)
                {
                    Map.AddVertex(new Vector2(x, y));
                    BlinkyMap.AddVertex(new Vector2(x, y));
                    food.Add(new BaseGameSprite(foodTexture, new Vector2(x, y), Color.Yellow, Vector2.One));
                }

                if (colorData[i] == powerUpColor)
                {
                    PowerUps.Add(new BaseGameSprite(poweruptexture, new Vector2(x, y), Color.White, Vector2.One));
                }
            }

            //make connections
            for (int i = 0; i < colorData.Length; i++)
            {
                if (colorData[i] == Color.Black)
                {
                    continue;
                }

                var x             = i % map.Width * 40;
                var y             = i / map.Width * 40;
                var currentVertex = Map.FindVertex(new Vector2(x, y));

                if (currentVertex == null)
                {
                    continue;
                }

                var leftVertex  = Map.FindVertex(new Vector2(x - 40, y));
                var rightVertex = Map.FindVertex(new Vector2(x + 40, y));
                var upVertex    = Map.FindVertex(new Vector2(x, y - 40));
                var downVertex  = Map.FindVertex(new Vector2(x, y + 40));

                Map.AddEdge(40, currentVertex, leftVertex);
                Map.AddEdge(40, currentVertex, rightVertex);
                Map.AddEdge(40, currentVertex, upVertex);
                Map.AddEdge(40, currentVertex, downVertex);


                var upLeftDiagonal    = BlinkyMap.FindVertex(new Vector2(x - 40, y - 40));
                var upRightDiagonal   = BlinkyMap.FindVertex(new Vector2(x + 40, y - 40));
                var downLeftDiagonal  = BlinkyMap.FindVertex(new Vector2(x - 40, y + 40));
                var downRightDiagonal = BlinkyMap.FindVertex(new Vector2(x + 40, y + 40));

                currentVertex = BlinkyMap.FindVertex(new Vector2(x, y));

                leftVertex  = BlinkyMap.FindVertex(new Vector2(x - 40, y));
                rightVertex = BlinkyMap.FindVertex(new Vector2(x + 40, y));
                upVertex    = BlinkyMap.FindVertex(new Vector2(x, y - 40));
                downVertex  = BlinkyMap.FindVertex(new Vector2(x, y + 40));


                BlinkyMap.AddEdge(40, currentVertex, leftVertex);
                BlinkyMap.AddEdge(40, currentVertex, rightVertex);
                BlinkyMap.AddEdge(40, currentVertex, upVertex);
                BlinkyMap.AddEdge(40, currentVertex, downVertex);
                BlinkyMap.AddEdge(40, currentVertex, upLeftDiagonal);
                BlinkyMap.AddEdge(40, currentVertex, upRightDiagonal);
                BlinkyMap.AddEdge(40, currentVertex, downLeftDiagonal);
                BlinkyMap.AddEdge(40, currentVertex, downRightDiagonal);
            }

            pinky  = new Pinky(pinkyTexture, new Vector2(400, 360), Color.White, Vector2.One, Map);
            Clyde  = new Clyde(clydeTexture, new Vector2(440, 360), Color.White, Vector2.One, Map);
            blinky = new Blinky(blinkyTexture, new Vector2(480, 360), Color.White, Vector2.One, BlinkyMap);
            Inky   = new Inky(inkyTexture, new Vector2(520, 360), Color.White, Vector2.One, Map);

            for (int i = 0; i < food.Count; i++)
            {
                bool wasRemoved = false;
                for (int j = 0; j < PowerUps.Count; j++)
                {
                    if (food[i].HitBox.Contains(PowerUps[j].Position))
                    {
                        food.RemoveAt(i);
                        wasRemoved = true;
                    }
                }
                if (wasRemoved)
                {
                    i--;
                }
            }

            Ghosts = new List <BaseGameSprite>
            {
                Inky,
                blinky,
                Clyde,
                pinky
            };

            originalFoodCount = food.Count;
        }