Beispiel #1
0
        private void StartMovement()
        {
            if (!collapse.PredictCollapse())//якщо не очікується зіткнення-зробити крок
            {
                ghost.MoveGhost();
            }
            else
            {
                return;
            }
            Direction dir          = ghost.currentDirection;
            MyPoint   endAnimPoint = converter.ToCanvasCoordinates(ghost.currentPosition);

            if (dir == Direction.up)
            {
                double          duration = Math.Abs(endAnimPoint.Y - currentGhostPosition.Y) / 100.0;
                Storyboard      sb       = new Storyboard();
                DoubleAnimation anim     = new DoubleAnimation(currentGhostPosition.Y, endAnimPoint.Y, TimeSpan.FromSeconds(duration));
                Storyboard.SetTarget(anim, ghostImage);
                Storyboard.SetTargetProperty(anim, new PropertyPath("(Canvas.Top)"));
                sb.Children.Add(anim);
                sb.Begin();
                currentGhostPosition = endAnimPoint;
            }
            else if (dir == Direction.down)
            {
                double          duration = Math.Abs(endAnimPoint.Y - currentGhostPosition.Y) / 100.0;
                Storyboard      sb       = new Storyboard();
                DoubleAnimation anim     = new DoubleAnimation(currentGhostPosition.Y, endAnimPoint.Y, TimeSpan.FromSeconds(duration));
                Storyboard.SetTarget(anim, ghostImage);
                Storyboard.SetTargetProperty(anim, new PropertyPath("(Canvas.Top)"));
                sb.Children.Add(anim);
                sb.Begin();
                currentGhostPosition = endAnimPoint;
            }
            else if (dir == Direction.left)
            {
                double          duration = Math.Abs(endAnimPoint.X - currentGhostPosition.X) / 100.0;
                Storyboard      sb       = new Storyboard();
                DoubleAnimation anim     = new DoubleAnimation(currentGhostPosition.X, endAnimPoint.X, TimeSpan.FromSeconds(duration));
                Storyboard.SetTarget(anim, ghostImage);
                Storyboard.SetTargetProperty(anim, new PropertyPath("(Canvas.Left)"));
                sb.Children.Add(anim);
                sb.Begin();
                currentGhostPosition = endAnimPoint;
            }
            else if (dir == Direction.right)
            {
                double          duration = Math.Abs(endAnimPoint.X - currentGhostPosition.X) / 100.0;
                Storyboard      sb       = new Storyboard();
                DoubleAnimation anim     = new DoubleAnimation(currentGhostPosition.X, endAnimPoint.X, TimeSpan.FromSeconds(duration));
                Storyboard.SetTarget(anim, ghostImage);
                Storyboard.SetTargetProperty(anim, new PropertyPath("(Canvas.Left)"));
                sb.Children.Add(anim);
                sb.Begin();
                currentGhostPosition = endAnimPoint;
            }
        }
Beispiel #2
0
        private void InterruptedEndPosition() //викликається, якщо попередня подія не була успішно завершена
        {                                     //згладжує візуалізацію перерваної анімації
            MyPoint currentTemp = new MyPoint((int)Canvas.GetLeft(pacmanImage), (int)Canvas.GetTop(pacmanImage));

            pacman.currentPosition = converter.ToCellCoordinates(currentTemp);
            if (pacman.myMaze[pacman.currentPosition.X, pacman.currentPosition.Y].visited == false)
            {
                gs.AddScore();
                coins.SetCellVisited(pacman.currentPosition);
            }
            currentPacmanPosition = converter.ToCanvasCoordinates(pacman.currentPosition);
            DoubleAnimation animX = new DoubleAnimation(currentTemp.X, currentPacmanPosition.X, TimeSpan.FromSeconds(0.05));
            DoubleAnimation animY = new DoubleAnimation(currentTemp.Y, currentPacmanPosition.Y, TimeSpan.FromSeconds(0.05));

            Storyboard.SetTarget(animX, pacmanImage);
            Storyboard.SetTargetProperty(animX, new PropertyPath("(Canvas.Left)"));
            Storyboard.SetTarget(animY, pacmanImage);
            Storyboard.SetTargetProperty(animY, new PropertyPath("(Canvas.Top)"));
            sb.Children.Add(animX);
            sb.Children.Add(animY);
            sb.Begin();
        }
Beispiel #3
0
        public GhostMovement(Cell[,] myMaze, Pacman pacman, int thickness, int imageSize, string Path, Random rand, DispatcherTimer timer, DispatcherTimer pacmanTimer)
        {
            this.pacmanTimer     = pacmanTimer;
            this.thickness       = thickness;
            this.imageSize       = imageSize;
            converter            = new CoordinatesConverter(thickness, imageSize);
            ghost                = new Ghost(myMaze, pacman.currentPosition, rand);
            collapse             = new Collapse(pacman, ghost);                          //екземпляр класу зіткнення, який приймає вхідними параметрами привида та пакмена
            currentGhostPosition = converter.ToCanvasCoordinates(ghost.currentPosition); //поточне розташування
            BitmapImage pacmanBitmap = new System.Windows.Media.Imaging.BitmapImage(new Uri(Path, UriKind.Relative));

            ghostImage        = new Image();
            ghostImage.Source = pacmanBitmap;
            Canvas.SetLeft(ghostImage, currentGhostPosition.X);
            Canvas.SetTop(ghostImage, currentGhostPosition.Y);
            ((MainWindow)System.Windows.Application.Current.MainWindow).canvas.Children.Add(ghostImage);
            this.timer     = timer;
            timer.Interval = TimeSpan.FromSeconds((imageSize + 2 * thickness) / 100.0);
            timer.Tick    += Timer_Tick;;
            timer.Start();
        }
Beispiel #4
0
        public Coins(Cell[,] myMaze, Pacman pacman, int thickness, int imageSize)
        {
            this.pacman = pacman;
            CoordinatesConverter conver = new CoordinatesConverter(thickness, imageSize);

            coinsMap = new Image[myMaze.GetLength(0), myMaze.GetLength(1)];
            BitmapImage coinBitmap = new BitmapImage(new Uri(@".\Images\coin.png", UriKind.Relative));

            for (int i = 0; i < myMaze.GetLength(0); i++)//розмістити в кожній клітинці монетку
            {
                for (int j = 0; j < myMaze.GetLength(1); j++)
                {
                    Image coinImage = new Image();
                    coinImage.Source = coinBitmap;
                    coinsMap[i, j]   = coinImage;
                    MyPoint coinPosition = conver.ToCanvasCoordinates(new MyPoint(i, j));
                    Canvas.SetLeft(coinImage, coinPosition.X);
                    Canvas.SetTop(coinImage, coinPosition.Y);
                    ((MainWindow)System.Windows.Application.Current.MainWindow).canvas.Children.Add(coinImage);
                }
            }
        }
Beispiel #5
0
        public PacmanMovement(Cell[,] myMaze, int thickness, int imageSize, GameScore gs, DispatcherTimer moveTimer)
        {
            this.thickness = thickness;
            this.imageSize = imageSize;

            pacman = new Pacman(myMaze);
            coins  = new Coins(myMaze, pacman, thickness, imageSize);
            coins.SetCellVisited(pacman.currentPosition);
            converter = new CoordinatesConverter(thickness, imageSize);
            this.gs   = gs;

            currentPacmanPosition   = converter.ToCanvasCoordinates(pacman.currentPosition);
            pacmanBitmapUp          = new BitmapImage(new Uri(@".\Images\upFirst.png", UriKind.Relative));
            pacmanBitmapDown        = new BitmapImage(new Uri(@".\Images\downFirst.png", UriKind.Relative));
            pacmanBitmapLeft        = new BitmapImage(new Uri(@".\Images\leftFirst.png", UriKind.Relative));
            pacmanBitmapRight       = new BitmapImage(new Uri(@".\Images\rigthFirst.png", UriKind.Relative));
            pacmanBitmapUpSecond    = new BitmapImage(new Uri(@".\Images\upSecond.png", UriKind.Relative));
            pacmanBitmapDownSecond  = new BitmapImage(new Uri(@".\Images\downSecond.png", UriKind.Relative));
            pacmanBitmapLeftSecond  = new BitmapImage(new Uri(@".\Images\leftSecond.png", UriKind.Relative));
            pacmanBitmapRightSecond = new BitmapImage(new Uri(@".\Images\rigthSecond.png", UriKind.Relative));
            BitmapImage pacmanBitmap = new BitmapImage(new Uri(@".\Images\basic.png", UriKind.Relative));

            pacmanImage        = new Image();
            pacmanImage.Source = pacmanBitmap;
            Canvas.SetLeft(pacmanImage, currentPacmanPosition.X);
            Canvas.SetTop(pacmanImage, currentPacmanPosition.Y);
            ((MainWindow)System.Windows.Application.Current.MainWindow).canvas.Children.Add(pacmanImage);
            (System.Windows.Application.Current.MainWindow).KeyDown += this.HandleKeyDown;

            animDuration = (imageSize + 2 * thickness) / 100.0;

            this.moveTimer        = moveTimer;
            moveTimer.Interval    = TimeSpan.FromSeconds((imageSize + 2 * thickness) / 110.0);
            moveTimer.Tick       += Timer_Tick;
            chewingTimer          = new DispatcherTimer();
            chewingTimer.Interval = TimeSpan.FromSeconds(0.1);
            chewingTimer.Tick    += Chewing_Tick;
        }